mirror of
https://github.com/HeyPuter/puter.git
synced 2026-01-05 20:50:22 -06:00
add Convert modules to Puter.js
This commit is contained in:
@@ -24,6 +24,7 @@ import { PTLSSocket } from "./modules/networking/PTLS.js"
|
||||
import { PWispHandler } from './modules/networking/PWispHandler.js';
|
||||
import { make_http_api } from './lib/http.js';
|
||||
import Exec from './modules/Exec.js';
|
||||
import Convert from './modules/Convert.js';
|
||||
|
||||
// TODO: This is for a safe-guard below; we should check if we can
|
||||
// generalize this behavior rather than hard-coding it.
|
||||
@@ -100,6 +101,7 @@ window.puter = (function() {
|
||||
this.registerModule('drivers', Drivers);
|
||||
this.registerModule('debug', Debug);
|
||||
this.registerModule('exec', Exec);
|
||||
this.registerModule('convert', Convert);
|
||||
|
||||
// Path
|
||||
this.path = path;
|
||||
|
||||
39
src/puter-js/src/modules/Convert.js
Normal file
39
src/puter-js/src/modules/Convert.js
Normal file
@@ -0,0 +1,39 @@
|
||||
import * as utils from '../lib/utils.js';
|
||||
|
||||
class Convert {
|
||||
constructor(context) {
|
||||
this.authToken = context.authToken;
|
||||
this.APIOrigin = context.APIOrigin;
|
||||
this.appID = context.appID; // Might not be strictly necessary for this module, but good for consistency
|
||||
}
|
||||
|
||||
setAuthToken(authToken) {
|
||||
this.authToken = authToken;
|
||||
}
|
||||
|
||||
setAPIOrigin(APIOrigin) {
|
||||
this.APIOrigin = APIOrigin;
|
||||
}
|
||||
|
||||
|
||||
convert = async (...args) => {
|
||||
let options = {};
|
||||
|
||||
// if args is a single object, assume it is the options object
|
||||
if (typeof args[0] === 'object' && args[0] !== null) {
|
||||
options = args[0];
|
||||
} else {
|
||||
// Otherwise, we assume separate arguments are provided
|
||||
options = {
|
||||
source: args[0],
|
||||
to: args[1],
|
||||
success: args[2],
|
||||
error: args[3],
|
||||
};
|
||||
}
|
||||
|
||||
return utils.make_driver_method(['source', 'to'], 'convert-files', undefined, 'convert').call(this, options);
|
||||
}
|
||||
}
|
||||
|
||||
export default Convert;
|
||||
Reference in New Issue
Block a user