mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 15:09:33 +01:00
web: use same logic for uploading attachment on desktop & web
This commit is contained in:
@@ -260,6 +260,7 @@ async function uploadFile(
|
|||||||
|
|
||||||
return uploaded;
|
return uploaded;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
reportProgress(undefined, { type: "upload", hash: filename });
|
reportProgress(undefined, { type: "upload", hash: filename });
|
||||||
const error = toS3Error(e);
|
const error = toS3Error(e);
|
||||||
if (
|
if (
|
||||||
@@ -301,9 +302,7 @@ async function singlePartUploadFile(
|
|||||||
headers: {
|
headers: {
|
||||||
"Content-Type": ""
|
"Content-Type": ""
|
||||||
},
|
},
|
||||||
data: IS_DESKTOP_APP
|
data: await fileHandle.toBlob(),
|
||||||
? await (await fileHandle.toBlob()).arrayBuffer()
|
|
||||||
: await fileHandle.toBlob(),
|
|
||||||
signal,
|
signal,
|
||||||
onUploadProgress: (ev) =>
|
onUploadProgress: (ev) =>
|
||||||
reportProgress(
|
reportProgress(
|
||||||
@@ -376,14 +375,13 @@ async function multiPartUploadFile(
|
|||||||
UPLOAD_PART_REQUIRED_CHUNKS
|
UPLOAD_PART_REQUIRED_CHUNKS
|
||||||
);
|
);
|
||||||
const url = parts[i];
|
const url = parts[i];
|
||||||
const data = await blob.arrayBuffer();
|
|
||||||
const response = await axios
|
const response = await axios
|
||||||
.request({
|
.request({
|
||||||
url,
|
url,
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: { "Content-Type": "", "X-Content-Length": data.byteLength },
|
headers: { "Content-Type": "" },
|
||||||
signal,
|
signal,
|
||||||
data,
|
data: blob,
|
||||||
onUploadProgress
|
onUploadProgress
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
@@ -603,10 +601,13 @@ export async function saveFile(filename: string, fileMetadata: FileMetadata) {
|
|||||||
|
|
||||||
async function deleteFile(
|
async function deleteFile(
|
||||||
filename: string,
|
filename: string,
|
||||||
requestOptions: RequestOptionsWithSignal
|
requestOptions?: RequestOptionsWithSignal
|
||||||
) {
|
) {
|
||||||
if (!requestOptions) return await streamablefs.deleteFile(filename);
|
if (!requestOptions)
|
||||||
if (!requestOptions && !(await streamablefs.exists(filename))) return true;
|
return (
|
||||||
|
!(await streamablefs.exists(filename)) ||
|
||||||
|
(await streamablefs.deleteFile(filename))
|
||||||
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { url, headers } = requestOptions;
|
const { url, headers } = requestOptions;
|
||||||
|
|||||||
Reference in New Issue
Block a user