Fix metadata in proxy object

This commit is contained in:
Arnaud 2024-10-22 10:22:06 +02:00
parent a9832f81a9
commit c685d13e05
No known key found for this signature in database
GPG Key ID: 69D6CE281FCAE663

View File

@ -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<SafeValue<string>>((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);
}