Оптимизация ядра, исправление гонки потоков при получении версии
This commit is contained in:
@@ -14,6 +14,7 @@ import { DialogContext } from "../DialogProvider/DialogProvider";
|
||||
import { useSaveAvatar } from "../AvatarProvider/useSaveAvatar";
|
||||
import { AVATAR_PASSWORD_TO_ENCODE } from "@/app/constants";
|
||||
import { useDialog } from "../DialogProvider/useDialog";
|
||||
import { useCore } from "@/app/hooks/useCore";
|
||||
|
||||
export enum DownloadStatus {
|
||||
DOWNLOADED,
|
||||
@@ -37,6 +38,7 @@ export function useAttachment(attachment: Attachment, keyPlain: string) {
|
||||
const {updateAttachmentInDialogCache} = useDialogsCache();
|
||||
const {info} = useConsoleLogger('useAttachment');
|
||||
const {updateAttachmentsInMessagesByAttachmentId} = useDialog();
|
||||
const {getDownloadsPath} = useCore();
|
||||
|
||||
|
||||
const context = useContext(DialogContext);
|
||||
@@ -85,7 +87,8 @@ export function useAttachment(attachment: Attachment, keyPlain: string) {
|
||||
const preview = getPreview();
|
||||
const filesize = parseInt(preview.split("::")[0]);
|
||||
const filename = preview.split("::")[1];
|
||||
let pathInDownloads = window.downloadsPath + "/Rosetta Downloads/" + filename;
|
||||
const downloadsPath = await getDownloadsPath();
|
||||
let pathInDownloads = downloadsPath + "/Rosetta Downloads/" + filename;
|
||||
const exists = await fileExists(pathInDownloads, false);
|
||||
const existsLength = await size(pathInDownloads, false);
|
||||
if(exists && existsLength == filesize){
|
||||
@@ -161,8 +164,9 @@ export function useAttachment(attachment: Attachment, keyPlain: string) {
|
||||
*/
|
||||
const preview = getPreview();
|
||||
const filename = preview.split("::")[1];
|
||||
const downloadsPath = await getDownloadsPath();
|
||||
let buffer = Buffer.from(decrypted.split(",")[1], 'base64');
|
||||
let pathInDownloads = window.downloadsPath + "/Rosetta Downloads/" + filename;
|
||||
let pathInDownloads = downloadsPath + "/Rosetta Downloads/" + filename;
|
||||
/**
|
||||
* Пишем файл в загрузки, но перед этим выбираем ему название, если файл в загрузках
|
||||
* уже есть с таким названием то добавляем к названию (1), (2) и так далее, чтобы не перезаписать существующий файл
|
||||
@@ -170,7 +174,7 @@ export function useAttachment(attachment: Attachment, keyPlain: string) {
|
||||
let finalPath = pathInDownloads;
|
||||
let fileIndex = 1;
|
||||
while (await fileExists(finalPath, false)) {
|
||||
finalPath = window.downloadsPath + "/Rosetta Downloads/" + filename.split(".").slice(0, -1).join(".") + ` (${fileIndex})` + "." + filename.split(".").slice(-1);
|
||||
finalPath = downloadsPath + "/Rosetta Downloads/" + filename.split(".").slice(0, -1).join(".") + ` (${fileIndex})` + "." + filename.split(".").slice(-1);
|
||||
fileIndex++;
|
||||
}
|
||||
await writeFile(finalPath, buffer, false);
|
||||
|
||||
Reference in New Issue
Block a user