1
0

Minor cleanup

This commit is contained in:
Zef Hemel 2023-11-22 15:51:44 +01:00
parent ae1561ac90
commit 621c21d26c

View File

@ -65,7 +65,7 @@ export function editorSyscalls(editor: Client): SysCallMapping {
"editor.uploadFile": ( "editor.uploadFile": (
_ctx, _ctx,
accept?: string, accept?: string,
capture?: string capture?: string,
): Promise<UploadFile> => { ): Promise<UploadFile> => {
return new Promise<UploadFile>((resolve, reject) => { return new Promise<UploadFile>((resolve, reject) => {
const input = document.createElement("input"); const input = document.createElement("input");
@ -82,22 +82,27 @@ export function editorSyscalls(editor: Client): SysCallMapping {
if (!file) { if (!file) {
reject(new Error("No file found")); reject(new Error("No file found"));
} else { } else {
var reader = new FileReader(); const reader = new FileReader();
reader.readAsArrayBuffer(file); reader.readAsArrayBuffer(file);
reader.onloadend = async (evt) => { reader.onloadend = async (evt) => {
if (evt.target?.readyState == FileReader.DONE) { if (evt.target?.readyState == FileReader.DONE) {
const arrayBuffer = evt.target.result;
resolve({ resolve({
name: file.name, name: file.name,
content: new Uint8Array(await file.arrayBuffer()) content: new Uint8Array(await file.arrayBuffer()),
}); });
} }
}; };
reader.onabort = (e) => { reject(e) }; reader.onabort = (e) => {
reader.onerror = (e) => { reject(e) }; reject(e);
};
reader.onerror = (e) => {
reject(e);
};
} }
} };
input.onabort = (e) => { reject(e) }; input.onabort = (e) => {
reject(e);
};
input.click(); input.click();
}); });