Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patch: this awaits for files to download ? #459

Merged
merged 6 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.0.4",
"version": "2.0.5",
"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.0.4",
"version": "2.0.5",
"description": "Internxt Drive client UI",
"main": "./dist/main/main.js",
"author": "Internxt <[email protected]>",
Expand Down
50 changes: 49 additions & 1 deletion release/app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@
enabled "2.0.x"
kuler "^2.0.0"

"@hapi/hoek@^9.0.0", "@hapi/hoek@^9.3.0":
version "9.3.0"
resolved "https://registry.yarnpkg.com/@hapi/hoek/-/hoek-9.3.0.tgz#8368869dcb735be2e7f5cb7647de78e167a251fb"
integrity sha512-/c6rf4UJlmHlC9b5BaNvzAcFv7HZ2QHaV0D4/HNlBdvFnvQq8RI4kYdhyPCl7Xj+oWvTWQ8ujhqS53LIgAe6KQ==

"@hapi/topo@^5.1.0":
version "5.1.0"
resolved "https://registry.yarnpkg.com/@hapi/topo/-/topo-5.1.0.tgz#dc448e332c6c6e37a4dc02fd84ba8d44b9afb012"
integrity sha512-foQZKJig7Ob0BMAYBfcJk8d77QtOe7Wo4ox7ff1lQYoNNAb6jwcY1ncdoy2e9wQZzvNy7ODZCYJkK8kzmcAnAg==
dependencies:
"@hapi/hoek" "^9.0.0"

"@ioredis/commands@^1.1.1":
version "1.2.0"
resolved "https://registry.npmjs.org/@ioredis/commands/-/commands-1.2.0.tgz"
Expand Down Expand Up @@ -91,6 +103,23 @@
component-type "^1.2.1"
join-component "^1.1.0"

"@sideway/address@^4.1.5":
version "4.1.5"
resolved "https://registry.yarnpkg.com/@sideway/address/-/address-4.1.5.tgz#4bc149a0076623ced99ca8208ba780d65a99b9d5"
integrity sha512-IqO/DUQHUkPeixNQ8n0JA6102hT9CmaljNTPmQ1u8MEhBo/R4Q8eKLN/vGZxuebwOroDB4cbpjheD4+/sKFK4Q==
dependencies:
"@hapi/hoek" "^9.0.0"

"@sideway/formula@^3.0.1":
version "3.0.1"
resolved "https://registry.yarnpkg.com/@sideway/formula/-/formula-3.0.1.tgz#80fcbcbaf7ce031e0ef2dd29b1bfc7c3f583611f"
integrity sha512-/poHZJJVjx3L+zVD6g9KgHfYnb443oi7wLu/XKojDviHy6HOEOA6z1Trk5aR1dGcmPenJEgb2sK2I80LeS3MIg==

"@sideway/pinpoint@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@sideway/pinpoint/-/pinpoint-2.0.0.tgz#cff8ffadc372ad29fd3f78277aeb29e632cc70df"
integrity sha512-RNiOoTPkptFtSVzQevY/yWtZwf/RxyVnPy/OcA9HBM3MlGDnBEYL5B41H0MTn0Uec8Hi+2qUtTfG2WWZBmMejQ==

"@sqltools/formatter@^1.2.5":
version "1.2.5"
resolved "https://registry.npmjs.org/@sqltools/formatter/-/formatter-1.2.5.tgz"
Expand Down Expand Up @@ -374,6 +403,11 @@ dotenv@^16.0.3:
resolved "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz"
integrity sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==

dotenv@^16.4.1:
version "16.4.4"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.4.tgz#a26e7bb95ebd36272ebb56edb80b826aecf224c1"
integrity sha512-XvPXc8XAQThSjAbY6cQ/9PcBXmFoWuw1sQ3b8HqUCR6ziGXjkTi//kB9SWa2UwqlgdAIuRqAa/9hVljzPehbYg==

emoji-regex@^8.0.0:
version "8.0.0"
resolved "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz"
Expand Down Expand Up @@ -530,6 +564,17 @@ is-stream@^2.0.0:
resolved "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz"
integrity sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==

joi@^17.12.0:
version "17.12.1"
resolved "https://registry.yarnpkg.com/joi/-/joi-17.12.1.tgz#3347ecf4cd3301962d42191c021b165eef1f395b"
integrity sha512-vtxmq+Lsc5SlfqotnfVjlViWfOL9nt/avKNbKYizwf6gsCfq9NYY/ceYRMFD8XDdrjJ9abJyScWmhmIiy+XRtQ==
dependencies:
"@hapi/hoek" "^9.3.0"
"@hapi/topo" "^5.1.0"
"@sideway/address" "^4.1.5"
"@sideway/formula" "^3.0.1"
"@sideway/pinpoint" "^2.0.0"

join-component@^1.1.0:
version "1.1.0"
resolved "https://registry.npmjs.org/join-component/-/join-component-1.1.0.tgz"
Expand Down Expand Up @@ -1031,7 +1076,10 @@ uuid@^9.0.0:
virtual-drive@../../../node-win:
version "1.0.1"
dependencies:
dotenv "^16.4.1"
joi "^17.12.0"
tsconfig-paths "^4.2.0"
yargs "^17.7.2"

winston-transport@^4.5.0:
version "4.5.0"
Expand Down Expand Up @@ -1106,7 +1154,7 @@ yargs@^16.0.0:
y18n "^5.0.5"
yargs-parser "^20.2.2"

yargs@^17.6.2:
yargs@^17.6.2, yargs@^17.7.2:
version "17.7.2"
resolved "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz"
integrity sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==
Expand Down
10 changes: 10 additions & 0 deletions src/apps/main/fordwardToWindows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ ipcMainDrive.on('FILE_DOWNLOADING', (_, payload) => {
});
});

ipcMainDrive.on('FILE_PREPARING', (_, payload) => {
const { nameWithExtension, processInfo } = payload;

broadcastToWindows('sync-info-update', {
action: 'PREPARING',
name: nameWithExtension,
progress: processInfo.progress,
});
});

ipcMainDrive.on('FILE_DOWNLOADED', (_, payload) => {
const { nameWithExtension } = payload;

Expand Down
4 changes: 4 additions & 0 deletions src/apps/main/tray/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ ipcMainDrive.on('FILE_DOWNLOADING', () => {
setTrayStatus('SYNCING');
});

ipcMainDrive.on('FILE_PREPARING', () => {
setTrayStatus('SYNCING');
});

ipcMainDrive.on('FILE_DOWNLOADED', () => {
setTrayStatus('IDLE');
});
Expand Down
1 change: 1 addition & 0 deletions src/apps/renderer/localize/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
"activity": {
"operation": {
"downloading": "Downloading",
"preparing": "Preparing",
"decrypting": "Decrypting",
"uploading": "Uploading",
"encrypting": "Encrypting",
Expand Down
1 change: 1 addition & 0 deletions src/apps/renderer/localize/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
"activity": {
"operation": {
"downloading": "Descargando",
"preparing": "Preparando",
"decrypting": "Desencriptando",
"uploading": "Subiendo",
"encrypting": "Encriptando",
Expand Down
1 change: 1 addition & 0 deletions src/apps/renderer/localize/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
"activity": {
"operation": {
"downloading": "Téléchargement",
"preparing": "Préparation",
"decrypting": "Décryptage",
"uploading": "téléchargement",
"encrypting": "Encryptage",
Expand Down
3 changes: 3 additions & 0 deletions src/apps/renderer/pages/Widget/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export function Item({
description = progress
? translate('widget.body.activity.operation.downloading')
: translate('widget.body.activity.operation.decrypting');
} else if (action === 'PREPARING') {
description = translate('widget.body.activity.operation.preparing');
} else if (action === 'UPLOADING') {
description = progress
? translate('widget.body.activity.operation.uploading')
Expand Down Expand Up @@ -94,6 +96,7 @@ export function Item({
{action &&
(action === 'UPLOADING' ||
action === 'DOWNLOADING' ||
action === 'PREPARING' ||
action === 'RENAMING' ||
action === 'DELETING') && (
<CircularProgressbar
Expand Down
1 change: 1 addition & 0 deletions src/apps/shared/IPC/events/drive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type UploadEvents = {

type DownloadEvents = {
FILE_DOWNLOADING: (payload: FileProgressInfo) => void;
FILE_PREPARING: (payload: FileProgressInfo) => void;
FILE_DOWNLOADED: (payload: FileProgressInfo) => void;
FILE_DOWNLOAD_ERROR: (payload: FileErrorInfo) => void;
};
Expand Down
1 change: 1 addition & 0 deletions src/apps/shared/IPC/events/sync-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export type FilesEvents = {
}) => void;

FILE_DOWNLOADING: (payload: FileUpdatePayload) => void;
FILE_PREPARING: (payload: FileUpdatePayload) => void;
FILE_DOWNLOADED: (payload: FileUpdatePayload) => void;
FILE_UPLOAD_ERROR: (payload: {
name: string;
Expand Down
23 changes: 21 additions & 2 deletions src/apps/shared/fs/write-readable-to-file.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
import fs, { PathLike } from 'fs';
import { stat } from 'fs/promises';
import { Readable } from 'stream';

export class WriteReadableToFile {
static write(readable: Readable, path: PathLike): Promise<void> {
static write(
readable: Readable,
path: PathLike,
expectedSize?: number
): Promise<void> {
const writableStream = fs.createWriteStream(path);

readable.pipe(writableStream);

return new Promise<void>((resolve, reject) => {
writableStream.on('finish', resolve);
writableStream.on('finish', async () => {
const { size } = await stat(path);

if (!expectedSize) {
resolve();
return;
}
if (size !== expectedSize) {
reject(new Error('Wried file does not have expected size'));
return;
}

resolve();
});

writableStream.on('error', reject);
});
}
Expand Down
7 changes: 6 additions & 1 deletion src/apps/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,12 @@ export type ProcessInfoUpdatePayload =
| (ProcessInfoBase &
(
| {
action: 'UPLOADING' | 'DOWNLOADING' | 'RENAMING' | 'DELETING';
action:
| 'UPLOADING'
| 'DOWNLOADING'
| 'PREPARING'
| 'RENAMING'
| 'DELETING';
progress: number;
}
| {
Expand Down
57 changes: 31 additions & 26 deletions src/apps/sync-engine/BindingManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,8 @@ export class BindingsManager {
callback: CallbackDownload
) => {
try {
const path = await controllers.downloadFile.execute(
contentsId,
callback
);
Logger.debug('Execute Fetch Data Callback, sending path:', path);
Logger.debug('[Fetch Data Callback] Donwloading begins');
const path = await controllers.downloadFile.execute(contentsId);
const file = controllers.downloadFile.fileFinderByContentsId(
contentsId
.replace(
Expand All @@ -110,35 +107,43 @@ export class BindingsManager {
)
.split(':')[1]
);
Logger.debug('[Fetch Data Callback] Preparing begins', path);
let finished = false;
while (!finished) {
const result = await callback(true, path);
finished = result.finished;
if (this.progressBuffer == result.progress) {
break;
} else {
this.progressBuffer = result.progress;
try {
while (!finished) {
const result = await callback(true, path);
finished = result.finished;
Logger.debug('callback result', result);

if (finished && result.progress === 0) {
throw new Error('Result progress is 0');
} else if (this.progressBuffer == result.progress) {
break;
} else {
this.progressBuffer = result.progress;
}
Logger.debug('condition', finished);
ipcRendererSyncEngine.send('FILE_PREPARING', {
name: file.name,
extension: file.type,
nameWithExtension: file.nameWithExtension,
size: file.size,
processInfo: {
elapsedTime: 0,
progress: result.progress,
},
});
}
Logger.debug('condition', finished);
ipcRendererSyncEngine.send('FILE_DOWNLOADING', {
name: file.name,
extension: file.type,
nameWithExtension: file.nameWithExtension,
size: file.size,
processInfo: {
elapsedTime: 0,
progress: result.progress,
},
});
}
this.progressBuffer = 0;

this.progressBuffer = 0;
try {
await controllers.notifyPlaceholderHydrationFinished.execute(
contentsId
);

await this.container.virtualDrive.closeDownloadMutex();
} catch (error) {
Logger.error('notify: ', error);
await this.container.virtualDrive.closeDownloadMutex();
}

// Esperar hasta que la ejecución de fetchDataCallback esté completa antes de continuar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Logger from 'electron-log';
import { ContentsDownloader } from '../../../../context/virtual-drive/contents/application/ContentsDownloader';
import { FileFinderByContentsId } from '../../../../context/virtual-drive/files/application/FileFinderByContentsId';
import { FilePlaceholderId } from '../../../../context/virtual-drive/files/domain/PlaceholderId';
import { CallbackDownload } from '../../BindingManager';
import { CallbackController } from './CallbackController';

export class DownloadFileController extends CallbackController {
Expand All @@ -13,25 +12,21 @@ export class DownloadFileController extends CallbackController {
super();
}

private async action(id: string, cb: CallbackDownload): Promise<string> {
private async action(id: string): Promise<string> {
const file = this.fileFinder.run(id);

return await this.downloader.run(file, cb);
return await this.downloader.run(file);
}

fileFinderByContentsId(contentsId: string) {
return this.fileFinder.run(contentsId);
}

async execute(
filePlaceholderId: FilePlaceholderId,
cb: CallbackDownload
): Promise<string> {
async execute(filePlaceholderId: FilePlaceholderId): Promise<string> {
const trimmedId = this.trim(filePlaceholderId);

try {
const [_, contentsId] = trimmedId.split(':');
return await this.action(contentsId, cb);
return await this.action(contentsId);
} catch (error: unknown) {
Logger.error(
'Error downloading a file, going to refresh and retry: ',
Expand All @@ -42,8 +37,7 @@ export class DownloadFileController extends CallbackController {
setTimeout(async () => {
try {
const [_, contentsId] = trimmedId.split(':');
Logger.debug('cb: ', cb);
const result = await this.action(contentsId, cb);
const result = await this.action(contentsId);
resolve(result);
} catch (error) {
reject(error);
Expand Down
Loading
Loading