mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-21 22:19:41 +01:00
mobile: reupload if file size is zero
This commit is contained in:
committed by
Abdullah Atta
parent
95b9edca62
commit
64d10f5050
@@ -96,6 +96,7 @@ export async function downloadFile(filename, data, cancelToken) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getUploadedFileSize(hash) {
|
export async function getUploadedFileSize(hash) {
|
||||||
|
try {
|
||||||
const url = `${hosts.API_HOST}/s3?name=${hash}`;
|
const url = `${hosts.API_HOST}/s3?name=${hash}`;
|
||||||
const token = await db.user.tokenManager.getAccessToken();
|
const token = await db.user.tokenManager.getAccessToken();
|
||||||
|
|
||||||
@@ -104,8 +105,13 @@ export async function getUploadedFileSize(hash) {
|
|||||||
headers: { Authorization: `Bearer ${token}` }
|
headers: { Authorization: `Bearer ${token}` }
|
||||||
});
|
});
|
||||||
|
|
||||||
const contentLength = parseInt(attachmentInfo.headers?.get("content-length"));
|
const contentLength = parseInt(
|
||||||
|
attachmentInfo.headers?.get("content-length")
|
||||||
|
);
|
||||||
return isNaN(contentLength) ? 0 : contentLength;
|
return isNaN(contentLength) ? 0 : contentLength;
|
||||||
|
} catch (e) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function checkAttachment(hash) {
|
export async function checkAttachment(hash) {
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import { FILE_SIZE_LIMIT, IMAGE_SIZE_LIMIT } from "../../../utils/constants";
|
|||||||
import { eCloseSheet } from "../../../utils/events";
|
import { eCloseSheet } from "../../../utils/events";
|
||||||
import { editorController, editorState } from "./utils";
|
import { editorController, editorState } from "./utils";
|
||||||
import { useSettingStore } from "../../../stores/use-setting-store";
|
import { useSettingStore } from "../../../stores/use-setting-store";
|
||||||
|
import filesystem from "../../../common/filesystem";
|
||||||
|
|
||||||
const showEncryptionSheet = (file) => {
|
const showEncryptionSheet = (file) => {
|
||||||
presentSheet({
|
presentSheet({
|
||||||
@@ -270,6 +271,10 @@ export async function attachFile(uri, hash, type, filename, options) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!options.reupload && exists) {
|
||||||
|
options.reupload = (await filesystem.getUploadedFileSize(hash)) <= 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (!exists || options?.reupload) {
|
if (!exists || options?.reupload) {
|
||||||
let key = await db.attachments.generateKey();
|
let key = await db.attachments.generateKey();
|
||||||
encryptionInfo = await Sodium.encryptFile(key, {
|
encryptionInfo = await Sodium.encryptFile(key, {
|
||||||
|
|||||||
Reference in New Issue
Block a user