diff --git a/release/app/yarn.lock b/release/app/yarn.lock index b4f8416f3..d89a9eb15 100644 --- a/release/app/yarn.lock +++ b/release/app/yarn.lock @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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== diff --git a/src/apps/shared/fs/write-readable-to-file.ts b/src/apps/shared/fs/write-readable-to-file.ts index 857cc509f..913fad799 100644 --- a/src/apps/shared/fs/write-readable-to-file.ts +++ b/src/apps/shared/fs/write-readable-to-file.ts @@ -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 { + static write( + readable: Readable, + path: PathLike, + expectedSize?: number + ): Promise { const writableStream = fs.createWriteStream(path); readable.pipe(writableStream); return new Promise((resolve, reject) => { - writableStream.on('finish', resolve); + writableStream.on('finish', async () => { + const { size } = await stat(path); + + if (!expectedSize) { + resolve(); + return; + } + if (size !== expectedSize) { + reject('Wried file does not have expected size'); + return; + } + + resolve(); + }); + writableStream.on('error', reject); }); } diff --git a/src/context/virtual-drive/contents/application/ContentsDownloader.ts b/src/context/virtual-drive/contents/application/ContentsDownloader.ts index 0ea20cc02..c6ad91248 100644 --- a/src/context/virtual-drive/contents/application/ContentsDownloader.ts +++ b/src/context/virtual-drive/contents/application/ContentsDownloader.ts @@ -47,34 +47,18 @@ export class ContentsDownloader { downloader.on('progress', async () => { Logger.debug('[Server] Download progress'); - const result = await cb(true, filePath); - const hydrationProgress = result.progress; - - if (result.finished) { - downloader.forceStop(); - Logger.debug('Downloader force stop', this.readableDownloader); - this.readableDownloader?.destroy(); - this.readableDownloader?.emit('close'); - this.ipc.send('FILE_DOWNLOADED', { - name: file.name, - extension: file.type, - nameWithExtension: file.nameWithExtension, - size: file.size, - processInfo: { elapsedTime: downloader.elapsedTime() }, - }); - ipcRenderer.send('CHECK_SYNC'); - } else { - this.ipc.send('FILE_DOWNLOADING', { - name: file.name, - extension: file.type, - nameWithExtension: file.nameWithExtension, - size: file.size, - processInfo: { - elapsedTime: downloader.elapsedTime(), - progress: hydrationProgress, - }, - }); - } + const { progress } = await cb(true, filePath); + + this.ipc.send('FILE_DOWNLOADING', { + name: file.name, + extension: file.type, + nameWithExtension: file.nameWithExtension, + size: file.size, + processInfo: { + elapsedTime: downloader.elapsedTime(), + progress, + }, + }); }); downloader.on('error', (error: Error) => { @@ -99,6 +83,7 @@ export class ContentsDownloader { const readable = await downloader.download(file); this.readableDownloader = readable; + const localContents = LocalFileContents.downloadedFrom( file, readable, @@ -110,6 +95,14 @@ export class ContentsDownloader { const events = localContents.pullDomainEvents(); await this.eventBus.publish(events); + this.ipc.send('FILE_DOWNLOADED', { + name: file.name, + extension: file.type, + nameWithExtension: file.nameWithExtension, + size: file.size, + processInfo: { elapsedTime: downloader.elapsedTime() }, + }); + return write; } } diff --git a/src/context/virtual-drive/contents/infrastructure/FSLocalFileWriter.ts b/src/context/virtual-drive/contents/infrastructure/FSLocalFileWriter.ts index 51b26fcc2..e6aaf4f0c 100644 --- a/src/context/virtual-drive/contents/infrastructure/FSLocalFileWriter.ts +++ b/src/context/virtual-drive/contents/infrastructure/FSLocalFileWriter.ts @@ -16,7 +16,7 @@ export class FSLocalFileWriter implements LocalFileWriter { const filePath = path.join(location, contents.nameWithExtension); - await WriteReadableToFile.write(contents.stream, filePath); + await WriteReadableToFile.write(contents.stream, filePath, contents.size); return filePath; } diff --git a/yarn.lock b/yarn.lock index b08729e41..470a2aebd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1285,7 +1285,7 @@ resolved "https://npm.pkg.github.com/download/@internxt/lib/1.2.0/172d7929abb3dc34fda044ad9977875791f7a471#172d7929abb3dc34fda044ad9977875791f7a471" integrity sha512-14byNxSU0S0KSc3g+BWiJb7/fcHUfqxkHQRz9fwJhAHNmgOo+Bhx13xXk07KKUzeNX1JymSGEZkVCk0AOQiM+Q== -"@internxt/sdk@^1.4.27", "@internxt/sdk@^1.4.33": +"@internxt/sdk@^1.4.27": version "1.4.35" resolved "https://npm.pkg.github.com/download/@internxt/sdk/1.4.35/d947a5608ce9c16dbf22984f3b4ae3a0c4bd87cb#d947a5608ce9c16dbf22984f3b4ae3a0c4bd87cb" integrity sha512-WX5cJiRoj8buRobAq+zRPKNavZ09vbCNdw9PVtEG6A5okK4wYIaGqbWBTldffgrO4JgtyNbMqxUCDD0i0UUSCQ== @@ -1294,6 +1294,15 @@ query-string "^7.1.0" uuid "^8.3.2" +"@internxt/sdk@^1.4.68": + version "1.4.71" + resolved "https://npm.pkg.github.com/download/@internxt/sdk/1.4.71/eb6f1cd524f2a861afdb1f14483848910bc0d0a7#eb6f1cd524f2a861afdb1f14483848910bc0d0a7" + integrity sha512-pirbb8odDDdqJxXwpNapVdLlhSw9di2emklzVza81JuWzXeyOlwpgvu65JU0RFZ+AjSl+0mJR4fmdfbh3evTEA== + dependencies: + axios "^0.24.0" + query-string "^7.1.0" + uuid "^8.3.2" + "@isaacs/cliui@^8.0.2": version "8.0.2" resolved "https://registry.yarnpkg.com/@isaacs/cliui/-/cliui-8.0.2.tgz#b37667b7bc181c168782259bab42474fbf52b550"