filemail-sdk 9.4.5 → 9.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/client/uploader/transferUploaderBase.d.ts +1 -0
- package/dist/src/client/uploader/transferUploaderBase.d.ts.map +1 -1
- package/dist/src/client/uploader/transferUploaderBase.js +15 -8
- package/dist/src/client/uploader/transferUploaderBase.js.map +1 -1
- package/dist/src/uploader/api/node/nodeFileServerUdpClient.js +1 -1
- package/dist/src/uploader/api/node/nodeFileServerUdpClient.js.map +1 -1
- package/dist/src/uploader/api/node/nodeFileServerUploadClient.js +3 -3
- package/dist/src/uploader/api/node/nodeFileServerUploadClient.js.map +1 -1
- package/dist/src/uploader/api/web/webFileServerUploadClient.js +1 -1
- package/dist/src/uploader/api/web/webFileServerUploadClient.js.map +1 -1
- package/dist/src/uploader/transferFailureAbortReason.d.ts +4 -0
- package/dist/src/uploader/transferFailureAbortReason.d.ts.map +1 -0
- package/dist/src/uploader/transferFailureAbortReason.js +9 -0
- package/dist/src/uploader/transferFailureAbortReason.js.map +1 -0
- package/dist/src/uploader/transferUpload.d.ts +2 -0
- package/dist/src/uploader/transferUpload.d.ts.map +1 -1
- package/dist/src/uploader/transferUpload.js +18 -3
- package/dist/src/uploader/transferUpload.js.map +1 -1
- package/dist/src/utils/fileSystem/chunkStreamProvider.d.ts +2 -2
- package/dist/src/utils/fileSystem/chunkStreamProvider.d.ts.map +1 -1
- package/dist/src/utils/fileSystem/chunkStreamProvider.js.map +1 -1
- package/dist/src/utils/fileSystem/node/nodeChunkStreamProvider.d.ts +9 -4
- package/dist/src/utils/fileSystem/node/nodeChunkStreamProvider.d.ts.map +1 -1
- package/dist/src/utils/fileSystem/node/nodeChunkStreamProvider.js +117 -26
- package/dist/src/utils/fileSystem/node/nodeChunkStreamProvider.js.map +1 -1
- package/dist/src/utils/fileSystem/web/chunkStreamProvider/webChunkStreamProvider.d.ts +2 -2
- package/dist/src/utils/fileSystem/web/chunkStreamProvider/webChunkStreamProvider.d.ts.map +1 -1
- package/dist/src/utils/fileSystem/web/chunkStreamProvider/webChunkStreamProvider.js +2 -2
- package/dist/src/utils/fileSystem/web/chunkStreamProvider/webChunkStreamProvider.js.map +1 -1
- package/package.json +1 -1
|
@@ -20,6 +20,7 @@ export default abstract class TransferUploaderBase<T extends NodeFileDetails | W
|
|
|
20
20
|
private tryGetApiFilemailError;
|
|
21
21
|
private addHealthMonitorEventListeners;
|
|
22
22
|
private addTransferEventListeners;
|
|
23
|
+
private failTransfer;
|
|
23
24
|
private logTrace;
|
|
24
25
|
private logDebug;
|
|
25
26
|
private logInfo;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transferUploaderBase.d.ts","sourceRoot":"","sources":["../../../../src/client/uploader/transferUploaderBase.ts"],"names":[],"mappings":"AAIA,OAAO,cAAc,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"transferUploaderBase.d.ts","sourceRoot":"","sources":["../../../../src/client/uploader/transferUploaderBase.ts"],"names":[],"mappings":"AAIA,OAAO,cAAc,MAAM,kCAAkC,CAAC;AAW9D,OAAO,KAAK,eAAe,MAAM,gDAAgD,CAAC;AAClF,OAAO,KAAK,MAAM,MAAM,sBAAsB,CAAC;AAC/C,OAAO,KAAK,oBAAoB,MAAM,4BAA4B,CAAC;AACnE,OAAO,KAAK,gBAAgB,MAAM,uBAAuB,CAAC;AAE1D,OAAO,KAAK,sBAAsB,MAAM,6BAA6B,CAAC;AACtE,OAAO,KAAK,cAAc,MAAM,8CAA8C,CAAC;AAE/E,OAAO,KAAK,6BAA6B,MAAM,mDAAmD,CAAC;AAInG,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,oBAAoB,CAAC,CAAC,SAAS,eAAe,GAAG,cAAc,CAAE,YAAW,gBAAgB,CAAC,CAAC,CAAC;;gBAwB7G,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,sBAAsB,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,6BAA6B,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM;IAiBrN,IAAI,QAAQ,IAAI,cAAc,CAAC,CAAC,CAAC,CAEhC;IAED,IAAI,aAAa,IAAI,6BAA6B,CAEjD;IAED,IAAI,YAAY,IAAI,MAAM,GAAG,SAAS,CAErC;IAEM,KAAK;IAWL,IAAI;IAWE,MAAM,CAAC,WAAW,CAAC,EAAE,WAAW;IAMvC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA+C5B,OAAO,CAAC,wBAAwB;IAgBhC,OAAO,CAAC,sBAAsB;IAU9B,OAAO,CAAC,8BAA8B;IAuBtC,OAAO,CAAC,yBAAyB;IA4DjC,OAAO,CAAC,YAAY;IASpB,OAAO,CAAC,QAAQ;IAKhB,OAAO,CAAC,QAAQ;IAKhB,OAAO,CAAC,OAAO;IAKf,OAAO,CAAC,UAAU;IAKlB,OAAO,CAAC,QAAQ;IAKhB,OAAO,CAAC,mBAAmB;IAO3B,OAAO,CAAC,yBAAyB;IAYjC,OAAO,CAAC,iBAAiB;CAG5B"}
|
|
@@ -6,6 +6,7 @@ import TransferStatus from "../../utils/types/transferStatus.js";
|
|
|
6
6
|
import TransferUploadEvent from "../../uploader/transferUploadEvent.js";
|
|
7
7
|
import FsError from "../../utils/fileSystem/fsError.js";
|
|
8
8
|
import TransferUploadError from "../../uploader/transferUploadError.js";
|
|
9
|
+
import { createTransferFailureAbortReason } from "../../uploader/transferFailureAbortReason.js";
|
|
9
10
|
import logEventPropertyName from "../../utils/logging/logEventPropertyNames.js";
|
|
10
11
|
import ApiFilemailError from "../../utils/api/apiFilemailError.js";
|
|
11
12
|
import logHealthyStatus from "../loggers/utils/logHealthyStatus.js";
|
|
@@ -48,21 +49,21 @@ export default class TransferUploaderBase {
|
|
|
48
49
|
return this.#failedReason;
|
|
49
50
|
}
|
|
50
51
|
pause() {
|
|
51
|
-
this.logInfo(`Pause called`);
|
|
52
|
+
this.logInfo(`Pause called on uploader client`);
|
|
52
53
|
if (!this.#pauseController)
|
|
53
54
|
throw new TransferUploadError(`Can't pause not started transfer`);
|
|
54
55
|
this.#isShuttingDown = true;
|
|
55
56
|
this.#pauseController.pause();
|
|
56
57
|
}
|
|
57
58
|
stop() {
|
|
58
|
-
this.logInfo(`Stop called`);
|
|
59
|
+
this.logInfo(`Stop called on uploader client`);
|
|
59
60
|
if (!this.#abortController)
|
|
60
61
|
throw new TransferUploadError(`Can't stop not started transfer`);
|
|
61
62
|
this.#isShuttingDown = true;
|
|
62
|
-
this.#abortController.abort();
|
|
63
|
+
this.#abortController.abort(new Error(`Transfer stop requested`));
|
|
63
64
|
}
|
|
64
65
|
async cancel(abortSignal) {
|
|
65
|
-
this.logInfo(`Cancel called`);
|
|
66
|
+
this.logInfo(`Cancel called on uploader client`);
|
|
66
67
|
await this.#transfer.cancel(abortSignal);
|
|
67
68
|
}
|
|
68
69
|
async start() {
|
|
@@ -149,13 +150,13 @@ export default class TransferUploaderBase {
|
|
|
149
150
|
const fullFilePathOrName = this.getFullFilePathOrFileName(eventArgs.fileStatus);
|
|
150
151
|
if (isFileAccessError && !this.#isShuttingDown) {
|
|
151
152
|
this.#failedReason = `Can't read ${fullFilePathOrName} anymore`;
|
|
152
|
-
this.logWarning(`${this.#failedReason}.
|
|
153
|
-
this.
|
|
153
|
+
this.logWarning(`${this.#failedReason}. Failing transfer...`);
|
|
154
|
+
this.failTransfer();
|
|
154
155
|
}
|
|
155
156
|
if (!this.#config.infiniteRetries && !this.#isShuttingDown) {
|
|
156
157
|
this.#failedReason = `Uploading ${fullFilePathOrName} failed after ${this.#config.chunkUploadRetryLimit} retries`;
|
|
157
|
-
this.logWarning(`${this.#failedReason}.
|
|
158
|
-
this.
|
|
158
|
+
this.logWarning(`${this.#failedReason}. Failing transfer...`);
|
|
159
|
+
this.failTransfer();
|
|
159
160
|
}
|
|
160
161
|
});
|
|
161
162
|
this.#transfer.addEventListener(TransferUploadEvent.FileUploadFailed, eventArgs => {
|
|
@@ -181,6 +182,12 @@ export default class TransferUploaderBase {
|
|
|
181
182
|
this.#transfer.addEventListener(TransferUploadEvent.FileChunkUploadCompleted, eventArgs => this.logTrace(`File ${eventArgs.fileStatus.fileName} having external id = ${eventArgs.fileStatus.externalId}, chunk starting at ${eventArgs.chunkStartPosition} having size ${eventArgs.chunkSizeInBytes} - upload completed`));
|
|
182
183
|
this.#transfer.addEventListener(TransferUploadEvent.FileChunkUploadCompletedPartially, eventArgs => this.logWarning(`File ${eventArgs.fileStatus.fileName} having external id = ${eventArgs.fileStatus.externalId}, chunk starting at ${eventArgs.chunkStartPosition} having size ${eventArgs.chunkSizeInBytes} - uploaded partially - only ${eventArgs.uploadedBytesCount} bytes uploaded`));
|
|
183
184
|
}
|
|
185
|
+
failTransfer() {
|
|
186
|
+
if (!this.#abortController)
|
|
187
|
+
throw new TransferUploadError(`Can't fail not started transfer`);
|
|
188
|
+
this.#isShuttingDown = true;
|
|
189
|
+
this.#abortController.abort(createTransferFailureAbortReason());
|
|
190
|
+
}
|
|
184
191
|
logTrace(message) {
|
|
185
192
|
const logEntryMetadata = this.getLogEntryMetadata();
|
|
186
193
|
this.#logger.logTrace(message, logEntryMetadata);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transferUploaderBase.js","sourceRoot":"","sources":["../../../../src/client/uploader/transferUploaderBase.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,OAAO,KAAK,MAAM,iBAAiB,CAAC;AACpC,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AAGvC,OAAO,eAAe,MAAM,mCAAmC,CAAC;AAChE,OAAO,cAAc,MAAM,qCAAqC,CAAC;AACjE,OAAO,mBAAmB,MAAM,uCAAuC,CAAC;AACxE,OAAO,OAAO,MAAM,mCAAmC,CAAC;AACxD,OAAO,mBAAmB,MAAM,uCAAuC,CAAC;AACxE,O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,OAAO,OAAQ,WAA+B,CAAC,YAAY,KAAK,QAAQ,CAAC;IAC7E,CAAC;CACJ","sourcesContent":["/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport sleep from \"abortable-sleep\";\nimport throttle from \"lodash.throttle\";\n\nimport TransferUpload from \"../../uploader/transferUpload.js\";\nimport PauseController from \"../../uploader/pauseController.js\";\nimport TransferStatus from \"../../utils/types/transferStatus.js\";\nimport TransferUploadEvent from \"../../uploader/transferUploadEvent.js\";\nimport FsError from \"../../utils/fileSystem/fsError.js\";\nimport TransferUploadError from \"../../uploader/transferUploadError.js\";\nimport logEventPropertyName from \"../../utils/logging/logEventPropertyNames.js\";\nimport ApiFilemailError from \"../../utils/api/apiFilemailError.js\";\nimport logHealthyStatus from \"../loggers/utils/logHealthyStatus.js\";\n\nimport type NodeFileDetails from \"../../utils/fileSystem/node/nodeFileDetails.js\";\nimport type Logger from \"../loggers/logger.js\";\nimport type EnvironmentVariables from \"../environmentVariables.js\";\nimport type TransferUploader from \"./transferUploader.js\";\nimport type ReadonlyTransferUploadStateFile from \"../../uploader/state/readonlyTransferUploadStateFile.js\";\nimport type TransferUploaderConfig from \"./transferUploaderConfig.js\";\nimport type WebFileDetails from \"../../utils/fileSystem/web/webFileDetails.js\";\nimport TransferHealthMonitorEvent from \"../healthMonitor/events/transferHealthMonitorEvent.js\";\nimport type TransferUploaderHealthMonitor from \"../healthMonitor/transferUploaderHealthMonitor.js\";\n\nconst TransferFailedSleepInMs = 500;\n\nexport default abstract class TransferUploaderBase<T extends NodeFileDetails | WebFileDetails> implements TransferUploader<T> {\n #logger: Logger;\n #trackingId: number | string;\n\n #fileDetails: T[];\n\n #config: TransferUploaderConfig;\n #envValues: EnvironmentVariables;\n\n #pauseController?: PauseController;\n #abortController?: AbortController;\n\n #transfer: TransferUpload<T>;\n #healthMonitor: TransferUploaderHealthMonitor;\n\n #isShuttingDown = false;\n\n #failedReason?: string;\n\n #isUdp?: boolean;\n\n #isHealthy = true;\n #logHealthyStatusThrottled: ReturnType<typeof throttle>;\n\n constructor(transfer: TransferUpload<T>, fileDetails: T[], config: TransferUploaderConfig, envValues: EnvironmentVariables, logger: Logger, healthMonitor: TransferUploaderHealthMonitor, trackingId: number | string) {\n this.#logger = logger;\n this.#trackingId = trackingId;\n\n this.#config = config;\n this.#envValues = envValues;\n\n this.#fileDetails = fileDetails;\n this.#transfer = transfer;\n this.#healthMonitor = healthMonitor;\n\n this.#logHealthyStatusThrottled = throttle(logHealthyStatus, 20_000);\n\n this.addHealthMonitorEventListeners();\n this.addTransferEventListeners();\n }\n\n get transfer(): TransferUpload<T> {\n return this.#transfer;\n }\n\n get healthMonitor(): TransferUploaderHealthMonitor {\n return this.#healthMonitor;\n }\n\n get failedReason(): string | undefined {\n return this.#failedReason;\n }\n\n public pause() {\n this.logInfo(`Pause called`);\n\n if (!this.#pauseController)\n throw new TransferUploadError(`Can't pause not started transfer`);\n\n this.#isShuttingDown = true;\n\n this.#pauseController.pause();\n }\n\n public stop() {\n this.logInfo(`Stop called`);\n\n if (!this.#abortController)\n throw new TransferUploadError(`Can't stop not started transfer`);\n\n this.#isShuttingDown = true;\n\n this.#abortController.abort();\n }\n\n public async cancel(abortSignal?: AbortSignal) {\n this.logInfo(`Cancel called`);\n\n await this.#transfer.cancel(abortSignal);\n }\n\n async start(): Promise<void> {\n if (this.#transfer.status !== TransferStatus.Failed && this.#transfer.status !== TransferStatus.Aborted && this.#transfer.status !== TransferStatus.Initialized && this.#transfer.status !== TransferStatus.Paused)\n throw new TransferUploadError(`Transfer is in ${TransferStatus[this.#transfer.status]} state and cannot be run`);\n\n this.logInfo(`Starting upload. Already uploaded bytes: ${this.transfer.uploadedBytesCount}/${this.#transfer.totalSizeInBytes}B, completed files: ${this.transfer.completedFilesCount}.`);\n\n const logMessageEntries = this.#transfer.files.map(f => `'Sending ${f.fileName}' with id = ${f.externalId}. It will be put into '${f.fileDestinationPathInTransfer}' folder.`);\n this.logInfo(`Transfer file details:\\n${logMessageEntries.join(`\\n`)}`);\n\n this.#failedReason = undefined;\n this.#isShuttingDown = false;\n\n this.#pauseController = new PauseController();\n this.#abortController = new AbortController();\n\n this.#healthMonitor.start();\n\n do {\n /* eslint-disable no-await-in-loop */\n try {\n await this.#transfer.run(this.#pauseController.signal, this.#abortController.signal);\n }\n catch (error) {\n this.logError(error as TransferUploadError, `Transfer upload run method exception`);\n\n this.setFailedReasonFromError(error as TransferUploadError);\n this.#isShuttingDown = true;\n\n break;\n }\n finally {\n // @ts-ignore Typescript's brainfart\n if (this.#transfer.status !== TransferStatus.Completed && !this.#isShuttingDown) {\n this.logWarning(`Retrying transfer in ${TransferFailedSleepInMs}ms.`);\n\n await sleep(TransferFailedSleepInMs);\n }\n }\n }\n while (this.#transfer.progressInPercentage < 100 && !this.#isShuttingDown);\n\n this.#healthMonitor.stop();\n this.#logHealthyStatusThrottled.cancel();\n\n this.logInfo(`Upload finished in status ${TransferStatus[this.#transfer.status]} having ${this.#transfer.progressInPercentage}% completed`);\n }\n\n private setFailedReasonFromError(error: TransferUploadError) {\n const apiFilemailError = this.tryGetApiFilemailError(error);\n\n if (apiFilemailError) {\n this.#failedReason = apiFilemailError.reason;\n return;\n }\n\n if (error.message.startsWith(`Unhandled error occured`) && error.cause) {\n this.#failedReason = error.cause.message;\n return;\n }\n\n this.#failedReason = error.message;\n }\n\n private tryGetApiFilemailError(error: Error): ApiFilemailError | null {\n if (error instanceof ApiFilemailError)\n return error;\n\n if (error.cause)\n return this.tryGetApiFilemailError(error.cause);\n\n return null;\n }\n\n private addHealthMonitorEventListeners() {\n this.#healthMonitor.addEventListener(TransferHealthMonitorEvent.Healthy, eventArgs => {\n this.#logHealthyStatusThrottled(this.#logger, true, eventArgs, this.getLogEntryMetadata());\n\n if (!this.#isHealthy)\n logHealthyStatus(this.#logger, true, eventArgs, this.getLogEntryMetadata());\n\n this.#isHealthy = true;\n });\n\n this.#healthMonitor.addEventListener(TransferHealthMonitorEvent.Unhealthy, eventArgs => {\n if (eventArgs.reason.api.status === `Checking` || eventArgs.reason.fileServer.status === `Checking` || eventArgs.reason.internet.status === `Checking`)\n return;\n\n this.#logHealthyStatusThrottled(this.#logger, false, eventArgs, this.getLogEntryMetadata());\n\n if (this.#isHealthy)\n logHealthyStatus(this.#logger, false, eventArgs, this.getLogEntryMetadata());\n\n this.#isHealthy = false;\n });\n }\n\n private addTransferEventListeners() {\n this.#transfer.addEventListener(TransferUploadEvent.TransferUploadModeChosen, eventArgs => {\n this.#isUdp = eventArgs.isUdpMode;\n });\n\n this.#transfer.addEventListener(TransferUploadEvent.FileChunkUploadFailed, eventArgs => {\n const isTimeoutError = eventArgs.error.message.includes(`Timeout`);\n const errorMessage = `File ${eventArgs.fileStatus.externalId} chunk starting at ${eventArgs.chunkStartPosition} having size ${eventArgs.chunkSizeInBytes} upload failed: ${eventArgs.reason}`;\n\n if (this.#isUdp && isTimeoutError)\n this.logDebug(errorMessage);\n else\n this.logError(eventArgs.error, errorMessage);\n\n const isFileAccessError = eventArgs.error.cause instanceof FsError;\n const fullFilePathOrName = this.getFullFilePathOrFileName(eventArgs.fileStatus);\n\n if (isFileAccessError && !this.#isShuttingDown) {\n this.#failedReason = `Can't read ${fullFilePathOrName} anymore`;\n\n this.logWarning(`${this.#failedReason}. Aborting...`);\n this.stop();\n }\n\n if (!this.#config.infiniteRetries && !this.#isShuttingDown) {\n this.#failedReason = `Uploading ${fullFilePathOrName} failed after ${this.#config.chunkUploadRetryLimit} retries`;\n\n this.logWarning(`${this.#failedReason}. Aborting...`);\n this.stop();\n }\n });\n\n this.#transfer.addEventListener(TransferUploadEvent.FileUploadFailed, eventArgs => {\n const isTimeoutError = eventArgs.reason?.includes(`Timeout`);\n const errorMessage = `File ${eventArgs.fileStatus.fileName} having external id = ${eventArgs.fileStatus.externalId} - upload failed: ${eventArgs.reason}`;\n\n if (this.#isUdp && isTimeoutError)\n this.logWarning(errorMessage);\n else\n this.logError(new Error(errorMessage));\n });\n\n this.#transfer.addEventListener(TransferUploadEvent.TransferRun, () => this.logInfo(`Transfer run.`));\n this.#transfer.addEventListener(TransferUploadEvent.TransferAbortRequested, () => this.logInfo(`Transfer abort requested`));\n this.#transfer.addEventListener(TransferUploadEvent.TransferAborted, async () => this.logInfo(`Transfer aborted.`));\n this.#transfer.addEventListener(TransferUploadEvent.TransferCancelRequested, () => this.logInfo(`Transfer cancel requested.`));\n this.#transfer.addEventListener(TransferUploadEvent.TransferCanceled, () => this.logInfo(`Transfer canceled.`));\n this.#transfer.addEventListener(TransferUploadEvent.TransferFailed, () => this.logError(new Error(`Transfer failed.`)));\n this.#transfer.addEventListener(TransferUploadEvent.TransferUploadModeChosen, eventArgs => this.logInfo(`Transfer upload mode chosen. Is UDP: ${eventArgs.isUdpMode}; Latency: ${eventArgs.latency ?? `<unkown>`}; Error: ${eventArgs.error ?? `<none>`}`));\n\n this.#transfer.addEventListener(TransferUploadEvent.TransferCompleted, eventArgs => this.logInfo(`Transfer completed successfully. ID: ${eventArgs.transferId}, URL: ${eventArgs.transferDownloadUrl}`));\n this.#transfer.addEventListener(TransferUploadEvent.FileChunkUploadProgressed, eventArgs => this.logTrace(`File ${eventArgs.fileStatus.fileName} having external id = ${eventArgs.fileStatus.externalId}, chunk starting at ${eventArgs.chunkStartPosition} having size ${eventArgs.chunkSizeInBytes} progressed: ${eventArgs.transferredBytesSinceLastEvent} bytes sinc last event. Total progress: ${this.#transfer?.progressInPercentage}%.`));\n\n this.#transfer.addEventListener(TransferUploadEvent.FileUploadStarted, eventArgs => this.logDebug(`File ${eventArgs.fileStatus.fileName} having external id = ${eventArgs.fileStatus.externalId} - upload started.`));\n this.#transfer.addEventListener(TransferUploadEvent.FileUploadCompleted, eventArgs => this.logDebug(`File ${eventArgs.fileStatus.fileName} having external id = ${eventArgs.fileStatus.externalId} - upload completed.`));\n this.#transfer.addEventListener(TransferUploadEvent.FileChunkUploadStarted, eventArgs => this.logTrace(`File ${eventArgs.fileStatus.fileName} having external id = ${eventArgs.fileStatus.externalId}, chunk starting at ${eventArgs.chunkStartPosition} having size ${eventArgs.chunkSizeInBytes} - upload started`));\n this.#transfer.addEventListener(TransferUploadEvent.FileChunkUploadCompleted, eventArgs => this.logTrace(`File ${eventArgs.fileStatus.fileName} having external id = ${eventArgs.fileStatus.externalId}, chunk starting at ${eventArgs.chunkStartPosition} having size ${eventArgs.chunkSizeInBytes} - upload completed`));\n this.#transfer.addEventListener(TransferUploadEvent.FileChunkUploadCompletedPartially, eventArgs => this.logWarning(`File ${eventArgs.fileStatus.fileName} having external id = ${eventArgs.fileStatus.externalId}, chunk starting at ${eventArgs.chunkStartPosition} having size ${eventArgs.chunkSizeInBytes} - uploaded partially - only ${eventArgs.uploadedBytesCount} bytes uploaded`));\n }\n\n private logTrace(message: string) {\n const logEntryMetadata = this.getLogEntryMetadata();\n this.#logger.logTrace(message, logEntryMetadata);\n }\n\n private logDebug(message: string) {\n const logEntryMetadata = this.getLogEntryMetadata();\n this.#logger.logDebug(message, logEntryMetadata);\n }\n\n private logInfo(message: string) {\n const logEntryMetadata = this.getLogEntryMetadata();\n this.#logger.logInfo(message, logEntryMetadata);\n }\n\n private logWarning(message: string) {\n const logEntryMetadata = this.getLogEntryMetadata();\n this.#logger.logWarning(message, logEntryMetadata);\n }\n\n private logError(error: Error, message?: string) {\n const logEntryMetadata = this.getLogEntryMetadata();\n this.#logger.logError(error, message, logEntryMetadata);\n }\n\n private getLogEntryMetadata() {\n return {\n [logEventPropertyName.TrackingIdPropertyName]: this.#trackingId,\n [logEventPropertyName.TransferIdPropertyName]: this.#transfer.transferId,\n };\n }\n\n private getFullFilePathOrFileName(fileStatus: ReadonlyTransferUploadStateFile): string {\n const fileDetails = this.#fileDetails.find(f => f.externalId === fileStatus.externalId);\n\n if (!fileDetails)\n return fileStatus.fileName;\n\n if (this.isNodeFileDetails(fileDetails))\n return fileDetails.fileFullPath;\n\n return fileDetails.file.name;\n }\n\n private isNodeFileDetails(fileDetails: NodeFileDetails | WebFileDetails): fileDetails is NodeFileDetails {\n return typeof (fileDetails as NodeFileDetails).fileFullPath === `string`;\n }\n}"]}
|
|
1
|
+
{"version":3,"file":"transferUploaderBase.js","sourceRoot":"","sources":["../../../../src/client/uploader/transferUploaderBase.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,OAAO,KAAK,MAAM,iBAAiB,CAAC;AACpC,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AAGvC,OAAO,eAAe,MAAM,mCAAmC,CAAC;AAChE,OAAO,cAAc,MAAM,qCAAqC,CAAC;AACjE,OAAO,mBAAmB,MAAM,uCAAuC,CAAC;AACxE,OAAO,OAAO,MAAM,mCAAmC,CAAC;AACxD,OAAO,mBAAmB,MAAM,uCAAuC,CAAC;AACxE,OAAO,EAAE,gCAAgC,EAAE,MAAM,8CAA8C,CAAC;AAChG,OAAO,oBAAoB,MAAM,8CAA8C,CAAC;AAChF,OAAO,gBAAgB,MAAM,qCAAqC,CAAC;AACnE,OAAO,gBAAgB,MAAM,sCAAsC,CAAC;AASpE,OAAO,0BAA0B,MAAM,uDAAuD,CAAC;AAG/F,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAEpC,MAAM,CAAC,OAAO,OAAgB,oBAAoB;IAC9C,OAAO,CAAS;IAChB,WAAW,CAAkB;IAE7B,YAAY,CAAM;IAElB,OAAO,CAAyB;IAChC,UAAU,CAAuB;IAEjC,gBAAgB,CAAmB;IACnC,gBAAgB,CAAmB;IAEnC,SAAS,CAAoB;IAC7B,cAAc,CAAgC;IAE9C,eAAe,GAAG,KAAK,CAAC;IAExB,aAAa,CAAU;IAEvB,MAAM,CAAW;IAEjB,UAAU,GAAG,IAAI,CAAC;IAClB,0BAA0B,CAA8B;IAExD,YAAY,QAA2B,EAAE,WAAgB,EAAE,MAA8B,EAAE,SAA+B,EAAE,MAAc,EAAE,aAA4C,EAAE,UAA2B;QACjN,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAE9B,IAAI,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AY,EAAE,OAAgB;QAC3C,MAAM,gBAAgB,GAAG,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACpD,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,gBAAgB,CAAC,CAAC;IAC5D,CAAC;IAEO,mBAAmB;QACvB,OAAO;YACH,CAAC,oBAAoB,CAAC,sBAAsB,CAAC,EAAE,IAAI,CAAC,WAAW;YAC/D,CAAC,oBAAoB,CAAC,sBAAsB,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU;SAC3E,CAAC;IACN,CAAC;IAEO,yBAAyB,CAAC,UAA2C;QACzE,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,UAAU,CAAC,UAAU,CAAC,CAAC;QAExF,IAAI,CAAC,WAAW;YACZ,OAAO,UAAU,CAAC,QAAQ,CAAC;QAE/B,IAAI,IAAI,CAAC,iBAAiB,CAAC,WAAW,CAAC;YACnC,OAAO,WAAW,CAAC,YAAY,CAAC;QAEpC,OAAO,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;IACjC,CAAC;IAEO,iBAAiB,CAAC,WAA6C;QACnE,OAAO,OAAQ,WAA+B,CAAC,YAAY,KAAK,QAAQ,CAAC;IAC7E,CAAC;CACJ","sourcesContent":["/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport sleep from \"abortable-sleep\";\nimport throttle from \"lodash.throttle\";\n\nimport TransferUpload from \"../../uploader/transferUpload.js\";\nimport PauseController from \"../../uploader/pauseController.js\";\nimport TransferStatus from \"../../utils/types/transferStatus.js\";\nimport TransferUploadEvent from \"../../uploader/transferUploadEvent.js\";\nimport FsError from \"../../utils/fileSystem/fsError.js\";\nimport TransferUploadError from \"../../uploader/transferUploadError.js\";\nimport { createTransferFailureAbortReason } from \"../../uploader/transferFailureAbortReason.js\";\nimport logEventPropertyName from \"../../utils/logging/logEventPropertyNames.js\";\nimport ApiFilemailError from \"../../utils/api/apiFilemailError.js\";\nimport logHealthyStatus from \"../loggers/utils/logHealthyStatus.js\";\n\nimport type NodeFileDetails from \"../../utils/fileSystem/node/nodeFileDetails.js\";\nimport type Logger from \"../loggers/logger.js\";\nimport type EnvironmentVariables from \"../environmentVariables.js\";\nimport type TransferUploader from \"./transferUploader.js\";\nimport type ReadonlyTransferUploadStateFile from \"../../uploader/state/readonlyTransferUploadStateFile.js\";\nimport type TransferUploaderConfig from \"./transferUploaderConfig.js\";\nimport type WebFileDetails from \"../../utils/fileSystem/web/webFileDetails.js\";\nimport TransferHealthMonitorEvent from \"../healthMonitor/events/transferHealthMonitorEvent.js\";\nimport type TransferUploaderHealthMonitor from \"../healthMonitor/transferUploaderHealthMonitor.js\";\n\nconst TransferFailedSleepInMs = 500;\n\nexport default abstract class TransferUploaderBase<T extends NodeFileDetails | WebFileDetails> implements TransferUploader<T> {\n #logger: Logger;\n #trackingId: number | string;\n\n #fileDetails: T[];\n\n #config: TransferUploaderConfig;\n #envValues: EnvironmentVariables;\n\n #pauseController?: PauseController;\n #abortController?: AbortController;\n\n #transfer: TransferUpload<T>;\n #healthMonitor: TransferUploaderHealthMonitor;\n\n #isShuttingDown = false;\n\n #failedReason?: string;\n\n #isUdp?: boolean;\n\n #isHealthy = true;\n #logHealthyStatusThrottled: ReturnType<typeof throttle>;\n\n constructor(transfer: TransferUpload<T>, fileDetails: T[], config: TransferUploaderConfig, envValues: EnvironmentVariables, logger: Logger, healthMonitor: TransferUploaderHealthMonitor, trackingId: number | string) {\n this.#logger = logger;\n this.#trackingId = trackingId;\n\n this.#config = config;\n this.#envValues = envValues;\n\n this.#fileDetails = fileDetails;\n this.#transfer = transfer;\n this.#healthMonitor = healthMonitor;\n\n this.#logHealthyStatusThrottled = throttle(logHealthyStatus, 20_000);\n\n this.addHealthMonitorEventListeners();\n this.addTransferEventListeners();\n }\n\n get transfer(): TransferUpload<T> {\n return this.#transfer;\n }\n\n get healthMonitor(): TransferUploaderHealthMonitor {\n return this.#healthMonitor;\n }\n\n get failedReason(): string | undefined {\n return this.#failedReason;\n }\n\n public pause() {\n this.logInfo(`Pause called on uploader client`);\n\n if (!this.#pauseController)\n throw new TransferUploadError(`Can't pause not started transfer`);\n\n this.#isShuttingDown = true;\n\n this.#pauseController.pause();\n }\n\n public stop() {\n this.logInfo(`Stop called on uploader client`);\n\n if (!this.#abortController)\n throw new TransferUploadError(`Can't stop not started transfer`);\n\n this.#isShuttingDown = true;\n\n this.#abortController.abort(new Error(`Transfer stop requested`));\n }\n\n public async cancel(abortSignal?: AbortSignal) {\n this.logInfo(`Cancel called on uploader client`);\n\n await this.#transfer.cancel(abortSignal);\n }\n\n async start(): Promise<void> {\n if (this.#transfer.status !== TransferStatus.Failed && this.#transfer.status !== TransferStatus.Aborted && this.#transfer.status !== TransferStatus.Initialized && this.#transfer.status !== TransferStatus.Paused)\n throw new TransferUploadError(`Transfer is in ${TransferStatus[this.#transfer.status]} state and cannot be run`);\n\n this.logInfo(`Starting upload. Already uploaded bytes: ${this.transfer.uploadedBytesCount}/${this.#transfer.totalSizeInBytes}B, completed files: ${this.transfer.completedFilesCount}.`);\n\n const logMessageEntries = this.#transfer.files.map(f => `'Sending ${f.fileName}' with id = ${f.externalId}. It will be put into '${f.fileDestinationPathInTransfer}' folder.`);\n this.logInfo(`Transfer file details:\\n${logMessageEntries.join(`\\n`)}`);\n\n this.#failedReason = undefined;\n this.#isShuttingDown = false;\n\n this.#pauseController = new PauseController();\n this.#abortController = new AbortController();\n\n this.#healthMonitor.start();\n\n do {\n /* eslint-disable no-await-in-loop */\n try {\n await this.#transfer.run(this.#pauseController.signal, this.#abortController.signal);\n }\n catch (error) {\n this.logError(error as TransferUploadError, `Transfer upload run method exception`);\n\n this.setFailedReasonFromError(error as TransferUploadError);\n this.#isShuttingDown = true;\n\n break;\n }\n finally {\n // @ts-ignore Typescript's brainfart\n if (this.#transfer.status !== TransferStatus.Completed && !this.#isShuttingDown) {\n this.logWarning(`Retrying transfer in ${TransferFailedSleepInMs}ms.`);\n\n await sleep(TransferFailedSleepInMs);\n }\n }\n }\n while (this.#transfer.progressInPercentage < 100 && !this.#isShuttingDown);\n\n this.#healthMonitor.stop();\n this.#logHealthyStatusThrottled.cancel();\n\n this.logInfo(`Upload finished in status ${TransferStatus[this.#transfer.status]} having ${this.#transfer.progressInPercentage}% completed`);\n }\n\n private setFailedReasonFromError(error: TransferUploadError) {\n const apiFilemailError = this.tryGetApiFilemailError(error);\n\n if (apiFilemailError) {\n this.#failedReason = apiFilemailError.reason;\n return;\n }\n\n if (error.message.startsWith(`Unhandled error occured`) && error.cause) {\n this.#failedReason = error.cause.message;\n return;\n }\n\n this.#failedReason = error.message;\n }\n\n private tryGetApiFilemailError(error: Error): ApiFilemailError | null {\n if (error instanceof ApiFilemailError)\n return error;\n\n if (error.cause)\n return this.tryGetApiFilemailError(error.cause);\n\n return null;\n }\n\n private addHealthMonitorEventListeners() {\n this.#healthMonitor.addEventListener(TransferHealthMonitorEvent.Healthy, eventArgs => {\n this.#logHealthyStatusThrottled(this.#logger, true, eventArgs, this.getLogEntryMetadata());\n\n if (!this.#isHealthy)\n logHealthyStatus(this.#logger, true, eventArgs, this.getLogEntryMetadata());\n\n this.#isHealthy = true;\n });\n\n this.#healthMonitor.addEventListener(TransferHealthMonitorEvent.Unhealthy, eventArgs => {\n if (eventArgs.reason.api.status === `Checking` || eventArgs.reason.fileServer.status === `Checking` || eventArgs.reason.internet.status === `Checking`)\n return;\n\n this.#logHealthyStatusThrottled(this.#logger, false, eventArgs, this.getLogEntryMetadata());\n\n if (this.#isHealthy)\n logHealthyStatus(this.#logger, false, eventArgs, this.getLogEntryMetadata());\n\n this.#isHealthy = false;\n });\n }\n\n private addTransferEventListeners() {\n this.#transfer.addEventListener(TransferUploadEvent.TransferUploadModeChosen, eventArgs => {\n this.#isUdp = eventArgs.isUdpMode;\n });\n\n this.#transfer.addEventListener(TransferUploadEvent.FileChunkUploadFailed, eventArgs => {\n const isTimeoutError = eventArgs.error.message.includes(`Timeout`);\n const errorMessage = `File ${eventArgs.fileStatus.externalId} chunk starting at ${eventArgs.chunkStartPosition} having size ${eventArgs.chunkSizeInBytes} upload failed: ${eventArgs.reason}`;\n\n if (this.#isUdp && isTimeoutError)\n this.logDebug(errorMessage);\n else\n this.logError(eventArgs.error, errorMessage);\n\n const isFileAccessError = eventArgs.error.cause instanceof FsError;\n const fullFilePathOrName = this.getFullFilePathOrFileName(eventArgs.fileStatus);\n\n if (isFileAccessError && !this.#isShuttingDown) {\n this.#failedReason = `Can't read ${fullFilePathOrName} anymore`;\n\n this.logWarning(`${this.#failedReason}. Failing transfer...`);\n this.failTransfer();\n }\n\n if (!this.#config.infiniteRetries && !this.#isShuttingDown) {\n this.#failedReason = `Uploading ${fullFilePathOrName} failed after ${this.#config.chunkUploadRetryLimit} retries`;\n\n this.logWarning(`${this.#failedReason}. Failing transfer...`);\n this.failTransfer();\n }\n });\n\n this.#transfer.addEventListener(TransferUploadEvent.FileUploadFailed, eventArgs => {\n const isTimeoutError = eventArgs.reason?.includes(`Timeout`);\n const errorMessage = `File ${eventArgs.fileStatus.fileName} having external id = ${eventArgs.fileStatus.externalId} - upload failed: ${eventArgs.reason}`;\n\n if (this.#isUdp && isTimeoutError)\n this.logWarning(errorMessage);\n else\n this.logError(new Error(errorMessage));\n });\n\n this.#transfer.addEventListener(TransferUploadEvent.TransferRun, () => this.logInfo(`Transfer run.`));\n this.#transfer.addEventListener(TransferUploadEvent.TransferAbortRequested, () => this.logInfo(`Transfer abort requested`));\n this.#transfer.addEventListener(TransferUploadEvent.TransferAborted, async () => this.logInfo(`Transfer aborted.`));\n this.#transfer.addEventListener(TransferUploadEvent.TransferCancelRequested, () => this.logInfo(`Transfer cancel requested.`));\n this.#transfer.addEventListener(TransferUploadEvent.TransferCanceled, () => this.logInfo(`Transfer canceled.`));\n this.#transfer.addEventListener(TransferUploadEvent.TransferFailed, () => this.logError(new Error(`Transfer failed.`)));\n this.#transfer.addEventListener(TransferUploadEvent.TransferUploadModeChosen, eventArgs => this.logInfo(`Transfer upload mode chosen. Is UDP: ${eventArgs.isUdpMode}; Latency: ${eventArgs.latency ?? `<unkown>`}; Error: ${eventArgs.error ?? `<none>`}`));\n\n this.#transfer.addEventListener(TransferUploadEvent.TransferCompleted, eventArgs => this.logInfo(`Transfer completed successfully. ID: ${eventArgs.transferId}, URL: ${eventArgs.transferDownloadUrl}`));\n this.#transfer.addEventListener(TransferUploadEvent.FileChunkUploadProgressed, eventArgs => this.logTrace(`File ${eventArgs.fileStatus.fileName} having external id = ${eventArgs.fileStatus.externalId}, chunk starting at ${eventArgs.chunkStartPosition} having size ${eventArgs.chunkSizeInBytes} progressed: ${eventArgs.transferredBytesSinceLastEvent} bytes sinc last event. Total progress: ${this.#transfer?.progressInPercentage}%.`));\n\n this.#transfer.addEventListener(TransferUploadEvent.FileUploadStarted, eventArgs => this.logDebug(`File ${eventArgs.fileStatus.fileName} having external id = ${eventArgs.fileStatus.externalId} - upload started.`));\n this.#transfer.addEventListener(TransferUploadEvent.FileUploadCompleted, eventArgs => this.logDebug(`File ${eventArgs.fileStatus.fileName} having external id = ${eventArgs.fileStatus.externalId} - upload completed.`));\n this.#transfer.addEventListener(TransferUploadEvent.FileChunkUploadStarted, eventArgs => this.logTrace(`File ${eventArgs.fileStatus.fileName} having external id = ${eventArgs.fileStatus.externalId}, chunk starting at ${eventArgs.chunkStartPosition} having size ${eventArgs.chunkSizeInBytes} - upload started`));\n this.#transfer.addEventListener(TransferUploadEvent.FileChunkUploadCompleted, eventArgs => this.logTrace(`File ${eventArgs.fileStatus.fileName} having external id = ${eventArgs.fileStatus.externalId}, chunk starting at ${eventArgs.chunkStartPosition} having size ${eventArgs.chunkSizeInBytes} - upload completed`));\n this.#transfer.addEventListener(TransferUploadEvent.FileChunkUploadCompletedPartially, eventArgs => this.logWarning(`File ${eventArgs.fileStatus.fileName} having external id = ${eventArgs.fileStatus.externalId}, chunk starting at ${eventArgs.chunkStartPosition} having size ${eventArgs.chunkSizeInBytes} - uploaded partially - only ${eventArgs.uploadedBytesCount} bytes uploaded`));\n }\n\n private failTransfer() {\n if (!this.#abortController)\n throw new TransferUploadError(`Can't fail not started transfer`);\n\n this.#isShuttingDown = true;\n\n this.#abortController.abort(createTransferFailureAbortReason());\n }\n\n private logTrace(message: string) {\n const logEntryMetadata = this.getLogEntryMetadata();\n this.#logger.logTrace(message, logEntryMetadata);\n }\n\n private logDebug(message: string) {\n const logEntryMetadata = this.getLogEntryMetadata();\n this.#logger.logDebug(message, logEntryMetadata);\n }\n\n private logInfo(message: string) {\n const logEntryMetadata = this.getLogEntryMetadata();\n this.#logger.logInfo(message, logEntryMetadata);\n }\n\n private logWarning(message: string) {\n const logEntryMetadata = this.getLogEntryMetadata();\n this.#logger.logWarning(message, logEntryMetadata);\n }\n\n private logError(error: Error, message?: string) {\n const logEntryMetadata = this.getLogEntryMetadata();\n this.#logger.logError(error, message, logEntryMetadata);\n }\n\n private getLogEntryMetadata() {\n return {\n [logEventPropertyName.TrackingIdPropertyName]: this.#trackingId,\n [logEventPropertyName.TransferIdPropertyName]: this.#transfer.transferId,\n };\n }\n\n private getFullFilePathOrFileName(fileStatus: ReadonlyTransferUploadStateFile): string {\n const fileDetails = this.#fileDetails.find(f => f.externalId === fileStatus.externalId);\n\n if (!fileDetails)\n return fileStatus.fileName;\n\n if (this.isNodeFileDetails(fileDetails))\n return fileDetails.fileFullPath;\n\n return fileDetails.file.name;\n }\n\n private isNodeFileDetails(fileDetails: NodeFileDetails | WebFileDetails): fileDetails is NodeFileDetails {\n return typeof (fileDetails as NodeFileDetails).fileFullPath === `string`;\n }\n}"]}
|
|
@@ -148,7 +148,7 @@ export default class NodeFileServerUdpClient {
|
|
|
148
148
|
}
|
|
149
149
|
async sendChunkCall(request, chunkStreamProvider) {
|
|
150
150
|
const packetGuid = newGuid();
|
|
151
|
-
const chunkReadStream = await chunkStreamProvider.getChunkReadStream();
|
|
151
|
+
const chunkReadStream = await chunkStreamProvider.getChunkReadStream(undefined, this.#abortSignal);
|
|
152
152
|
const chunkBytes = await this.readStreamToEnd(chunkReadStream);
|
|
153
153
|
const udpRequest = this.createSendChunkRequest(packetGuid, request, chunkBytes);
|
|
154
154
|
return await this.makeCall(udpRequest, packetGuid, (sentTime, responseTime) => this.createLatencyResponse(sentTime, responseTime));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodeFileServerUdpClient.js","sourceRoot":"","sources":["../../../../../src/uploader/api/node/nodeFileServerUdpClient.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAKpE,OAAO,SAAS,MAAM,wBAAwB,CAAC;AAC/C,OAAO,KAAK,MAAM,iBAAiB,CAAC;AAEpC,OAAO,EAAE,EAAE,IAAI,OAAO,EAAE,KAAK,IAAI,WAAW,EAAE,SAAS,IAAI,WAAW,EAAE,MAAM,MAAM,CAAC;AAErF,OAAO,OAAO,MAAM,sCAAsC,CAAC;AAS3D,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACrC,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1C,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1C,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAE1C,MAAM,iBAAiB,GAAG;;;;;;;;yBAQD,CAAC;AAE1B,MAAM,CAAC,OAAO,OAAO,uBAAuB;IACxC,QAAQ,CAAS;IACjB,KAAK,CAAS;IAEd,eAAe,CAAS;IACxB,QAAQ,CAAS;IACjB,WAAW,CAAS;IAEpB,YAAY,CAAe;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,KAAK,EAAE;gBACrC,OAAO,KAAK,CAAC;YAEjB,MAAM,YAAY,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;YAEzC,OAAO,IAAI,KAAK,YAAY,CAAC;QACjC,CAAC;QACD,MAAM,CAAC;YACH,OAAO,KAAK,CAAC;QACjB,CAAC;IACL,CAAC;IAEO,KAAK,CAAC,GAAW;QACrB,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACnD,OAAO,MAAM,KAAK,IAAI,CAAC;IAC3B,CAAC;CACJ","sourcesContent":["/* eslint-disable no-await-in-loop */\nimport path from 'path';\nimport { clearTimeout } from 'timers';\nimport { publicEncrypt, randomBytes, createCipheriv } from 'crypto';\n\nimport type { RemoteInfo } from 'dgram';\nimport type { ReadableStream as NodeReadableStream } from \"stream/web\";\n\nimport UdpClient from 'promisified-udp-client';\nimport sleep from 'abortable-sleep';\n\nimport { v4 as newGuid, parse as guidToBytes, stringify as bytesToGuid } from 'uuid';\n\nimport FsError from '../../../utils/fileSystem/fsError.js';\n\nimport type LatencyResponse from \"../dtos/pingResponse.js\";\nimport type HandshakeRequest from '../dtos/handshakeRequest.js';\nimport type SendChunkRequest from '../dtos/sendChunkRequest.js';\nimport type FileServerUdpClient from '../fileServerUdpClient.js';\nimport type HandshakeResponse from '../dtos/handshakeResponse.js';\nimport type ChunkStreamProvider from '../../../utils/fileSystem/chunkStreamProvider.js';\n\nconst pingPrefix = Buffer.from(`P2`);\nconst handshakePrefix = Buffer.from(`H2`);\nconst chunkDataPrefix = Buffer.from(`D2`);\nconst encryptedPrefix = Buffer.from(`E2`);\n\nconst filemailPublicKey = `-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvmW7lnKl2UN7gLrLjsIP\nWMMA2Nc8zROtwcGuumiN5bpw8ju/58MSE2DiYnGJKOVXxI2A52FgVK4I9hXKstwZ\n5Sotcf3BXw1wMusnHwVGYRsQob76EJKiqQODc/pLyLtRDiFRY5tgafkW0dU1X8AU\nkjtAawPp7ed/Z6DJaV2jWOQyJ9sCBXGhnNSExPOeSFvRKFM5vfurPXPXG4ii6tGU\nXaqjVeX5+b9dJFTJ2HzUSUxAkYUCS1y4E9jehlimM7gGTR0m7ISQa/bg1eE1X8iA\nD2DVevYVGqs9A6p+e/WJ2dMXU4XxBmfxWZe+szqgfU3wqvOmCS5JrGUKi6SAx8a5\nWQIDAQAB\n-----END PUBLIC KEY-----`;\n\nexport default class NodeFileServerUdpClient implements FileServerUdpClient {\n #address: string;\n #port: number;\n\n #requestTimeout: number;\n #retries: number;\n #retryDelay: number;\n\n #abortSignal?: AbortSignal;\n\n #udpClient: UdpClient;\n\n constructor(address: string, port: number, requestTimeout: number, retries: number, abortSignal?: AbortSignal, retryDelay: number = 1000) {\n this.#address = address;\n this.#port = port;\n this.#requestTimeout = requestTimeout;\n this.#retries = retries;\n this.#retryDelay = retryDelay;\n this.#abortSignal = abortSignal;\n\n this.#udpClient = new UdpClient(abortSignal);\n }\n\n addMessageListener(listener: (msg: Buffer, rinfo: RemoteInfo) => void) {\n this.#udpClient.addMessageListener(listener);\n }\n\n removeMessageListener(listener: (msg: Buffer, rinfo: RemoteInfo) => void) {\n this.#udpClient.removeMessageListener(listener);\n }\n\n addErrorListener(listener: (msg: Buffer, rinfo: RemoteInfo) => void) {\n this.#udpClient.addErrorListener(listener);\n }\n\n removeErrorListener(listener: (msg: Buffer, rinfo: RemoteInfo) => void) {\n this.#udpClient.removeErrorListener(listener);\n }\n\n async connect(): Promise<void> {\n await this.#udpClient.connect(this.#port, this.#address);\n }\n\n async close(): Promise<void> {\n await this.#udpClient.close();\n }\n\n private async retryMechanism<T>(apiCall: () => Promise<T>): Promise<T> {\n let lastError: Error | undefined;\n\n for (let attempt = 0; attempt <= this.#retries; attempt++) {\n try {\n const result = await apiCall();\n return result;\n }\n catch (error) {\n if (attempt < this.#retries) {\n lastError = error as Error;\n await sleep(this.#retryDelay * attempt, this.#abortSignal);\n }\n\n if (this.#abortSignal?.aborted)\n throw new Error(`Aborted`);\n }\n }\n\n throw lastError;\n }\n\n async ping(): Promise<LatencyResponse> {\n return await this.retryMechanism(async () => await this.pingCall());\n }\n\n async handshake(request: HandshakeRequest): Promise<HandshakeResponse> {\n return await this.retryMechanism(async () => await this.handshakeCall(request));\n }\n\n async sendChunk(request: SendChunkRequest, chunkStreamProvider: ChunkStreamProvider): Promise<LatencyResponse> {\n try {\n return await this.retryMechanism(async () => await this.sendChunkCall(request, chunkStreamProvider));\n }\n catch (error) {\n if (this.isWrappedCreatingFileReadStreamException(error as Error))\n throw new FsError((error as Error).message);\n\n throw error;\n }\n finally {\n if (!chunkStreamProvider.isReleased)\n await chunkStreamProvider.release();\n }\n }\n\n private isWrappedCreatingFileReadStreamException(error: Error): boolean {\n return error.message === `CreatingFileReadStreamException`;\n }\n\n private async pingCall(): Promise<LatencyResponse> {\n const packetGuid = newGuid();\n\n const udpRequest = this.createPingRequest(packetGuid);\n\n return await this.makeCall(udpRequest, packetGuid, (sentTime, responseTime) => this.createLatencyResponse(sentTime, responseTime));\n }\n\n private createPingRequest(packetGuid: string): Buffer {\n const guidBytes = guidToBytes(packetGuid);\n return Buffer.concat([pingPrefix, guidBytes]);\n }\n\n private createLatencyResponse(sentTime: number, responseTime: number): LatencyResponse {\n return {\n latencyInMs: responseTime - sentTime,\n };\n }\n\n private async handshakeCall(request: HandshakeRequest): Promise<HandshakeResponse> {\n const packetGuid = newGuid();\n const sessionGuid = newGuid();\n const aesKey = this.generateAes256Key();\n\n const udpRequest = this.createHandshakeRequest(packetGuid, sessionGuid, aesKey, request);\n\n return await this.makeCall(udpRequest, packetGuid, () => this.createHandshakeResponse(sessionGuid, aesKey));\n }\n\n private generateAes256Key(): Buffer {\n return randomBytes(32);\n }\n\n private createHandshakeRequest(packetGuid: string, sessionGuid: string, aesKey: Buffer, request: HandshakeRequest) {\n const packetGuidBytes = guidToBytes(packetGuid);\n const sessionGuidBytes = guidToBytes(sessionGuid);\n const transferKeyBytes = guidToBytes(this.transferKeyToGuid(request.transferKey));\n const transferIdBytes = Buffer.from(request.transferId);\n\n const encryptableRequestPart = Buffer.concat([\n packetGuidBytes,\n sessionGuidBytes,\n transferKeyBytes,\n transferIdBytes,\n aesKey,\n ]);\n\n const encryptedRequestPart = this.publicRsaEncrypt(encryptableRequestPart);\n\n return Buffer.concat([handshakePrefix, encryptedRequestPart]);\n }\n\n private transferKeyToGuid(transferKey: string): string {\n return `${transferKey.slice(0, 8)}-${transferKey.slice(8, 12)}-${transferKey.slice(12, 16)}-${transferKey.slice(16, 20)}-${transferKey.slice(20)}`;\n }\n\n private publicRsaEncrypt(data: Buffer) {\n return publicEncrypt(filemailPublicKey, data);\n }\n\n private createHandshakeResponse(sessionGuid: string, aesKey: Buffer): HandshakeResponse {\n return {\n aesKey,\n sessionGuid,\n };\n }\n\n private async sendChunkCall(request: SendChunkRequest, chunkStreamProvider: ChunkStreamProvider): Promise<LatencyResponse> {\n const packetGuid = newGuid();\n\n const chunkReadStream = await chunkStreamProvider.getChunkReadStream();\n const chunkBytes = await this.readStreamToEnd(chunkReadStream);\n\n const udpRequest = this.createSendChunkRequest(packetGuid, request, chunkBytes);\n\n return await this.makeCall(udpRequest, packetGuid, (sentTime, responseTime) => this.createLatencyResponse(sentTime, responseTime));\n }\n\n private async readStreamToEnd(stream: ReadableStream | NodeReadableStream) {\n const reader = stream.getReader();\n\n const chunks: Uint8Array[] = [];\n\n while (true) {\n const { done, value } = await reader.read();\n\n if (done)\n break;\n\n if (value)\n chunks.push(value);\n }\n\n const totalLength = chunks.reduce((sum, c) => sum + c.length, 0);\n const merged = new Uint8Array(totalLength);\n\n let offset = 0;\n\n for (const c of chunks) {\n merged.set(c, offset);\n offset += c.length;\n }\n\n return Buffer.from(merged);\n }\n\n private createSendChunkRequest(packetGuid: string, request: SendChunkRequest, chunkBytes: Buffer) {\n const fullDestinationFileNameString = path.posix.join(request.fileDestinationPathInTransfer, request.fileName);\n const fullDestinationFileName = Buffer.from(fullDestinationFileNameString);\n\n const fullDestinationFileNameLength = Buffer.alloc(2);\n fullDestinationFileNameLength.writeUint16BE(fullDestinationFileName.length);\n\n const fileSize = Buffer.alloc(8);\n fileSize.writeBigInt64BE(BigInt(request.fileSizeInBytes));\n\n const chunkStartPosition = Buffer.alloc(8);\n chunkStartPosition.writeBigInt64BE(BigInt(request.chunkStartPosition));\n\n const encryptableRequestPart = Buffer.concat([\n chunkDataPrefix,\n fullDestinationFileNameLength,\n fileSize,\n chunkStartPosition,\n fullDestinationFileName,\n chunkBytes,\n ]);\n\n const aesKey = Buffer.from(request.aesKey).subarray(0, 16); // .subarray directly on request.aesKey throws in Electron\n\n const { encryptedData, iv, authTag } = this.aesEncrypt(encryptableRequestPart, aesKey);\n\n const packetGuidBytes = guidToBytes(packetGuid);\n const sessionGuidBytes = guidToBytes(request.sessionGuid);\n\n return Buffer.concat([\n encryptedPrefix,\n packetGuidBytes,\n sessionGuidBytes,\n iv,\n authTag,\n encryptedData,\n ]);\n }\n\n private aesEncrypt(data: Buffer, aesKey: Buffer): { encryptedData: Buffer, iv: Buffer, authTag: Buffer } {\n const iv = randomBytes(12);\n\n const cipher = createCipheriv(`aes-128-gcm`, aesKey, iv);\n\n let encryptedData = cipher.update(data);\n encryptedData = Buffer.concat([encryptedData, cipher.final()]);\n\n const authTag = cipher.getAuthTag();\n\n return { encryptedData, iv, authTag };\n }\n\n private async makeCall<T>(request: string | readonly any[] | Uint8Array, packetGuid: string, createResponse?: (sentTime: number, responseTime: number, message: Buffer) => T): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n const sentTime = new Date().getTime();\n\n const timeout = setTimeout(() => {\n cleanup();\n reject(new Error(`Timeout`));\n }, this.#requestTimeout);\n\n const responseListener = (msg: Buffer) => {\n const responseTime = new Date().getTime();\n\n if (!this.isAckResponse(msg, packetGuid))\n return;\n\n cleanup();\n\n if (!createResponse)\n resolve(undefined as any);\n else {\n const response = createResponse(sentTime, responseTime, msg);\n resolve(response);\n }\n };\n\n this.addMessageListener(responseListener);\n\n const sendPromise = this.#udpClient.send(request);\n\n const errorAndAbortHandler = (error: Error) => {\n cleanup();\n reject(error);\n };\n\n const abortSignalListener = () => errorAndAbortHandler(new Error(`Aborted`));\n\n const cleanup = () => {\n this.removeMessageListener(responseListener);\n clearTimeout(timeout);\n this.#abortSignal?.removeEventListener(`abort`, abortSignalListener);\n };\n\n sendPromise.catch(error => errorAndAbortHandler(error));\n this.#abortSignal?.addEventListener(`abort`, abortSignalListener);\n });\n }\n\n private isAckResponse(msg: Buffer, guid: string) {\n try {\n if (!this.isAck(msg) || msg.length !== 18)\n return false;\n\n const responseGuid = bytesToGuid(msg, 2);\n\n return guid === responseGuid;\n }\n catch {\n return false;\n }\n }\n\n private isAck(msg: Buffer) {\n const prefix = msg.subarray(0, 2).toString(`utf8`);\n return prefix === `A1`;\n }\n}"]}
|
|
1
|
+
{"version":3,"file":"nodeFileServerUdpClient.js","sourceRoot":"","sources":["../../../../../src/uploader/api/node/nodeFileServerUdpClient.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAKpE,OAAO,SAAS,MAAM,wBAAwB,CAAC;AAC/C,OAAO,KAAK,MAAM,iBAAiB,CAAC;AAEpC,OAAO,EAAE,EAAE,IAAI,OAAO,EAAE,KAAK,IAAI,WAAW,EAAE,SAAS,IAAI,WAAW,EAAE,MAAM,MAAM,CAAC;AAErF,OAAO,OAAO,MAAM,sCAAsC,CAAC;AAS3D,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACrC,MAAM,eAAe,GAAG,MA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AAY,EAAE,mBAAmB,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;YACzE,CAAC,CAAC;YAEF,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC,CAAC;YACxD,IAAI,CAAC,YAAY,EAAE,gBAAgB,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;QACtE,CAAC,CAAC,CAAC;IACP,CAAC;IAEO,aAAa,CAAC,GAAW,EAAE,IAAY;QAC3C,IAAI,CAAC;YACD,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,MAAM,KAAK,EAAE;gBACrC,OAAO,KAAK,CAAC;YAEjB,MAAM,YAAY,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;YAEzC,OAAO,IAAI,KAAK,YAAY,CAAC;QACjC,CAAC;QACD,MAAM,CAAC;YACH,OAAO,KAAK,CAAC;QACjB,CAAC;IACL,CAAC;IAEO,KAAK,CAAC,GAAW;QACrB,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACnD,OAAO,MAAM,KAAK,IAAI,CAAC;IAC3B,CAAC;CACJ","sourcesContent":["/* eslint-disable no-await-in-loop */\nimport path from 'path';\nimport { clearTimeout } from 'timers';\nimport { publicEncrypt, randomBytes, createCipheriv } from 'crypto';\n\nimport type { RemoteInfo } from 'dgram';\nimport type { ReadableStream as NodeReadableStream } from \"stream/web\";\n\nimport UdpClient from 'promisified-udp-client';\nimport sleep from 'abortable-sleep';\n\nimport { v4 as newGuid, parse as guidToBytes, stringify as bytesToGuid } from 'uuid';\n\nimport FsError from '../../../utils/fileSystem/fsError.js';\n\nimport type LatencyResponse from \"../dtos/pingResponse.js\";\nimport type HandshakeRequest from '../dtos/handshakeRequest.js';\nimport type SendChunkRequest from '../dtos/sendChunkRequest.js';\nimport type FileServerUdpClient from '../fileServerUdpClient.js';\nimport type HandshakeResponse from '../dtos/handshakeResponse.js';\nimport type ChunkStreamProvider from '../../../utils/fileSystem/chunkStreamProvider.js';\n\nconst pingPrefix = Buffer.from(`P2`);\nconst handshakePrefix = Buffer.from(`H2`);\nconst chunkDataPrefix = Buffer.from(`D2`);\nconst encryptedPrefix = Buffer.from(`E2`);\n\nconst filemailPublicKey = `-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvmW7lnKl2UN7gLrLjsIP\nWMMA2Nc8zROtwcGuumiN5bpw8ju/58MSE2DiYnGJKOVXxI2A52FgVK4I9hXKstwZ\n5Sotcf3BXw1wMusnHwVGYRsQob76EJKiqQODc/pLyLtRDiFRY5tgafkW0dU1X8AU\nkjtAawPp7ed/Z6DJaV2jWOQyJ9sCBXGhnNSExPOeSFvRKFM5vfurPXPXG4ii6tGU\nXaqjVeX5+b9dJFTJ2HzUSUxAkYUCS1y4E9jehlimM7gGTR0m7ISQa/bg1eE1X8iA\nD2DVevYVGqs9A6p+e/WJ2dMXU4XxBmfxWZe+szqgfU3wqvOmCS5JrGUKi6SAx8a5\nWQIDAQAB\n-----END PUBLIC KEY-----`;\n\nexport default class NodeFileServerUdpClient implements FileServerUdpClient {\n #address: string;\n #port: number;\n\n #requestTimeout: number;\n #retries: number;\n #retryDelay: number;\n\n #abortSignal?: AbortSignal;\n\n #udpClient: UdpClient;\n\n constructor(address: string, port: number, requestTimeout: number, retries: number, abortSignal?: AbortSignal, retryDelay: number = 1000) {\n this.#address = address;\n this.#port = port;\n this.#requestTimeout = requestTimeout;\n this.#retries = retries;\n this.#retryDelay = retryDelay;\n this.#abortSignal = abortSignal;\n\n this.#udpClient = new UdpClient(abortSignal);\n }\n\n addMessageListener(listener: (msg: Buffer, rinfo: RemoteInfo) => void) {\n this.#udpClient.addMessageListener(listener);\n }\n\n removeMessageListener(listener: (msg: Buffer, rinfo: RemoteInfo) => void) {\n this.#udpClient.removeMessageListener(listener);\n }\n\n addErrorListener(listener: (msg: Buffer, rinfo: RemoteInfo) => void) {\n this.#udpClient.addErrorListener(listener);\n }\n\n removeErrorListener(listener: (msg: Buffer, rinfo: RemoteInfo) => void) {\n this.#udpClient.removeErrorListener(listener);\n }\n\n async connect(): Promise<void> {\n await this.#udpClient.connect(this.#port, this.#address);\n }\n\n async close(): Promise<void> {\n await this.#udpClient.close();\n }\n\n private async retryMechanism<T>(apiCall: () => Promise<T>): Promise<T> {\n let lastError: Error | undefined;\n\n for (let attempt = 0; attempt <= this.#retries; attempt++) {\n try {\n const result = await apiCall();\n return result;\n }\n catch (error) {\n if (attempt < this.#retries) {\n lastError = error as Error;\n await sleep(this.#retryDelay * attempt, this.#abortSignal);\n }\n\n if (this.#abortSignal?.aborted)\n throw new Error(`Aborted`);\n }\n }\n\n throw lastError;\n }\n\n async ping(): Promise<LatencyResponse> {\n return await this.retryMechanism(async () => await this.pingCall());\n }\n\n async handshake(request: HandshakeRequest): Promise<HandshakeResponse> {\n return await this.retryMechanism(async () => await this.handshakeCall(request));\n }\n\n async sendChunk(request: SendChunkRequest, chunkStreamProvider: ChunkStreamProvider): Promise<LatencyResponse> {\n try {\n return await this.retryMechanism(async () => await this.sendChunkCall(request, chunkStreamProvider));\n }\n catch (error) {\n if (this.isWrappedCreatingFileReadStreamException(error as Error))\n throw new FsError((error as Error).message);\n\n throw error;\n }\n finally {\n if (!chunkStreamProvider.isReleased)\n await chunkStreamProvider.release();\n }\n }\n\n private isWrappedCreatingFileReadStreamException(error: Error): boolean {\n return error.message === `CreatingFileReadStreamException`;\n }\n\n private async pingCall(): Promise<LatencyResponse> {\n const packetGuid = newGuid();\n\n const udpRequest = this.createPingRequest(packetGuid);\n\n return await this.makeCall(udpRequest, packetGuid, (sentTime, responseTime) => this.createLatencyResponse(sentTime, responseTime));\n }\n\n private createPingRequest(packetGuid: string): Buffer {\n const guidBytes = guidToBytes(packetGuid);\n return Buffer.concat([pingPrefix, guidBytes]);\n }\n\n private createLatencyResponse(sentTime: number, responseTime: number): LatencyResponse {\n return {\n latencyInMs: responseTime - sentTime,\n };\n }\n\n private async handshakeCall(request: HandshakeRequest): Promise<HandshakeResponse> {\n const packetGuid = newGuid();\n const sessionGuid = newGuid();\n const aesKey = this.generateAes256Key();\n\n const udpRequest = this.createHandshakeRequest(packetGuid, sessionGuid, aesKey, request);\n\n return await this.makeCall(udpRequest, packetGuid, () => this.createHandshakeResponse(sessionGuid, aesKey));\n }\n\n private generateAes256Key(): Buffer {\n return randomBytes(32);\n }\n\n private createHandshakeRequest(packetGuid: string, sessionGuid: string, aesKey: Buffer, request: HandshakeRequest) {\n const packetGuidBytes = guidToBytes(packetGuid);\n const sessionGuidBytes = guidToBytes(sessionGuid);\n const transferKeyBytes = guidToBytes(this.transferKeyToGuid(request.transferKey));\n const transferIdBytes = Buffer.from(request.transferId);\n\n const encryptableRequestPart = Buffer.concat([\n packetGuidBytes,\n sessionGuidBytes,\n transferKeyBytes,\n transferIdBytes,\n aesKey,\n ]);\n\n const encryptedRequestPart = this.publicRsaEncrypt(encryptableRequestPart);\n\n return Buffer.concat([handshakePrefix, encryptedRequestPart]);\n }\n\n private transferKeyToGuid(transferKey: string): string {\n return `${transferKey.slice(0, 8)}-${transferKey.slice(8, 12)}-${transferKey.slice(12, 16)}-${transferKey.slice(16, 20)}-${transferKey.slice(20)}`;\n }\n\n private publicRsaEncrypt(data: Buffer) {\n return publicEncrypt(filemailPublicKey, data);\n }\n\n private createHandshakeResponse(sessionGuid: string, aesKey: Buffer): HandshakeResponse {\n return {\n aesKey,\n sessionGuid,\n };\n }\n\n private async sendChunkCall(request: SendChunkRequest, chunkStreamProvider: ChunkStreamProvider): Promise<LatencyResponse> {\n const packetGuid = newGuid();\n\n const chunkReadStream = await chunkStreamProvider.getChunkReadStream(undefined, this.#abortSignal);\n const chunkBytes = await this.readStreamToEnd(chunkReadStream);\n\n const udpRequest = this.createSendChunkRequest(packetGuid, request, chunkBytes);\n\n return await this.makeCall(udpRequest, packetGuid, (sentTime, responseTime) => this.createLatencyResponse(sentTime, responseTime));\n }\n\n private async readStreamToEnd(stream: ReadableStream | NodeReadableStream) {\n const reader = stream.getReader();\n\n const chunks: Uint8Array[] = [];\n\n while (true) {\n const { done, value } = await reader.read();\n\n if (done)\n break;\n\n if (value)\n chunks.push(value);\n }\n\n const totalLength = chunks.reduce((sum, c) => sum + c.length, 0);\n const merged = new Uint8Array(totalLength);\n\n let offset = 0;\n\n for (const c of chunks) {\n merged.set(c, offset);\n offset += c.length;\n }\n\n return Buffer.from(merged);\n }\n\n private createSendChunkRequest(packetGuid: string, request: SendChunkRequest, chunkBytes: Buffer) {\n const fullDestinationFileNameString = path.posix.join(request.fileDestinationPathInTransfer, request.fileName);\n const fullDestinationFileName = Buffer.from(fullDestinationFileNameString);\n\n const fullDestinationFileNameLength = Buffer.alloc(2);\n fullDestinationFileNameLength.writeUint16BE(fullDestinationFileName.length);\n\n const fileSize = Buffer.alloc(8);\n fileSize.writeBigInt64BE(BigInt(request.fileSizeInBytes));\n\n const chunkStartPosition = Buffer.alloc(8);\n chunkStartPosition.writeBigInt64BE(BigInt(request.chunkStartPosition));\n\n const encryptableRequestPart = Buffer.concat([\n chunkDataPrefix,\n fullDestinationFileNameLength,\n fileSize,\n chunkStartPosition,\n fullDestinationFileName,\n chunkBytes,\n ]);\n\n const aesKey = Buffer.from(request.aesKey).subarray(0, 16); // .subarray directly on request.aesKey throws in Electron\n\n const { encryptedData, iv, authTag } = this.aesEncrypt(encryptableRequestPart, aesKey);\n\n const packetGuidBytes = guidToBytes(packetGuid);\n const sessionGuidBytes = guidToBytes(request.sessionGuid);\n\n return Buffer.concat([\n encryptedPrefix,\n packetGuidBytes,\n sessionGuidBytes,\n iv,\n authTag,\n encryptedData,\n ]);\n }\n\n private aesEncrypt(data: Buffer, aesKey: Buffer): { encryptedData: Buffer, iv: Buffer, authTag: Buffer } {\n const iv = randomBytes(12);\n\n const cipher = createCipheriv(`aes-128-gcm`, aesKey, iv);\n\n let encryptedData = cipher.update(data);\n encryptedData = Buffer.concat([encryptedData, cipher.final()]);\n\n const authTag = cipher.getAuthTag();\n\n return { encryptedData, iv, authTag };\n }\n\n private async makeCall<T>(request: string | readonly any[] | Uint8Array, packetGuid: string, createResponse?: (sentTime: number, responseTime: number, message: Buffer) => T): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n const sentTime = new Date().getTime();\n\n const timeout = setTimeout(() => {\n cleanup();\n reject(new Error(`Timeout`));\n }, this.#requestTimeout);\n\n const responseListener = (msg: Buffer) => {\n const responseTime = new Date().getTime();\n\n if (!this.isAckResponse(msg, packetGuid))\n return;\n\n cleanup();\n\n if (!createResponse)\n resolve(undefined as any);\n else {\n const response = createResponse(sentTime, responseTime, msg);\n resolve(response);\n }\n };\n\n this.addMessageListener(responseListener);\n\n const sendPromise = this.#udpClient.send(request);\n\n const errorAndAbortHandler = (error: Error) => {\n cleanup();\n reject(error);\n };\n\n const abortSignalListener = () => errorAndAbortHandler(new Error(`Aborted`));\n\n const cleanup = () => {\n this.removeMessageListener(responseListener);\n clearTimeout(timeout);\n this.#abortSignal?.removeEventListener(`abort`, abortSignalListener);\n };\n\n sendPromise.catch(error => errorAndAbortHandler(error));\n this.#abortSignal?.addEventListener(`abort`, abortSignalListener);\n });\n }\n\n private isAckResponse(msg: Buffer, guid: string) {\n try {\n if (!this.isAck(msg) || msg.length !== 18)\n return false;\n\n const responseGuid = bytesToGuid(msg, 2);\n\n return guid === responseGuid;\n }\n catch {\n return false;\n }\n }\n\n private isAck(msg: Buffer) {\n const prefix = msg.subarray(0, 2).toString(`utf8`);\n return prefix === `A1`;\n }\n}"]}
|
|
@@ -56,14 +56,14 @@ export default class NodeFileServerUploadClient extends NodeFileServerClientBase
|
|
|
56
56
|
/* eslint-disable no-param-reassign */
|
|
57
57
|
if (!isRetry)
|
|
58
58
|
return;
|
|
59
|
-
const readableStream = await chunkStreamProvider.getChunkReadStream(pauseSignal);
|
|
59
|
+
const readableStream = await chunkStreamProvider.getChunkReadStream(pauseSignal, abortSignal);
|
|
60
60
|
options.body = Readable.fromWeb(readableStream);
|
|
61
61
|
},
|
|
62
62
|
],
|
|
63
63
|
},
|
|
64
64
|
});
|
|
65
|
-
const md5checksum = await chunkStreamProvider.getMd5Checksum(`base64`, pauseSignal);
|
|
66
|
-
const readableStream = await chunkStreamProvider.getChunkReadStream(pauseSignal);
|
|
65
|
+
const md5checksum = await chunkStreamProvider.getMd5Checksum(`base64`, pauseSignal, abortSignal);
|
|
66
|
+
const readableStream = await chunkStreamProvider.getChunkReadStream(pauseSignal, abortSignal);
|
|
67
67
|
const body = Readable.fromWeb(readableStream);
|
|
68
68
|
ongoingRequestPromise = gotChunkInstance.post(this.#uploadUrl, {
|
|
69
69
|
body,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodeFileServerUploadClient.js","sourceRoot":"","sources":["../../../../../src/uploader/api/node/nodeFileServerUploadClient.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,OAAO,GAAyC,MAAM,KAAK,CAAC;AAI5D,OAAO,wBAAwB,MAAM,qDAAqD,CAAC;AAE3F,OAAO,OAAO,MAAM,sCAAsC,CAAC;AAC3D,OAAO,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAC;AAOtF,6EAA6E;AAC7E,MAAM,CAAC,OAAO,OAAO,0BAA2B,SAAQ,wBAAwB;IACnE,UAAU,CAAS;IACnB,YAAY,CAAM;IAE3B,YAAY,SAAiB,EAAE,UAAkB,EAAE,WAAmB,EAAE,QAAgB,EAAE,mBAA2B,EAAE,oBAA4B,EAAE,MAAc,EAAE,aAAqB,EAAE,qBAA6B,EAAE,UAAkB;QACzO,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAE5B,MAAM,uBAAuB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;oBACL,mBAAmB,EAAE,SAAS;iBACjC;gBACD,KAAK,EAAE;oBACH,WAAW,EAAE;wBACT,YAAY,CAAC,EAAE;4BACX,OAAO,GAAG,IAAI,CAAC;4BACf,6CAA6C;4BAC7C,YAAY,CAAC,OAAO,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC,4EAA4E;wBAChH,CAAC;qBACJ;oBACD,aAAa,EAAE;wBACX,KAAK,EAAC,OAAO,EAAC,EAAE;4BACZ,sCAAsC;4BACtC,IAAI,CAAC,OAAO;gCACR,OAAO;4BAEX,MAAM,cAAc,GAAG,MAAM,mBAAmB,CAAC,kBAAkB,CAAC,WAAW,CAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"nodeFileServerUploadClient.js","sourceRoot":"","sources":["../../../../../src/uploader/api/node/nodeFileServerUploadClient.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,OAAO,GAAyC,MAAM,KAAK,CAAC;AAI5D,OAAO,wBAAwB,MAAM,qDAAqD,CAAC;AAE3F,OAAO,OAAO,MAAM,sCAAsC,CAAC;AAC3D,OAAO,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAC;AAOtF,6EAA6E;AAC7E,MAAM,CAAC,OAAO,OAAO,0BAA2B,SAAQ,wBAAwB;IACnE,UAAU,CAAS;IACnB,YAAY,CAAM;IAE3B,YAAY,SAAiB,EAAE,UAAkB,EAAE,WAAmB,EAAE,QAAgB,EAAE,mBAA2B,EAAE,oBAA4B,EAAE,MAAc,EAAE,aAAqB,EAAE,qBAA6B,EAAE,UAAkB;QACzO,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAE5B,MAAM,uBAAuB,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,mBAAmB,EAAE,QAAQ,CAAC,CAAC;QAE/E,IAAI,CAAC,YAAY,GAAG,I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,MAAM,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,0BAA0B,CAAC,CAAC;QACjE,CAAC;gBACO,CAAC;YACL,IAAI,CAAC,mBAAmB,CAAC,UAAU;gBAC/B,MAAM,mBAAmB,CAAC,OAAO,EAAE,CAAC;YAExC,qBAAqB,EAAE,GAAG,CAAC,gBAAgB,EAAE,qBAAqB,CAAC,CAAC,CAAC,yIAAyI;QAClN,CAAC;IACL,CAAC;IAEO,wCAAwC,CAAC,KAAY;QACzD,OAAO,KAAK,CAAC,OAAO,KAAK,iCAAiC,CAAC;IAC/D,CAAC;CACJ","sourcesContent":["import path from \"path\";\nimport { Readable } from \"stream\";\n\nimport got, { Got, Response, CancelableRequest } from \"got\";\n\nimport type { ReadableStream } from \"stream/web\";\n\nimport NodeFileServerClientBase from \"../../../utils/api/node/nodeFileserverClientBase.js\";\n\nimport FsError from \"../../../utils/fileSystem/fsError.js\";\nimport { retryEconnresetWorkaround } from \"../../../utils/api/node/gotWorkarounds.js\";\n\nimport type ChunkStreamProvider from \"../../../utils/fileSystem/chunkStreamProvider.js\";\nimport type SendFileChunkRequest from \"../../../utils/api/dtos/sendFileChunkRequest.js\";\nimport type FileServerUploadClient from \"../fileServerUploadClient.js\";\nimport type { PauseSignal } from \"../../pauseController.js\";\n\n// This should be used as a transient object - a new instance for every chunk\nexport default class NodeFileServerUploadClient extends NodeFileServerClientBase implements FileServerUploadClient {\n readonly #uploadUrl: string;\n readonly #gotInstance: Got;\n\n constructor(uploadUrl: string, transferId: string, transferKey: string, fileName: string, fileDestinationPath: string, fileTotalSizeInBytes: number, source: string, sourceDetails: string, uploadIdleTimeoutInMs: number, retryLimit: number) {\n super();\n\n this.#uploadUrl = uploadUrl;\n\n const fullDestinationFileName = path.posix.join(fileDestinationPath, fileName);\n\n this.#gotInstance = this.createGotInstance(transferId, transferKey, fullDestinationFileName, fileTotalSizeInBytes, source, sourceDetails, uploadIdleTimeoutInMs, retryLimit);\n }\n\n private createGotInstance(transferId: string, transferKey: string, fullDestinationFileName: string, fileTotalSizeInBytes: number, source: string, sourceDetails: string, uploadIdleTimeoutInMs: number, retryLimit: number): Got {\n return got.extend({\n timeout: {\n socket: uploadIdleTimeoutInMs > 0 ? uploadIdleTimeoutInMs : undefined,\n },\n searchParams: {\n transferid: transferId,\n transferkey: transferKey,\n thefilename: fullDestinationFileName,\n totalsize: fileTotalSizeInBytes,\n source,\n sourcedetails: sourceDetails,\n },\n retry: {\n limit: retryLimit,\n methods: [`GET`, `POST`, `PUT`, `PATCH`, `HEAD`, `DELETE`, `OPTIONS`, `TRACE`],\n ...retryEconnresetWorkaround,\n },\n });\n }\n\n async sendFileChunk(request: SendFileChunkRequest, chunkStreamProvider: ChunkStreamProvider, pauseSignal: PauseSignal, abortSignal: AbortSignal): Promise<void> {\n let ongoingRequestPromise: CancelableRequest<Response<string>> | null = null;\n\n const uploadProgressHandler = this.getDataTransferProgressHandler();\n\n try {\n let isRetry = false;\n\n const gotChunkInstance = this.#gotInstance.extend({\n headers: {\n 'Transfer-Encoding': `chunked`,\n },\n hooks: {\n beforeRetry: [\n requestError => {\n isRetry = true;\n // eslint-disable-next-line no-param-reassign\n requestError.options.body = ``; // clearing the body to avoid `Cannot retry with consumed body stream` error\n },\n ],\n beforeRequest: [\n async options => {\n /* eslint-disable no-param-reassign */\n if (!isRetry)\n return;\n\n const readableStream = await chunkStreamProvider.getChunkReadStream(pauseSignal, abortSignal) as ReadableStream;\n options.body = Readable.fromWeb(readableStream);\n },\n ],\n },\n });\n\n const md5checksum = await chunkStreamProvider.getMd5Checksum(`base64`, pauseSignal, abortSignal);\n\n const readableStream = await chunkStreamProvider.getChunkReadStream(pauseSignal, abortSignal) as ReadableStream;\n const body = Readable.fromWeb(readableStream);\n\n ongoingRequestPromise = gotChunkInstance.post(this.#uploadUrl, {\n body,\n signal: abortSignal,\n searchParams: {\n chunkpos: request.chunkStartPosition,\n chunksize: request.chunkLengthInBytes,\n md5: md5checksum,\n },\n });\n\n ongoingRequestPromise.on(`uploadProgress`, uploadProgressHandler);\n\n await ongoingRequestPromise;\n }\n catch (error) {\n /* eslint-disable no-ex-assign */\n if (this.isWrappedCreatingFileReadStreamException(error as Error))\n error = new FsError((error as Error).message);\n\n throw this.createApiError(error, `Error sending file chunk`);\n }\n finally {\n if (!chunkStreamProvider.isReleased)\n await chunkStreamProvider.release();\n\n ongoingRequestPromise?.off(`uploadProgress`, uploadProgressHandler); // There is a bug in GOT that it fires this event once after the got promise was canceled https://github.com/sindresorhus/got/issues/2084\n }\n }\n\n private isWrappedCreatingFileReadStreamException(error: Error): boolean {\n return error.message === `CreatingFileReadStreamException`;\n }\n}\n"]}
|
|
@@ -41,7 +41,7 @@ export default class WebFileServerUploadClient extends WebFileServerClientBase {
|
|
|
41
41
|
let isRequestFinished = false;
|
|
42
42
|
const idleTimeoutManager = new AxiosIdleTimeoutManager(this.#uploadIdleTimeoutInMs, abortSignal);
|
|
43
43
|
try {
|
|
44
|
-
const md5checksum = await chunkStreamProvider.getMd5Checksum(`base64`, pauseSignal);
|
|
44
|
+
const md5checksum = await chunkStreamProvider.getMd5Checksum(`base64`, pauseSignal, abortSignal);
|
|
45
45
|
const chunkBlob = await chunkStreamProvider.getChunkBlob();
|
|
46
46
|
const idleTimeout = idleTimeoutManager.configureNewIdleTimeout();
|
|
47
47
|
const uploadProgressHandler = this.getDataTransferProgressHandler();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webFileServerUploadClient.js","sourceRoot":"","sources":["../../../../../src/uploader/api/web/webFileServerUploadClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAwB,MAAM,OAAO,CAAC;AAC7C,OAAO,UAAU,EAAE,EAAE,iCAAiC,EAAE,MAAM,aAAa,CAAC;AAE5E,OAAO,uBAAuB,MAAM,mDAAmD,CAAC;AAExF,OAAO,OAAO,MAAM,sCAAsC,CAAC;AAC3D,OAAO,uBAAuB,MAAM,oCAAoC,CAAC;AAOzE,6EAA6E;AAC7E,MAAM,CAA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AC5B,OAAO,EAAE,IAAI,CAAC,WAAW;YACzB,UAAU,EAAE,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,IAAI;YAC3C,kBAAkB,EAAE,IAAI;YACxB,cAAc,EAAE,CAAC,CAAC,EAAE;gBAChB,MAAM,eAAe,GAAG,CAAC,CAAC,IAAI,KAAK,cAAc,IAAI,OAAO,CAAC,kBAAkB,CAAC,cAAc,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAC;gBAC3H,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;gBACpD,OAAO,iCAAiC,CAAC,CAAC,CAAC,IAAI,eAAe,IAAI,eAAe,CAAC;YACtF,CAAC;YACD,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,EAAE;gBAClD,MAAM,cAAc,GAAG,kBAAkB,CAAC,uBAAuB,EAAE,CAAC;gBAEpE,aAAa,CAAC,MAAM,GAAG,cAAc,CAAC,YAAY,CAAC;gBACnD,aAAa,CAAC,IAAI,GAAG,MAAM,mBAAmB,CAAC,YAAY,EAAE,CAAC;YAClE,CAAC;SACJ,CAAC,CAAC;IACP,CAAC;IAEO,wCAAwC,CAAC,KAAY;QACzD,OAAO,KAAK,CAAC,OAAO,KAAK,iCAAiC,CAAC;IAC/D,CAAC;CACJ","sourcesContent":["import axios, { AxiosInstance } from \"axios\";\nimport axiosRetry, { isNetworkOrIdempotentRequestError } from \"axios-retry\";\n\nimport WebFileServerClientBase from \"../../../utils/api/web/webFileserverClientBase.js\";\n\nimport FsError from \"../../../utils/fileSystem/fsError.js\";\nimport AxiosIdleTimeoutManager from \"./utils/axiosIdleTimeoutManager.js\";\n\nimport type ChunkStreamProvider from \"../../../utils/fileSystem/chunkStreamProvider.js\";\nimport type SendFileChunkRequest from \"../../../utils/api/dtos/sendFileChunkRequest.js\";\nimport type FileServerUploadClient from \"../fileServerUploadClient.js\";\nimport type { PauseSignal } from \"../../pauseController.js\";\n\n// This should be used as a transient object - a new instance for every chunk\nexport default class WebFileServerUploadClient extends WebFileServerClientBase implements FileServerUploadClient {\n readonly #uploadUrl: string;\n readonly #retryLimit: number;\n readonly #uploadIdleTimeoutInMs: number;\n\n readonly #axiosInstance: AxiosInstance;\n\n constructor(uploadUrl: string, transferId: string, transferKey: string, fileName: string, fileDestinationPath: string, fileTotalSizeInBytes: number, source: string, sourceDetails: string, uploadIdleTimeoutInMs: number, retryLimit: number) {\n super();\n\n this.#uploadUrl = uploadUrl;\n this.#retryLimit = retryLimit;\n this.#uploadIdleTimeoutInMs = uploadIdleTimeoutInMs;\n\n const fullDestinationFileName = this.joinDestinationPathAndFileName(fileDestinationPath, fileName);\n\n this.#axiosInstance = this.createAxiosInstance(transferId, transferKey, fullDestinationFileName, fileTotalSizeInBytes, source, sourceDetails);\n }\n\n private joinDestinationPathAndFileName(fileDestinationPath: string, fileName: string) {\n if (fileDestinationPath.endsWith(`/`))\n return `${fileDestinationPath}${fileName}`;\n\n return `${fileDestinationPath}/${fileName}`;\n }\n\n private createAxiosInstance(transferId: string, transferKey: string, fullDestinationFileName: string, fileTotalSizeInBytes: number, source: string, sourceDetails: string): AxiosInstance {\n return axios.create({\n params: {\n transferid: transferId,\n transferkey: transferKey,\n thefilename: fullDestinationFileName,\n totalsize: fileTotalSizeInBytes,\n source,\n sourcedetails: sourceDetails,\n },\n headers: {\n 'Content-Type': `application/octet-stream`,\n },\n });\n }\n\n async sendFileChunk(request: SendFileChunkRequest, chunkStreamProvider: ChunkStreamProvider, pauseSignal: PauseSignal, abortSignal: AbortSignal): Promise<void> {\n let isRequestFinished = false;\n\n const idleTimeoutManager = new AxiosIdleTimeoutManager(this.#uploadIdleTimeoutInMs, abortSignal);\n\n try {\n const md5checksum = await chunkStreamProvider.getMd5Checksum(`base64`, pauseSignal, abortSignal);\n const chunkBlob = await chunkStreamProvider.getChunkBlob();\n\n const idleTimeout = idleTimeoutManager.configureNewIdleTimeout();\n const uploadProgressHandler = this.getDataTransferProgressHandler();\n\n this.configureRetryMechanism(chunkStreamProvider, idleTimeoutManager);\n\n idleTimeoutManager.currentTimeout?.resetIdleTimeout();\n\n await this.#axiosInstance.post(this.#uploadUrl, chunkBlob, {\n maxBodyLength: Infinity,\n maxContentLength: Infinity,\n signal: idleTimeout.mergedSignal,\n onUploadProgress: progressEvent => {\n if (isRequestFinished)\n return; // Axios still sends events after abort signal was fired\n\n idleTimeoutManager.currentTimeout?.resetIdleTimeout();\n uploadProgressHandler(progressEvent);\n },\n params: {\n chunkpos: request.chunkStartPosition,\n chunksize: request.chunkLengthInBytes,\n md5: md5checksum,\n },\n });\n }\n catch (error) {\n /* eslint-disable no-ex-assign */\n if (this.isWrappedCreatingFileReadStreamException(error as Error))\n error = new FsError((error as Error).message);\n\n throw this.createApiError(error, `Error sending file chunk`, idleTimeoutManager.currentTimeout?.idleTimeoutSignal);\n }\n finally {\n isRequestFinished = true;\n\n idleTimeoutManager.currentTimeout?.stopIdleTimeout();\n\n if (!chunkStreamProvider.isReleased)\n await chunkStreamProvider.release();\n }\n }\n\n /* eslint-disable no-param-reassign */\n private configureRetryMechanism(chunkStreamProvider: ChunkStreamProvider, idleTimeoutManager: AxiosIdleTimeoutManager) {\n axiosRetry(this.#axiosInstance, {\n retries: this.#retryLimit,\n retryDelay: retryCount => retryCount * 1000,\n shouldResetTimeout: true,\n retryCondition: e => {\n const isIdleTimeouted = e.code === `ERR_CANCELED` && Boolean(idleTimeoutManager.currentTimeout?.idleTimeoutSignal.aborted);\n const isRetryablePost = e.config?.method === `post`;\n return isNetworkOrIdempotentRequestError(e) || isRetryablePost || isIdleTimeouted;\n },\n onRetry: async (_retryCount, _error, requestConfig) => {\n const newIdleTimeout = idleTimeoutManager.configureNewIdleTimeout();\n\n requestConfig.signal = newIdleTimeout.mergedSignal;\n requestConfig.data = await chunkStreamProvider.getChunkBlob();\n },\n });\n }\n\n private isWrappedCreatingFileReadStreamException(error: Error): boolean {\n return error.message === `CreatingFileReadStreamException`;\n }\n}\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import TransferUploadError from "./transferUploadError.js";
|
|
2
|
+
export declare function createTransferFailureAbortReason(): TransferUploadError;
|
|
3
|
+
export declare function isTransferFailureAbortReason(reason: unknown): boolean;
|
|
4
|
+
//# sourceMappingURL=transferFailureAbortReason.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transferFailureAbortReason.d.ts","sourceRoot":"","sources":["../../../src/uploader/transferFailureAbortReason.ts"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,MAAM,0BAA0B,CAAC;AAI3D,wBAAgB,gCAAgC,wBAE/C;AAED,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,OAAO,WAE3D"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import TransferUploadError from "./transferUploadError.js";
|
|
2
|
+
const TransferFailureAbortReasonMessage = `TransferFailureRequested`;
|
|
3
|
+
export function createTransferFailureAbortReason() {
|
|
4
|
+
return new TransferUploadError(TransferFailureAbortReasonMessage);
|
|
5
|
+
}
|
|
6
|
+
export function isTransferFailureAbortReason(reason) {
|
|
7
|
+
return reason instanceof TransferUploadError && reason.message === TransferFailureAbortReasonMessage;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=transferFailureAbortReason.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transferFailureAbortReason.js","sourceRoot":"","sources":["../../../src/uploader/transferFailureAbortReason.ts"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,MAAM,0BAA0B,CAAC;AAE3D,MAAM,iCAAiC,GAAG,0BAA0B,CAAC;AAErE,MAAM,UAAU,gCAAgC;IAC5C,OAAO,IAAI,mBAAmB,CAAC,iCAAiC,CAAC,CAAC;AACtE,CAAC;AAED,MAAM,UAAU,4BAA4B,CAAC,MAAe;IACxD,OAAO,MAAM,YAAY,mBAAmB,IAAI,MAAM,CAAC,OAAO,KAAK,iCAAiC,CAAC;AACzG,CAAC","sourcesContent":["import TransferUploadError from \"./transferUploadError.js\";\n\nconst TransferFailureAbortReasonMessage = `TransferFailureRequested`;\n\nexport function createTransferFailureAbortReason() {\n return new TransferUploadError(TransferFailureAbortReasonMessage);\n}\n\nexport function isTransferFailureAbortReason(reason: unknown) {\n return reason instanceof TransferUploadError && reason.message === TransferFailureAbortReasonMessage;\n}\n"]}
|
|
@@ -54,6 +54,8 @@ export default class TransferUpload<T extends FileDetails> {
|
|
|
54
54
|
private throwIfNotPossibleToRun;
|
|
55
55
|
private addPauseAndStopListeners;
|
|
56
56
|
private removePauseAndStopListeners;
|
|
57
|
+
private shouldStopSchedulingChunks;
|
|
58
|
+
private isFailureAbortRequested;
|
|
57
59
|
private startApiTransferAndCreateMetadata;
|
|
58
60
|
private generateEncryptionDataAndIvSaltHmacHex;
|
|
59
61
|
private getResponseOrForcedUdpData;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transferUpload.d.ts","sourceRoot":"","sources":["../../../src/uploader/transferUpload.ts"],"names":[],"mappings":"AAMA,OAAO,cAAc,MAAM,kCAAkC,CAAC;AAC9D,OAAO,mBAAmB,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"transferUpload.d.ts","sourceRoot":"","sources":["../../../src/uploader/transferUpload.ts"],"names":[],"mappings":"AAMA,OAAO,cAAc,MAAM,kCAAkC,CAAC;AAC9D,OAAO,mBAAmB,MAAM,0BAA0B,CAAC;AAQ3D,OAAO,KAAK,SAAS,MAAM,2BAA2B,CAAC;AAGvD,OAAO,KAAK,uBAAuB,MAAM,yCAAyC,CAAC;AACnF,OAAO,KAAK,WAAW,MAAM,oCAAoC,CAAC;AAElE,OAAO,KAAK,kBAAkB,MAAM,iCAAiC,CAAC;AACtE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uCAAuC,CAAC;AAEtF,OAAO,KAAK,YAAY,MAAM,iCAAiC,CAAC;AAChE,OAAO,KAAK,wB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AAC,KAAK,EAAE,iCAAiC,KAAK,IAAI,GAAG,IAAI;IACtI,gBAAgB,CAAC,SAAS,EAAE,mBAAmB,CAAC,iBAAiB,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,gCAAgC,KAAK,IAAI,GAAG,IAAI;IACpI,gBAAgB,CAAC,SAAS,EAAE,mBAAmB,CAAC,wBAAwB,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,iCAAiC,KAAK,IAAI,GAAG,IAAI;IAC5I,gBAAgB,CAAC,SAAS,EAAE,mBAAmB,CAAC,0BAA0B,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,mCAAmC,KAAK,IAAI,GAAG,IAAI;IAChJ,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,KAAK,IAAI,GAAG,IAAI;IAKvE,cAAc,IAAI,MAAM;IAKxB,MAAM,IAAI,wBAAwB,CAAC,CAAC,CAAC;IAWrC,OAAO,CAAC,8BAA8B;IAetC,MAAM,CAAC,QAAQ,CAAC,CAAC,SAAS,WAAW,EAAE,kBAAkB,EAAE,wBAAwB,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,kCAAkC,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAE,oBAAoB,GAAG,cAAc,CAAC,CAAC,CAAC;IAmB/W,OAAO,CAAC,MAAM,CAAC,wBAAwB;IAevC,OAAO,CAAC,MAAM,CAAC,sBAAsB;CAiBxC"}
|
|
@@ -9,6 +9,7 @@ import ChunksIterator from './chunksIterator/chunksIterator.js';
|
|
|
9
9
|
import mergeAbortAndPauseSignals from '../utils/mergeAbortAndPauseSignals.js';
|
|
10
10
|
import ApiFilemail449Error from '../utils/api/apiFilemail449Error.js';
|
|
11
11
|
import { promiseAllSettled } from '../utils/promiseAll.js';
|
|
12
|
+
import { isTransferFailureAbortReason } from './transferFailureAbortReason.js';
|
|
12
13
|
import { concatUint8Arrays, hexToUint8Array, uint8ArrayToHex } from '../utils/uint8ArrayUtils.js';
|
|
13
14
|
export default class TransferUpload {
|
|
14
15
|
#totalSizeInBytes;
|
|
@@ -127,7 +128,7 @@ export default class TransferUpload {
|
|
|
127
128
|
if (this.#optimizer.currentSleepTimeInMs >= 1)
|
|
128
129
|
// eslint-disable-next-line no-await-in-loop
|
|
129
130
|
await sleep(this.#optimizer.currentSleepTimeInMs, this.#mergedPauseAndAbortSignal);
|
|
130
|
-
if (this
|
|
131
|
+
if (this.shouldStopSchedulingChunks()) {
|
|
131
132
|
releaseSemaphore();
|
|
132
133
|
break;
|
|
133
134
|
}
|
|
@@ -136,10 +137,10 @@ export default class TransferUpload {
|
|
|
136
137
|
ongoingChunkUploads.delete(trackedChunkUploadPromise);
|
|
137
138
|
});
|
|
138
139
|
ongoingChunkUploads.add(trackedChunkUploadPromise);
|
|
139
|
-
if (this
|
|
140
|
+
if (this.shouldStopSchedulingChunks())
|
|
140
141
|
break;
|
|
141
142
|
}
|
|
142
|
-
if (this
|
|
143
|
+
if (this.shouldStopSchedulingChunks())
|
|
143
144
|
break;
|
|
144
145
|
}
|
|
145
146
|
await promiseAllSettled(Array.from(ongoingChunkUploads));
|
|
@@ -148,6 +149,8 @@ export default class TransferUpload {
|
|
|
148
149
|
this.#transferState.transferPaused();
|
|
149
150
|
else if (this.#transferState.status === TransferStatus.Aborting)
|
|
150
151
|
this.#transferState.transferAborted();
|
|
152
|
+
// else if (this.isFailureAbortRequested())
|
|
153
|
+
// this.#transferState.transferFailed();
|
|
151
154
|
else if (this.uploadedBytesCount !== this.totalSizeInBytes)
|
|
152
155
|
this.#transferState.transferFailed();
|
|
153
156
|
else {
|
|
@@ -159,6 +162,10 @@ export default class TransferUpload {
|
|
|
159
162
|
// We can get here with pausing or aborting status if any API call fails (e.g., finalizeTransfer) so we need to check the status again
|
|
160
163
|
if (!this.#transferState)
|
|
161
164
|
this.#eventsEngine.emit(TransferUploadEvent.TransferFailed);
|
|
165
|
+
// else if (this.isFailureAbortRequested()) {
|
|
166
|
+
// this.#transferState.transferFailed();
|
|
167
|
+
// return;
|
|
168
|
+
// }
|
|
162
169
|
else if (this.#transferState.status === TransferStatus.Pausing) {
|
|
163
170
|
this.#transferState.transferPaused();
|
|
164
171
|
return;
|
|
@@ -331,6 +338,8 @@ export default class TransferUpload {
|
|
|
331
338
|
this.#transferState.transferPauseRequested();
|
|
332
339
|
};
|
|
333
340
|
this.abortEventListener = () => {
|
|
341
|
+
if (this.isFailureAbortRequested())
|
|
342
|
+
return;
|
|
334
343
|
if (this.#transferState.status !== TransferStatus.Running)
|
|
335
344
|
throw new TransferUploadError(`Transfer is in ${TransferStatus[this.#transferState.status]} state and cannot be stopped`);
|
|
336
345
|
this.#transferState.transferAbortRequested();
|
|
@@ -342,6 +351,12 @@ export default class TransferUpload {
|
|
|
342
351
|
this.#pauseSignal.removeEventListener(`pause`, this.pauseEventListener);
|
|
343
352
|
this.#abortSignal.removeEventListener(`abort`, this.abortEventListener);
|
|
344
353
|
}
|
|
354
|
+
shouldStopSchedulingChunks() {
|
|
355
|
+
return this.#transferState.status !== TransferStatus.Running || this.#abortSignal?.aborted === true || this.#pauseSignal?.paused === true;
|
|
356
|
+
}
|
|
357
|
+
isFailureAbortRequested() {
|
|
358
|
+
return isTransferFailureAbortReason(this.#abortSignal?.reason);
|
|
359
|
+
}
|
|
345
360
|
async startApiTransferAndCreateMetadata() {
|
|
346
361
|
if (this.isUploadAppendInfo(this.#info))
|
|
347
362
|
throw new TransferUploadError(`Options are not TransferUploadOptions`);
|