mirror of
https://github.com/HeyPuter/puter.git
synced 2026-05-29 12:50:59 +00:00
fix: disable requests from server in two services
Docker Image CI / build-and-push-image (push) Has been cancelled
Maintain Release Merge PR / update-release-pr (push) Has been cancelled
release-please / release-please (push) Has been cancelled
test / test-backend (24.x) (push) Has been cancelled
test / API tests (node env, api-test) (24.x) (push) Has been cancelled
test / puterjs (node env, vitest) (24.x) (push) Has been cancelled
Docker Image CI / build-and-push-image (push) Has been cancelled
Maintain Release Merge PR / update-release-pr (push) Has been cancelled
release-please / release-please (push) Has been cancelled
test / test-backend (24.x) (push) Has been cancelled
test / API tests (node env, api-test) (24.x) (push) Has been cancelled
test / puterjs (node env, vitest) (24.x) (push) Has been cancelled
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
const APIError = require('../../api/APIError');
|
||||
const BaseService = require('../BaseService');
|
||||
const { TypeSpec } = require('./meta/Construct');
|
||||
const { TypedValue } = require('./meta/Runtime');
|
||||
@@ -29,10 +28,6 @@ const { TypedValue } = require('./meta/Runtime');
|
||||
* consumes specifications.
|
||||
*/
|
||||
class CoercionService extends BaseService {
|
||||
static MODULES = {
|
||||
axios: require('axios'),
|
||||
};
|
||||
|
||||
/**
|
||||
* Attempt to coerce a TypedValue to a target TypeSpec.
|
||||
* This method checks if the current TypedValue can be adapted to the specified target TypeSpec,
|
||||
@@ -53,70 +48,6 @@ class CoercionService extends BaseService {
|
||||
* operations are performed.
|
||||
*/
|
||||
async _init () {
|
||||
this.coercions_.push({
|
||||
produces: {
|
||||
$: 'stream',
|
||||
content_type: 'image',
|
||||
},
|
||||
consumes: {
|
||||
$: 'string:url:web',
|
||||
content_type: 'image',
|
||||
},
|
||||
coerce: async typed_value => {
|
||||
console.debug('coercion is running!');
|
||||
|
||||
const response = await (async () => {
|
||||
try {
|
||||
return await CoercionService.MODULES.axios.get(typed_value.value, {
|
||||
responseType: 'stream',
|
||||
});
|
||||
} catch (e) {
|
||||
APIError.create('field_invalid', null, {
|
||||
key: 'url',
|
||||
expected: 'web URL',
|
||||
got: `error during request: ${ e.message}`,
|
||||
});
|
||||
}
|
||||
})();
|
||||
|
||||
return new TypedValue({
|
||||
$: 'stream',
|
||||
content_type: response.headers['content-type'],
|
||||
}, response.data);
|
||||
},
|
||||
});
|
||||
|
||||
this.coercions_.push({
|
||||
produces: {
|
||||
$: 'stream',
|
||||
content_type: 'video',
|
||||
},
|
||||
consumes: {
|
||||
$: 'string:url:web',
|
||||
content_type: 'video',
|
||||
},
|
||||
coerce: async typed_value => {
|
||||
const response = await (async () => {
|
||||
try {
|
||||
return await CoercionService.MODULES.axios.get(typed_value.value, {
|
||||
responseType: 'stream',
|
||||
});
|
||||
} catch (e) {
|
||||
APIError.create('field_invalid', null, {
|
||||
key: 'url',
|
||||
expected: 'web URL',
|
||||
got: `error during request: ${ e.message}`,
|
||||
});
|
||||
}
|
||||
})();
|
||||
|
||||
return new TypedValue({
|
||||
$: 'stream',
|
||||
content_type: response.headers['content-type'] ?? 'video/mp4',
|
||||
}, response.data);
|
||||
},
|
||||
});
|
||||
|
||||
// Add coercion for data URLs to streams
|
||||
this.coercions_.push({
|
||||
produces: {
|
||||
|
||||
@@ -22,7 +22,6 @@ const { MultiValue } = require('../../util/multivalue');
|
||||
const { stream_to_buffer } = require('../../util/streamutil');
|
||||
const { PassThrough } = require('stream');
|
||||
const { LLRead } = require('../../filesystem/ll_operations/ll_read');
|
||||
const APIError = require('../../api/APIError');
|
||||
|
||||
/**
|
||||
* @class FileFacade
|
||||
@@ -41,10 +40,6 @@ class FileFacade extends AdvancedBase {
|
||||
STREAM: { key: 'stream' },
|
||||
};
|
||||
|
||||
static MODULES = {
|
||||
axios: require('axios'),
|
||||
};
|
||||
|
||||
constructor (...a) {
|
||||
super(...a);
|
||||
|
||||
@@ -88,24 +83,6 @@ class FileFacade extends AdvancedBase {
|
||||
return stream;
|
||||
});
|
||||
|
||||
this.values.add_factory('stream', 'web_url', async web_url => {
|
||||
const response = await (async () => {
|
||||
try {
|
||||
return await FileFacade.MODULES.axios.get(web_url, {
|
||||
responseType: 'stream',
|
||||
});
|
||||
} catch (e) {
|
||||
throw APIError.create('field_invalid', null, {
|
||||
key: 'url',
|
||||
expected: 'web URL',
|
||||
got: `error during request: ${ e.message}`,
|
||||
});
|
||||
}
|
||||
})();
|
||||
|
||||
return response.data;
|
||||
});
|
||||
|
||||
this.values.add_factory('stream', 'data_url', async data_url => {
|
||||
const data = data_url.split(',')[1];
|
||||
const buffer = Buffer.from(data, 'base64');
|
||||
|
||||
Reference in New Issue
Block a user