Skip to content

Commit

Permalink
Merge pull request #527 from internxt/fix/2-3-1-release
Browse files Browse the repository at this point in the history
fix some issues
  • Loading branch information
ArceDanielShok authored Dec 20, 2024
2 parents 11a5ee8 + d67a0c5 commit 6679f9f
Show file tree
Hide file tree
Showing 24 changed files with 226 additions and 136 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "internxt-drive",
"version": "2.3.1",
"version": "2.3.2",
"author": "Internxt <[email protected]>",
"description": "Internxt Drive client UI",
"license": "AGPL-3.0",
Expand Down
2 changes: 1 addition & 1 deletion release/app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "internxt-drive",
"version": "2.3.1",
"version": "2.3.2",
"description": "Internxt Drive client UI",
"main": "./dist/main/main.js",
"author": "Internxt <[email protected]>",
Expand Down
16 changes: 11 additions & 5 deletions src/apps/backups/Backups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class Backup {

const filesDiff = DiffFilesCalculator.calculate(local, remote);

await this.isThereEnoughSpace(filesDiff);
// await this.isThereEnoughSpace(filesDiff);

const alreadyBacked =
filesDiff.unmodified.length + foldersDiff.unmodified.length;
Expand Down Expand Up @@ -182,11 +182,17 @@ export class Backup {
);
} catch (error) {
Logger.error('Error uploading files', error);
}
this.backed += batch.length;
if (error instanceof DriveDesktopError) {
Logger.error('Error uploading files', {
cause: error.cause,
});
throw error;
}
this.backed += batch.length;

Logger.debug('[Backed]', this.backed);
BackupsIPCRenderer.send('backups.progress-update', this.backed);
Logger.debug('[Backed]', this.backed);
BackupsIPCRenderer.send('backups.progress-update', this.backed);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export async function registerLocalFileServices(builder: ContainerBuilder) {
});

Logger.info('Registering local file services');
Logger.info('User', user);

builder.register(Environment).useInstance(environment).private();

Expand Down
46 changes: 33 additions & 13 deletions src/apps/main/device/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { addGeneralIssue } from '../background-processes/process-issues';
import configStore from '../config';
import { BackupInfo } from '../../backups/BackupInfo';
import { PathLike } from 'fs';
import { downloadFolderAsZip } from '../network/download';
import { downloadFolder } from '../network/download';
import Logger from 'electron-log';
import { broadcastToWindows } from '../windows';
import { randomUUID } from 'crypto';
Expand Down Expand Up @@ -45,6 +45,7 @@ export interface FolderTreeResponse {
folderDecryptedNames: Record<number, string>;
fileDecryptedNames: Record<number, string>;
size: number;
totalItems: number;
}

export const addUnknownDeviceIssue = (error: Error) => {
Expand Down Expand Up @@ -84,7 +85,7 @@ export async function getDevices(): Promise<Array<Device>> {
headers: getHeaders(true),
});

const devices = (await response.json()) as Array<DeviceDTO>;
const devices = ((await response.json()) as Array<DeviceDTO>) || [];

return devices
.filter(({ removed, hasBackups }) => !removed && hasBackups)
Expand Down Expand Up @@ -186,8 +187,20 @@ export async function renameDevice(deviceName: string): Promise<Device> {
}

function decryptDeviceName({ name, ...rest }: Device): Device {
let nameDevice;
let key;
try {
key = `${process.env.NEW_CRYPTO_KEY}-${rest.bucket}`;
nameDevice = aes.decrypt(name, key);
} catch (error) {
key = `${process.env.NEW_CRYPTO_KEY}-${null}`;
nameDevice = aes.decrypt(name, key);
}

Logger.info(`[DEVICE] Decrypted device name "${nameDevice}"`);

return {
name: aes.decrypt(name, `${process.env.NEW_CRYPTO_KEY}-${rest.bucket}`),
name: nameDevice,
...rest,
};
}
Expand Down Expand Up @@ -267,7 +280,7 @@ async function createBackup(pathname: string): Promise<void> {

const newBackup = await postBackup(base);

logger.debug(`[BACKUPS] Created backup with id ${newBackup.id}`);
logger.debug(`[BACKUPS] Created backup with id ${newBackup.uuid}`);

const backupList = configStore.get('backupList');

Expand Down Expand Up @@ -365,6 +378,7 @@ function processFolderTree(tree: FolderTree) {
const folderDecryptedNames: Record<number, string> = {};
const fileDecryptedNames: Record<number, string> = {};
const pendingFolders = [tree];
let totalItems = 0;

while (pendingFolders.length > 0) {
const currentTree = pendingFolders.shift()!;
Expand All @@ -381,22 +395,23 @@ function processFolderTree(tree: FolderTree) {
`${process.env.NEW_CRYPTO_KEY}-${file.folderId}`
);
size += Number(file.size);
totalItems++;
}

pendingFolders.push(...folders);
}

return { size, folderDecryptedNames, fileDecryptedNames };
return { size, folderDecryptedNames, fileDecryptedNames, totalItems };
}

export async function fetchFolderTree(
folderUuid: string
): Promise<FolderTreeResponse> {
const tree = await fetchTreeFromApi(folderUuid);
const { size, folderDecryptedNames, fileDecryptedNames } =
const { size, folderDecryptedNames, fileDecryptedNames, totalItems } =
processFolderTree(tree);

return { tree, folderDecryptedNames, fileDecryptedNames, size };
return { tree, folderDecryptedNames, fileDecryptedNames, size, totalItems };
}

export async function fetchArrayFolderTree(
Expand All @@ -406,6 +421,7 @@ export async function fetchArrayFolderTree(
const folderDecryptedNames: Record<number, string> = {};
const fileDecryptedNames: Record<number, string> = {};
let totalSize = 0;
let totalItemsInTree = 0;

for (const folderUuid of folderUuids) {
const tree = await fetchTreeFromApi(folderUuid);
Expand All @@ -415,9 +431,11 @@ export async function fetchArrayFolderTree(
size,
folderDecryptedNames: folderNames,
fileDecryptedNames: fileNames,
totalItems,
} = processFolderTree(tree);

totalSize += size;
totalItemsInTree += totalItems;
Object.assign(folderDecryptedNames, folderNames);
Object.assign(fileDecryptedNames, fileNames);
}
Expand Down Expand Up @@ -450,6 +468,7 @@ export async function fetchArrayFolderTree(
folderDecryptedNames,
fileDecryptedNames,
size: totalSize,
totalItems: totalItemsInTree,
};
}

Expand Down Expand Up @@ -496,6 +515,8 @@ export async function disableBackup(backup: BackupInfo): Promise<void> {
const backupsList = configStore.get('backupList');
const pathname = findBackupPathnameFromId(backup.folderId)!;

await deleteBackup(backup);

backupsList[pathname].enabled = false;

configStore.set('backupList', backupsList);
Expand Down Expand Up @@ -577,16 +598,12 @@ async function downloadDeviceBackupZip(

const folders = await fetchFolders(foldersIdToDownload);

Logger.info(`[BACKUPS] Folders to download: ${folders}`);

Logger.info(folders);

const networkApiUrl = process.env.BRIDGE_URL;
const bridgeUser = user.bridgeUser;
const bridgePass = user.userId;
const encryptionKey = user.mnemonic;

await downloadFolderAsZip(
await downloadFolder(
device.name,
networkApiUrl,
folders.map((folder) => folder.uuid),
Expand Down Expand Up @@ -626,7 +643,8 @@ export async function downloadBackup(
String(date.getHours()) +
String(date.getMinutes()) +
String(date.getSeconds());
const zipFilePath = chosenPath + 'Backup_' + now + '.zip';
const zipFilePath = chosenPath + 'Backup_' + now + '';
// const zipFilePath = chosenPath + 'Backup_' + now + '.zip';

Logger.info(`[BACKUPS] Downloading backup to ${zipFilePath}`);

Expand All @@ -638,6 +656,7 @@ export async function downloadBackup(
Logger.info(`[BACKUPS] Aborting download for device ${device.name}`);
if (abortController && !abortController.signal.aborted) {
abortController.abort();
fs.unlinkSync(zipFilePath);
}
} catch (error) {
Logger.error(`[BACKUPS] Error while aborting download: ${error}`);
Expand All @@ -656,6 +675,7 @@ export async function downloadBackup(
await downloadDeviceBackupZip(device, foldersIdToDownload, zipFilePath, {
updateProgress: (progress: number) => {
if (abortController?.signal.aborted) return;
Logger.info(`[BACKUPS] Download progress: ${progress}`);
broadcastToWindows('backup-download-progress', {
id: device.uuid,
progress: Math.round(progress),
Expand Down
Loading

0 comments on commit 6679f9f

Please sign in to comment.