|
@@ -53,6 +53,7 @@ import { VISIBILITY_STATE } from "types/magicMetadata";
|
|
import { FileTypeInfo } from "types/upload";
|
|
import { FileTypeInfo } from "types/upload";
|
|
import { isArchivedFile, updateMagicMetadata } from "utils/magicMetadata";
|
|
import { isArchivedFile, updateMagicMetadata } from "utils/magicMetadata";
|
|
import { safeFileName } from "utils/native-fs";
|
|
import { safeFileName } from "utils/native-fs";
|
|
|
|
+import { writeStream } from "utils/native-stream";
|
|
|
|
|
|
const WAIT_TIME_IMAGE_CONVERSION = 30 * 1000;
|
|
const WAIT_TIME_IMAGE_CONVERSION = 30 * 1000;
|
|
|
|
|
|
@@ -798,55 +799,47 @@ async function downloadFileDesktop(
|
|
electron: Electron,
|
|
electron: Electron,
|
|
fileReader: FileReader,
|
|
fileReader: FileReader,
|
|
file: EnteFile,
|
|
file: EnteFile,
|
|
- downloadPath: string,
|
|
|
|
|
|
+ downloadDir: string,
|
|
) {
|
|
) {
|
|
- const fileStream = (await DownloadManager.getFile(
|
|
|
|
|
|
+ const fs = electron.fs;
|
|
|
|
+ const stream = (await DownloadManager.getFile(
|
|
file,
|
|
file,
|
|
)) as ReadableStream<Uint8Array>;
|
|
)) as ReadableStream<Uint8Array>;
|
|
- const updatedFileStream = await getUpdatedEXIFFileForDownload(
|
|
|
|
|
|
+ const updatedStream = await getUpdatedEXIFFileForDownload(
|
|
fileReader,
|
|
fileReader,
|
|
file,
|
|
file,
|
|
- fileStream,
|
|
|
|
|
|
+ stream,
|
|
);
|
|
);
|
|
|
|
|
|
if (file.metadata.fileType === FILE_TYPE.LIVE_PHOTO) {
|
|
if (file.metadata.fileType === FILE_TYPE.LIVE_PHOTO) {
|
|
- const fileBlob = await new Response(updatedFileStream).blob();
|
|
|
|
|
|
+ const fileBlob = await new Response(updatedStream).blob();
|
|
const livePhoto = await decodeLivePhoto(file, fileBlob);
|
|
const livePhoto = await decodeLivePhoto(file, fileBlob);
|
|
const imageExportName = await safeFileName(
|
|
const imageExportName = await safeFileName(
|
|
- downloadPath,
|
|
|
|
|
|
+ downloadDir,
|
|
livePhoto.imageNameTitle,
|
|
livePhoto.imageNameTitle,
|
|
- electron.fs.exists,
|
|
|
|
|
|
+ fs.exists,
|
|
);
|
|
);
|
|
const imageStream = generateStreamFromArrayBuffer(livePhoto.image);
|
|
const imageStream = generateStreamFromArrayBuffer(livePhoto.image);
|
|
- await electron.saveStreamToDisk(
|
|
|
|
- `${downloadPath}/${imageExportName}`,
|
|
|
|
- imageStream,
|
|
|
|
- );
|
|
|
|
|
|
+ await writeStream(`${downloadDir}/${imageExportName}`, imageStream);
|
|
try {
|
|
try {
|
|
const videoExportName = await safeFileName(
|
|
const videoExportName = await safeFileName(
|
|
- downloadPath,
|
|
|
|
|
|
+ downloadDir,
|
|
livePhoto.videoNameTitle,
|
|
livePhoto.videoNameTitle,
|
|
- electron.fs.exists,
|
|
|
|
|
|
+ fs.exists,
|
|
);
|
|
);
|
|
const videoStream = generateStreamFromArrayBuffer(livePhoto.video);
|
|
const videoStream = generateStreamFromArrayBuffer(livePhoto.video);
|
|
- await electron.saveStreamToDisk(
|
|
|
|
- `${downloadPath}/${videoExportName}`,
|
|
|
|
- videoStream,
|
|
|
|
- );
|
|
|
|
|
|
+ await writeStream(`${downloadDir}/${videoExportName}`, videoStream);
|
|
} catch (e) {
|
|
} catch (e) {
|
|
- await electron.fs.rm(`${downloadPath}/${imageExportName}`);
|
|
|
|
|
|
+ await fs.rm(`${downloadDir}/${imageExportName}`);
|
|
throw e;
|
|
throw e;
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
const fileExportName = await safeFileName(
|
|
const fileExportName = await safeFileName(
|
|
- downloadPath,
|
|
|
|
|
|
+ downloadDir,
|
|
file.metadata.title,
|
|
file.metadata.title,
|
|
- electron.fs.exists,
|
|
|
|
- );
|
|
|
|
- await electron.saveStreamToDisk(
|
|
|
|
- `${downloadPath}/${fileExportName}`,
|
|
|
|
- updatedFileStream,
|
|
|
|
|
|
+ fs.exists,
|
|
);
|
|
);
|
|
|
|
+ await writeStream(`${downloadDir}/${fileExportName}`, updatedStream);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|