You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tauri-plugins-workspace/plugins/upload/guest-js/dist/index.mjs

39 lines
1.1 KiB

import { invoke } from '@tauri-apps/api/tauri';
import { appWindow } from '@tauri-apps/api/window';
const handlers = new Map();
let listening = false;
async function listenToUploadEventIfNeeded() {
if (listening) {
return await Promise.resolve();
}
return await appWindow
.listen("upload://progress", ({ payload }) => {
const handler = handlers.get(payload.id);
if (handler != null) {
handler(payload.progress, payload.total);
}
})
.then(() => {
listening = true;
});
}
async function upload(url, filePath, progressHandler, headers) {
const ids = new Uint32Array(1);
window.crypto.getRandomValues(ids);
const id = ids[0];
if (progressHandler != null) {
handlers.set(id, progressHandler);
}
await listenToUploadEventIfNeeded();
await invoke("plugin:upload|upload", {
id,
url,
filePath,
headers: headers !== null && headers !== void 0 ? headers : {},
});
}
export { upload as default };
//# sourceMappingURL=index.mjs.map