mirror of
https://github.com/rclone/rclone.git
synced 2024-11-25 18:04:55 +01:00
aab9aa8a2e
This works by compiling rclone to wasm and exporting the RC api to javascript.
37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
var rc;
|
|
var rcValidResolve
|
|
var rcValid = new Promise(resolve => {
|
|
rcValidResolve = resolve
|
|
});
|
|
|
|
var script = document.createElement('script');
|
|
script.src = "wasm_exec.js";
|
|
script.onload = function () {
|
|
if (!WebAssembly.instantiateStreaming) { // polyfill
|
|
WebAssembly.instantiateStreaming = async (resp, importObject) => {
|
|
const source = await (await resp).arrayBuffer();
|
|
return await WebAssembly.instantiate(source, importObject);
|
|
};
|
|
}
|
|
const go = new Go();
|
|
WebAssembly.instantiateStreaming(fetch("rclone.wasm"), go.importObject).then((result) => {
|
|
go.run(result.instance);
|
|
});
|
|
|
|
};
|
|
document.head.appendChild(script);
|
|
|
|
rcValid.then(() => {
|
|
// Some examples of using the rc call
|
|
//
|
|
// The rc call takes two parameters, method and input object and
|
|
// returns an output object.
|
|
//
|
|
// If the output object has an "error" and a "status" then it is an
|
|
// error (it would be nice to signal this out of band).
|
|
console.log("core/version", rc("core/version", null))
|
|
console.log("core/version", rc("rc/noop", {"string":"one",number:2}))
|
|
console.log("core/version", rc("operations/mkdir", {"fs":":memory:","remote":"bucket"}))
|
|
console.log("core/version", rc("operations/list", {"fs":":memory:","remote":"bucket"}))
|
|
})
|