add Convert modules to Puter.js

This commit is contained in:
jelveh
2025-02-06 18:19:12 -08:00
parent 62cf10072a
commit 949d3ab17c
2 changed files with 41 additions and 0 deletions

View File

@@ -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;

View 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;