From c685d13e05322e060ee273d4329b4bdfd9ee7882 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Tue, 22 Oct 2024 10:22:06 +0200 Subject: [PATCH] Fix metadata in proxy object --- src/proxy.ts | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/src/proxy.ts b/src/proxy.ts index 04a8f54..2584292 100644 --- a/src/proxy.ts +++ b/src/proxy.ts @@ -16,15 +16,58 @@ class CodexDataMock extends CodexData { file: File, onProgress?: (loaded: number, total: number) => void ): UploadResponse { + // const url = CodexSdk.url() + "/api/codex/v1/data"; + + // const xhr = new XMLHttpRequest(); + + // const promise = new Promise>((resolve) => { + // xhr.upload.onprogress = (evt) => { + // if (evt.lengthComputable) { + // onProgress?.(evt.loaded, evt.total); + // } + // }; + + // xhr.open("POST", url, true); + // xhr.setRequestHeader("Content-Disposition", "attachment; filename=\"" + file.name + "\"") + // xhr.send(file); + + // xhr.onload = function () { + // if (xhr.status != 200) { + // resolve({ + // error: true, + // data: new CodexError(xhr.responseText, { + // code: xhr.status, + // }), + // }); + // } else { + // resolve({ error: false, data: xhr.response }); + // } + // }; + + // xhr.onerror = function () { + // resolve({ + // error: true, + // data: new CodexError("Something went wrong during the file upload."), + // }); + // }; + // }); + + // return { + // result: promise, + // abort: () => { + // xhr.abort(); + // }, + // }; const { result, abort } = super.upload(file, onProgress); return { abort, result: result.then((safe) => { if (!safe.error) { - return WebStorage.set(safe.data, { - type: file.type, + return FilesStorage.set(safe.data, { + mimetype: file.type, name: file.name, + uploadedAt: new Date().toJSON(), }).then(() => safe); }