Skip to content

Commit

Permalink
Merge pull request #504 from internxt/feat/new-traverse
Browse files Browse the repository at this point in the history
Change: Progressive file retrieval implemented
  • Loading branch information
ArceDanielShok authored Jul 19, 2024
2 parents 9752c7d + 1af1bcc commit e5b368b
Show file tree
Hide file tree
Showing 42 changed files with 1,053 additions and 396 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "internxt-drive",
"version": "2.0.10",
"version": "2.1.0",
"author": "Internxt <[email protected]>",
"description": "Internxt Drive client UI",
"license": "AGPL-3.0",
Expand Down Expand Up @@ -95,8 +95,7 @@
"win": {
"target": [
"nsis"
],
"certificateSubjectName": "Internxt Universal Technologies SL"
]
},
"linux": {
"target": [
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.0.10",
"version": "2.1.0",
"description": "Internxt Drive client UI",
"main": "./dist/main/main.js",
"author": "Internxt <[email protected]>",
Expand Down
10 changes: 10 additions & 0 deletions src/apps/main/analytics/drive-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ ipcMainDrive.on('FILE_DOWNLOADED', (_, payload) => {
});
});

ipcMainDrive.on('FILE_DOWNLOAD_CANCEL', (_, payload) => {
const { name, extension, size } = payload;

trackEvent('Download Aborted', {
file_name: name,
file_extension: extension,
file_size: size,
});
});

ipcMainDrive.on('FILE_CLONNED', (_, payload) => {
const { name, extension, size, processInfo } = payload;

Expand Down
3 changes: 2 additions & 1 deletion src/apps/main/auth/refresh-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ const authorizedClient = getClient();

async function obtainTokens() {
try {
Logger.debug('[TOKEN] Obtaining new tokens');
const res = await authorizedClient.get(
`${process.env.API_URL}/api/user/refresh`
`${process.env.API_URL}/user/refresh`
);

return res.data;
Expand Down
37 changes: 26 additions & 11 deletions src/apps/main/background-processes/sync-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async function healthCheck() {
resolve();
});

const millisecondsToWait = 8_000;
const millisecondsToWait = 5_000;

setTimeout(() => {
reject(
Expand All @@ -55,7 +55,7 @@ function scheduleHeathCheck() {
const relaunchOnFail = () =>
healthCheck()
.then(() => {
// Logger.debug('Health check succeeded');
Logger.debug('Health check succeeded');
})
.catch(() => {
const warning = 'Health check failed, relaunching the worker';
Expand All @@ -71,7 +71,7 @@ function scheduleHeathCheck() {
spawnSyncEngineWorker();
});

healthCheckSchedule = nodeSchedule.scheduleJob('*/30 * * * * *', async () => {
healthCheckSchedule = nodeSchedule.scheduleJob('*/20 * * * * *', async () => {
const workerIsPending = checkSyncEngineInProcess(15_000);
Logger.debug(
'Health check',
Expand Down Expand Up @@ -166,7 +166,7 @@ export async function stopSyncEngineWatcher() {
});

try {
worker?.webContents.send('STOP_SYNC_ENGINE_PROCESS');
worker?.webContents?.send('STOP_SYNC_ENGINE_PROCESS');

await stopPromise;
} catch (err) {
Expand Down Expand Up @@ -219,7 +219,7 @@ async function stopAndClearSyncEngineWatcher() {
});

try {
worker?.webContents.send('STOP_AND_CLEAR_SYNC_ENGINE_PROCESS');
worker?.webContents?.send('STOP_AND_CLEAR_SYNC_ENGINE_PROCESS');

await response;
} catch (err) {
Expand All @@ -235,8 +235,13 @@ async function stopAndClearSyncEngineWatcher() {

export function updateSyncEngine() {
try {
if (worker?.webContents && !worker?.isDestroyed()) {
worker?.webContents.send('UPDATE_SYNC_ENGINE_PROCESS');
if (
worker &&
!worker.isDestroyed() &&
worker.webContents &&
!worker.webContents.isDestroyed()
) {
worker.webContents?.send('UPDATE_SYNC_ENGINE_PROCESS');
}
} catch (err) {
// TODO: handle error
Expand All @@ -247,17 +252,27 @@ export function updateSyncEngine() {

export function fallbackSyncEngine() {
try {
if (worker?.webContents && !worker?.isDestroyed()) {
worker?.webContents.send('FALLBACK_SYNC_ENGINE_PROCESS');
if (
worker &&
!worker.isDestroyed() &&
worker.webContents &&
!worker.webContents.isDestroyed()
) {
worker?.webContents?.send('FALLBACK_SYNC_ENGINE_PROCESS');
}
} catch (err) {
Logger.error(err);
}
}
export async function sendUpdateFilesInSyncPending(): Promise<string[]> {
try {
if (worker?.webContents && !worker?.isDestroyed()) {
worker?.webContents.send('UPDATE_UNSYNC_FILE_IN_SYNC_ENGINE_PROCESS');
if (
worker &&
!worker.isDestroyed() &&
worker.webContents &&
!worker.webContents.isDestroyed()
) {
worker?.webContents?.send('UPDATE_UNSYNC_FILE_IN_SYNC_ENGINE_PROCESS');
}
return [];
} catch (err) {
Expand Down
12 changes: 6 additions & 6 deletions src/apps/main/device/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const addUnknownDeviceIssue = (error: Error) => {
};

function createDevice(deviceName: string) {
return fetch(`${process.env.API_URL}/api/backup/deviceAsFolder`, {
return fetch(`${process.env.API_URL}/backup/deviceAsFolder`, {
method: 'POST',
headers: getHeaders(true),
body: JSON.stringify({ deviceName }),
Expand Down Expand Up @@ -76,7 +76,7 @@ export async function getOrCreateDevice() {

if (deviceIsDefined) {
const res = await fetch(
`${process.env.API_URL}/api/backup/deviceAsFolder/${savedDeviceId}`,
`${process.env.API_URL}/backup/deviceAsFolder/${savedDeviceId}`,
{
method: 'GET',
headers: getHeaders(),
Expand Down Expand Up @@ -110,7 +110,7 @@ export async function renameDevice(deviceName: string): Promise<Device> {
const deviceId = getDeviceId();

const res = await fetch(
`${process.env.API_URL}/api/backup/deviceAsFolder/${deviceId}`,
`${process.env.API_URL}/backup/deviceAsFolder/${deviceId}`,
{
method: 'PATCH',
headers: getHeaders(true),
Expand Down Expand Up @@ -221,7 +221,7 @@ export async function addBackup(): Promise<void> {

async function fetchFolder(folderId: number) {
const res = await fetch(
`${process.env.API_URL}/api/storage/v2/folder/${folderId}`,
`${process.env.API_URL}/storage/v2/folder/${folderId}`,
{
method: 'GET',
headers: getHeaders(true),
Expand All @@ -236,7 +236,7 @@ async function fetchFolder(folderId: number) {

export async function deleteBackup(backup: Backup): Promise<void> {
const res = await fetch(
`${process.env.API_URL}/api/storage/folder/${backup.id}`,
`${process.env.API_URL}/storage/folder/${backup.id}`,
{
method: 'DELETE',
headers: getHeaders(true),
Expand Down Expand Up @@ -286,7 +286,7 @@ export async function changeBackupPath(currentPath: string): Promise<boolean> {
}

const res = await fetch(
`${process.env.API_URL}/api/storage/folder/${existingBackup.folderId}/meta`,
`${process.env.API_URL}/storage/folder/${existingBackup.folderId}/meta`,
{
method: 'POST',
headers: getHeaders(true),
Expand Down
26 changes: 26 additions & 0 deletions src/apps/main/fordwardToWindows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ ipcMainDrive.on('FILE_DOWNLOADING', (_, payload) => {
});
});

ipcMainDrive.on('SYNCING', () => {
setIsProcessing(true);
});

ipcMainDrive.on('SYNCED', () => {
setIsProcessing(false);
});

ipcMainDrive.on('FILE_PREPARING', (_, payload) => {
const { nameWithExtension, processInfo } = payload;
setIsProcessing(true);
Expand All @@ -34,12 +42,21 @@ ipcMainDrive.on('FILE_PREPARING', (_, payload) => {
});

ipcMainDrive.on('FILE_DOWNLOADED', (_, payload) => {
setIsProcessing(false);
const { nameWithExtension } = payload;
broadcastToWindows('sync-info-update', {
action: 'DOWNLOADED',
name: nameWithExtension,
});
});
ipcMainDrive.on('FILE_DOWNLOAD_CANCEL', (_, payload) => {
setIsProcessing(false);
const { nameWithExtension } = payload;
broadcastToWindows('sync-info-update', {
action: 'DOWNLOAD_CANCEL',
name: nameWithExtension,
});
});

ipcMainDrive.on('FILE_MOVED', (_, payload) => {
const { nameWithExtension } = payload;
Expand Down Expand Up @@ -97,6 +114,15 @@ ipcMainDrive.on('FILE_UPLOADING', (_, payload) => {
});
});

ipcMainDrive.on('FILE_UPLOADED', (_, payload) => {
const { nameWithExtension } = payload;
setIsProcessing(false);
broadcastToWindows('sync-info-update', {
action: 'UPLOADED',
name: nameWithExtension,
});
});

ipcMainDrive.on('FILE_CREATED', (_, payload) => {
const { nameWithExtension } = payload;
setIsProcessing(false);
Expand Down
Loading

0 comments on commit e5b368b

Please sign in to comment.