diff --git a/src/puter-js/src/index.js b/src/puter-js/src/index.js index eb42c4f9..10d4a476 100644 --- a/src/puter-js/src/index.js +++ b/src/puter-js/src/index.js @@ -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; diff --git a/src/puter-js/src/modules/Convert.js b/src/puter-js/src/modules/Convert.js new file mode 100644 index 00000000..9a5aeae2 --- /dev/null +++ b/src/puter-js/src/modules/Convert.js @@ -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; \ No newline at end of file