mobile: reupload if file size is zero

This commit is contained in:
Ammar Ahmed
2023-11-18 11:48:14 +05:00
committed by Abdullah Atta
parent 95b9edca62
commit 64d10f5050
2 changed files with 19 additions and 8 deletions

View File

@@ -96,16 +96,22 @@ export async function downloadFile(filename, data, cancelToken) {
} }
export async function getUploadedFileSize(hash) { export async function getUploadedFileSize(hash) {
const url = `${hosts.API_HOST}/s3?name=${hash}`; try {
const token = await db.user.tokenManager.getAccessToken(); const url = `${hosts.API_HOST}/s3?name=${hash}`;
const token = await db.user.tokenManager.getAccessToken();
const attachmentInfo = await fetch(url, { const attachmentInfo = await fetch(url, {
method: "HEAD", method: "HEAD",
headers: { Authorization: `Bearer ${token}` } headers: { Authorization: `Bearer ${token}` }
}); });
const contentLength = parseInt(attachmentInfo.headers?.get("content-length")); const contentLength = parseInt(
return isNaN(contentLength) ? 0 : contentLength; attachmentInfo.headers?.get("content-length")
);
return isNaN(contentLength) ? 0 : contentLength;
} catch (e) {
return 0;
}
} }
export async function checkAttachment(hash) { export async function checkAttachment(hash) {

View File

@@ -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, {