filemail-sdk 9.4.6 → 9.4.7
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/LICENSE +10 -10
- package/dist/src/autoDownloader/autoDownloader.js.map +1 -1
- package/dist/src/autoDownloader/autoDownloaderDestroyer.js.map +1 -1
- package/dist/src/autoDownloader/autoDownloaderError.js.map +1 -1
- package/dist/src/autoDownloader/autoDownloaderEvent.js.map +1 -1
- package/dist/src/autoDownloader/autoDownloaderOptions.js.map +1 -1
- package/dist/src/autoDownloader/autoDownloaderStateSerializer.js.map +1 -1
- package/dist/src/autoDownloader/eventArgs/autoDownloadEventArgs.js.map +1 -1
- package/dist/src/autoDownloader/eventArgs/autoDownloadFailedEventArgs.js.map +1 -1
- package/dist/src/autoDownloader/eventArgs/autoDownloadProgressedEventArgs.js.map +1 -1
- package/dist/src/autoDownloader/eventArgs/autoDownloadStartedEventArgs.js.map +1 -1
- package/dist/src/autoDownloader/eventArgs/autoDownloadStartingFailedEventArgs.js.map +1 -1
- package/dist/src/autoDownloader/eventArgs/autoDownloadUnhealthyEventArgs.js.map +1 -1
- package/dist/src/autoDownloader/eventArgs/checkingForNewTransfersStartedEventArgs.js.map +1 -1
- package/dist/src/autoDownloader/eventArgs/newTransfersCheckCompletedEventArgs.js.map +1 -1
- package/dist/src/autoDownloader/factory/nodeAutoDownloaderFactory.js.map +1 -1
- package/dist/src/autoDownloader/factory/nodeAutoDownloaderFactoryOptions.js.map +1 -1
- package/dist/src/autoDownloader/newInboxTransfersRetriever/newInboxTransfer.js.map +1 -1
- package/dist/src/autoDownloader/newInboxTransfersRetriever/newInboxTransfersRetriever.js.map +1 -1
- package/dist/src/autoDownloader/node/nodeAutoDownloaderStateSerializer.js.map +1 -1
- package/dist/src/autoDownloader/node/nodeTransferDownloaderFactory.js.map +1 -1
- package/dist/src/autoDownloader/state/autoDownloaderRecoverableState.js.map +1 -1
- package/dist/src/autoDownloader/state/autoDownloaderState.js.map +1 -1
- package/dist/src/autoDownloader/state/autoDownloaderStateRecoverableTransfer.js.map +1 -1
- package/dist/src/autoDownloader/state/autoDownloaderStateRunningTransfer.js.map +1 -1
- package/dist/src/autoDownloader/state/autoDownloaderStateSnapshot.js.map +1 -1
- package/dist/src/autoDownloader/transferDownloaderFactory.js.map +1 -1
- package/dist/src/autoDownloader/transferHandler/autoDownloaderNewTransferHandler.js.map +1 -1
- package/dist/src/autoDownloader/transferHandler/autoDownloaderRecoverableTransferHandler.js.map +1 -1
- package/dist/src/autoDownloader/transferHandler/autoDownloaderTransferHandlerBase.js.map +1 -1
- package/dist/src/client/downloader/downloaderCore.js.map +1 -1
- package/dist/src/client/downloader/node/nodeTransferDownloader.js.map +1 -1
- package/dist/src/client/downloader/transferDownloader.js.map +1 -1
- package/dist/src/client/environmentVariables.js.map +1 -1
- package/dist/src/client/healthMonitor/events/eventArgs/healthMonitorHealthyEventArgs.js.map +1 -1
- package/dist/src/client/healthMonitor/events/eventArgs/healthMonitorUnhealthyEventArgs.js.map +1 -1
- package/dist/src/client/healthMonitor/events/transferHealthMonitorEvent.js.map +1 -1
- package/dist/src/client/healthMonitor/onlineChecker/nodeOnlineChecker.js.map +1 -1
- package/dist/src/client/healthMonitor/onlineChecker/onlineChecker.d.ts +10 -1
- package/dist/src/client/healthMonitor/onlineChecker/onlineChecker.d.ts.map +1 -1
- package/dist/src/client/healthMonitor/onlineChecker/onlineChecker.js +103 -12
- package/dist/src/client/healthMonitor/onlineChecker/onlineChecker.js.map +1 -1
- package/dist/src/client/healthMonitor/onlineChecker/webOnlineChecker.d.ts +5 -0
- package/dist/src/client/healthMonitor/onlineChecker/webOnlineChecker.d.ts.map +1 -1
- package/dist/src/client/healthMonitor/onlineChecker/webOnlineChecker.js +32 -1
- package/dist/src/client/healthMonitor/onlineChecker/webOnlineChecker.js.map +1 -1
- package/dist/src/client/healthMonitor/transferDownloaderHealthMonitor.js.map +1 -1
- package/dist/src/client/healthMonitor/transferHealthMonitorBase.js.map +1 -1
- package/dist/src/client/healthMonitor/transferUploaderHealthMonitor.js.map +1 -1
- package/dist/src/client/loggers/dummyLogger.js.map +1 -1
- package/dist/src/client/loggers/logger.js.map +1 -1
- package/dist/src/client/loggers/utils/logHealthyStatus.js +23 -0
- package/dist/src/client/loggers/utils/logHealthyStatus.js.map +1 -1
- package/dist/src/client/node/nodeFileDetailsProvider.js.map +1 -1
- package/dist/src/client/uploader/node/nodeTransferUploader.js.map +1 -1
- package/dist/src/client/uploader/transferUploader.js.map +1 -1
- package/dist/src/client/uploader/transferUploaderBase.js.map +1 -1
- package/dist/src/client/uploader/transferUploaderConfig.js.map +1 -1
- package/dist/src/client/uploader/utils/uploaderUtils.js.map +1 -1
- package/dist/src/client/uploader/web/webTransferUploader.js.map +1 -1
- package/dist/src/downloader/api/fileServerDownloadClient.js.map +1 -1
- package/dist/src/downloader/api/node/nodeFileServerDownloadClient.js.map +1 -1
- package/dist/src/downloader/chunkDownloader.d.ts.map +1 -1
- package/dist/src/downloader/chunkDownloader.js +18 -1
- package/dist/src/downloader/chunkDownloader.js.map +1 -1
- package/dist/src/downloader/downloadFolderResolver.js.map +1 -1
- package/dist/src/downloader/downloadLogger.js.map +1 -1
- package/dist/src/downloader/downloadOptions.js.map +1 -1
- package/dist/src/downloader/downloadStatus/downloadFileChunkProgress.js.map +1 -1
- package/dist/src/downloader/downloadStatus/downloadFileProgress.js.map +1 -1
- package/dist/src/downloader/downloadStatus/downloadFilePromise.js.map +1 -1
- package/dist/src/downloader/downloadStatus/downloadState.js.map +1 -1
- package/dist/src/downloader/downloadTracker.js.map +1 -1
- package/dist/src/downloader/dtos/downloadCommand.js.map +1 -1
- package/dist/src/downloader/dtos/downloadError.js.map +1 -1
- package/dist/src/downloader/dtos/downloadErrorCode.js.map +1 -1
- package/dist/src/downloader/dtos/downloadEvent.js.map +1 -1
- package/dist/src/downloader/dtos/downloadFileChunkInfo.js.map +1 -1
- package/dist/src/downloader/dtos/downloadFileInfo.js.map +1 -1
- package/dist/src/downloader/dtos/downloadFilesCommand.js.map +1 -1
- package/dist/src/downloader/dtos/downloadInfo.js.map +1 -1
- package/dist/src/downloader/dtos/downloadRegistrationMode.js.map +1 -1
- package/dist/src/downloader/dtos/downloadTrackerFileInfo.js.map +1 -1
- package/dist/src/downloader/dtos/downloadTrackerFileProgressInfo.js.map +1 -1
- package/dist/src/downloader/dtos/downloadTrackerProgressInfo.js.map +1 -1
- package/dist/src/downloader/dtos/downloadTrackingMetadata.js.map +1 -1
- package/dist/src/downloader/dtos/downloaderRestoredState.js.map +1 -1
- package/dist/src/downloader/eventArgs/chunkDownloadEventArgs.js.map +1 -1
- package/dist/src/downloader/eventArgs/chunkDownloadFailedEventArgs.js.map +1 -1
- package/dist/src/downloader/eventArgs/downloadCompletedEventArgs.js.map +1 -1
- package/dist/src/downloader/eventArgs/downloadEventArgs.js.map +1 -1
- package/dist/src/downloader/eventArgs/downloadMetadataDeterminedEventArgs.js.map +1 -1
- package/dist/src/downloader/eventArgs/downloadPauseEventArgs.js.map +1 -1
- package/dist/src/downloader/eventArgs/downloadTrackingFailedEventArgs.js.map +1 -1
- package/dist/src/downloader/eventArgs/fileDownloadEventArgs.js.map +1 -1
- package/dist/src/downloader/eventArgs/fileDownloadFailedEventArgs.js.map +1 -1
- package/dist/src/downloader/filesDownloader.js.map +1 -1
- package/dist/src/downloader/filesPreparer.js.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/index.node.js.map +1 -1
- package/dist/src/index.web.js.map +1 -1
- package/dist/src/uploader/api/dtos/handshakeRequest.js.map +1 -1
- package/dist/src/uploader/api/dtos/handshakeResponse.js.map +1 -1
- package/dist/src/uploader/api/dtos/pingResponse.js.map +1 -1
- package/dist/src/uploader/api/dtos/sendChunkRequest.js.map +1 -1
- package/dist/src/uploader/api/fileServerUdpClient.js.map +1 -1
- package/dist/src/uploader/api/fileServerUploadClient.js.map +1 -1
- package/dist/src/uploader/api/node/nodeFileServerUdpClient.js +8 -8
- package/dist/src/uploader/api/node/nodeFileServerUdpClient.js.map +1 -1
- package/dist/src/uploader/api/node/nodeFileServerUploadClient.js.map +1 -1
- package/dist/src/uploader/api/web/utils/axiosIdleTimeoutManager.js.map +1 -1
- package/dist/src/uploader/api/web/webFileServerUploadClient.js.map +1 -1
- package/dist/src/uploader/chunkStreamProviderFactory/nodeFileDetailsUploaderChunkStreamProviderFactory.js.map +1 -1
- package/dist/src/uploader/chunkStreamProviderFactory/uploaderChunkStreamProviderFactory.js.map +1 -1
- package/dist/src/uploader/chunkStreamProviderFactory/webFileDetailsUploaderChunkStreamProviderFactory.js.map +1 -1
- package/dist/src/uploader/chunksIterator/chunksIterator.js.map +1 -1
- package/dist/src/uploader/eventArgs/fileChunkUploadCompletedEventArgs.js.map +1 -1
- package/dist/src/uploader/eventArgs/fileChunkUploadCompletedPartiallyEventArgs.js.map +1 -1
- package/dist/src/uploader/eventArgs/fileChunkUploadEventArgs.js.map +1 -1
- package/dist/src/uploader/eventArgs/fileChunkUploadFailedEventArgs.js.map +1 -1
- package/dist/src/uploader/eventArgs/fileChunkUploadProgressedEventArgs.js.map +1 -1
- package/dist/src/uploader/eventArgs/fileUploadEventArgs.js.map +1 -1
- package/dist/src/uploader/eventArgs/fileUploadFailedEventArgs.js.map +1 -1
- package/dist/src/uploader/eventArgs/transferMetadataDeterminedEventArgs.js.map +1 -1
- package/dist/src/uploader/eventArgs/transferUploadCompletedEventArgs.js.map +1 -1
- package/dist/src/uploader/eventArgs/transferUploadModeChosenEventArgs.js.map +1 -1
- package/dist/src/uploader/eventArgs/transferUploadProgressedEventArgs.js.map +1 -1
- package/dist/src/uploader/export/transferUploadExportData.js.map +1 -1
- package/dist/src/uploader/export/transferUploadExportState.js.map +1 -1
- package/dist/src/uploader/export/transferUploadMetadata.js.map +1 -1
- package/dist/src/uploader/optimizer/optimizationValues.js.map +1 -1
- package/dist/src/uploader/optimizer/strategies/udpConcurrencyBasedOptimizationStrategy.js.map +1 -1
- package/dist/src/uploader/optimizer/strategies/udpSleepBasedOptimizationStrategy.js.map +1 -1
- package/dist/src/uploader/optimizer/transferUploadOptimizationStrategy.js.map +1 -1
- package/dist/src/uploader/optimizer/transferUploadOptimizer.js.map +1 -1
- package/dist/src/uploader/optimizer/uploadOptimizer.js.map +1 -1
- package/dist/src/uploader/options/transferUploadAppendInfo.js.map +1 -1
- package/dist/src/uploader/options/transferUploadConfig.js.map +1 -1
- package/dist/src/uploader/options/transferUploadInfo.js.map +1 -1
- package/dist/src/uploader/options/transferUploadInfoBase.js.map +1 -1
- package/dist/src/uploader/pauseController.js.map +1 -1
- package/dist/src/uploader/state/continuousChunksCalculator.js.map +1 -1
- package/dist/src/uploader/state/readonlyTransferUploadStateFile.js.map +1 -1
- package/dist/src/uploader/state/readonlyTransferUploadStateFiles.js.map +1 -1
- package/dist/src/uploader/state/transferUploadProgressCalculator.js.map +1 -1
- package/dist/src/uploader/state/transferUploadState.js.map +1 -1
- package/dist/src/uploader/state/transferUploadStateFile.js.map +1 -1
- package/dist/src/uploader/state/transferUploadStateFiles.js.map +1 -1
- package/dist/src/uploader/transferFailureAbortReason.js.map +1 -1
- package/dist/src/uploader/transferUpload.d.ts.map +1 -1
- package/dist/src/uploader/transferUpload.js +4 -2
- package/dist/src/uploader/transferUpload.js.map +1 -1
- package/dist/src/uploader/transferUploadError.js.map +1 -1
- package/dist/src/uploader/transferUploadEvent.js.map +1 -1
- package/dist/src/utils/api/apiClient.js.map +1 -1
- package/dist/src/utils/api/apiClientBase.js.map +1 -1
- package/dist/src/utils/api/apiError.d.ts +4 -1
- package/dist/src/utils/api/apiError.d.ts.map +1 -1
- package/dist/src/utils/api/apiError.js +2 -0
- package/dist/src/utils/api/apiError.js.map +1 -1
- package/dist/src/utils/api/apiFilemail449Error.js.map +1 -1
- package/dist/src/utils/api/apiFilemailError.js.map +1 -1
- package/dist/src/utils/api/dtos/baseResponse.js.map +1 -1
- package/dist/src/utils/api/dtos/cancelTransferRequest.js.map +1 -1
- package/dist/src/utils/api/dtos/finalizeTransferRequest.js.map +1 -1
- package/dist/src/utils/api/dtos/finalizeTransferResponse.js.map +1 -1
- package/dist/src/utils/api/dtos/getCompanyResponse.js.map +1 -1
- package/dist/src/utils/api/dtos/getCompressedFileMetadataResponse.js.map +1 -1
- package/dist/src/utils/api/dtos/getInboxTransfersRequest.js.map +1 -1
- package/dist/src/utils/api/dtos/getInboxTransfersResponse.js.map +1 -1
- package/dist/src/utils/api/dtos/getRangehashResponse.js.map +1 -1
- package/dist/src/utils/api/dtos/getTransferRequest.js.map +1 -1
- package/dist/src/utils/api/dtos/getTransferResponse.js.map +1 -1
- package/dist/src/utils/api/dtos/initializeTransferRequest.js.map +1 -1
- package/dist/src/utils/api/dtos/initializeTransferResponse.js.map +1 -1
- package/dist/src/utils/api/dtos/loginRequest.js.map +1 -1
- package/dist/src/utils/api/dtos/loginResponse.js.map +1 -1
- package/dist/src/utils/api/dtos/registerFileDownloadRequest.js.map +1 -1
- package/dist/src/utils/api/dtos/registerTransferDownloadRequest.js.map +1 -1
- package/dist/src/utils/api/dtos/resetTransferRequest.js.map +1 -1
- package/dist/src/utils/api/dtos/sendFileChunkRequest.js.map +1 -1
- package/dist/src/utils/api/dtos/transferCustomFieldDto.js.map +1 -1
- package/dist/src/utils/api/dtos/transferFileDto.js.map +1 -1
- package/dist/src/utils/api/fileServerClientFactory.js.map +1 -1
- package/dist/src/utils/api/node/gotWorkarounds.js.map +1 -1
- package/dist/src/utils/api/node/nodeApiClient.js.map +1 -1
- package/dist/src/utils/api/node/nodeClientBase.d.ts +1 -0
- package/dist/src/utils/api/node/nodeClientBase.d.ts.map +1 -1
- package/dist/src/utils/api/node/nodeClientBase.js +7 -1
- package/dist/src/utils/api/node/nodeClientBase.js.map +1 -1
- package/dist/src/utils/api/node/nodeFileServerClientFactory.js.map +1 -1
- package/dist/src/utils/api/node/nodeFileserverClientBase.js.map +1 -1
- package/dist/src/utils/api/urlUtil.js.map +1 -1
- package/dist/src/utils/api/web/webApiClient.js.map +1 -1
- package/dist/src/utils/api/web/webClientBase.d.ts +1 -0
- package/dist/src/utils/api/web/webClientBase.d.ts.map +1 -1
- package/dist/src/utils/api/web/webClientBase.js +7 -1
- package/dist/src/utils/api/web/webClientBase.js.map +1 -1
- package/dist/src/utils/api/web/webFileServerClientFactory.js.map +1 -1
- package/dist/src/utils/api/web/webFileserverClientBase.js.map +1 -1
- package/dist/src/utils/concurrencyController/concurrencyController.js.map +1 -1
- package/dist/src/utils/concurrencyController/concurrencyReleaser.js.map +1 -1
- package/dist/src/utils/concurrencyController/transferConcurrencyController.js.map +1 -1
- package/dist/src/utils/crypto/cryptographyProvider.js.map +1 -1
- package/dist/src/utils/crypto/node/nodeCryptographyProvider.js.map +1 -1
- package/dist/src/utils/crypto/web/webCryptographyProvider.js.map +1 -1
- package/dist/src/utils/dateAndTime/simpleDateFormatter.js.map +1 -1
- package/dist/src/utils/events/chunkProgressEvent.js.map +1 -1
- package/dist/src/utils/events/eventsEngine.js.map +1 -1
- package/dist/src/utils/events/node/nodeEventsEngine.js.map +1 -1
- package/dist/src/utils/events/web/webEventsEngine.js.map +1 -1
- package/dist/src/utils/fileSystem/chunkStreamProvider.js.map +1 -1
- package/dist/src/utils/fileSystem/chunkStreamProviderFactory.js.map +1 -1
- package/dist/src/utils/fileSystem/fileDetails.js.map +1 -1
- package/dist/src/utils/fileSystem/fileSystemService.js.map +1 -1
- package/dist/src/utils/fileSystem/fsError.js.map +1 -1
- package/dist/src/utils/fileSystem/node/nodeChunkStreamProvider.js.map +1 -1
- package/dist/src/utils/fileSystem/node/nodeChunkStreamProviderFactory.js.map +1 -1
- package/dist/src/utils/fileSystem/node/nodeFileDetails.js.map +1 -1
- package/dist/src/utils/fileSystem/node/nodeFileSystemService.js.map +1 -1
- package/dist/src/utils/fileSystem/parsedPath.js.map +1 -1
- package/dist/src/utils/fileSystem/web/chunkStreamProvider/webChunkStreamEncrypter.js.map +1 -1
- package/dist/src/utils/fileSystem/web/chunkStreamProvider/webChunkStreamProvider.js.map +1 -1
- package/dist/src/utils/fileSystem/web/webChunkStreamProviderFactory.js.map +1 -1
- package/dist/src/utils/fileSystem/web/webFileDetails.js.map +1 -1
- package/dist/src/utils/jsonParsing.js.map +1 -1
- package/dist/src/utils/logging/logEventPropertyNames.js.map +1 -1
- package/dist/src/utils/mergeAbortAndPauseSignals.js.map +1 -1
- package/dist/src/utils/networking/throttlingOptions.js.map +1 -1
- package/dist/src/utils/promiseAll.js.map +1 -1
- package/dist/src/utils/types/transferStatus.js.map +1 -1
- package/dist/src/utils/uint8ArrayUtils.js.map +1 -1
- package/package.json +79 -79
- package/readme.md +18 -18
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uploaderUtils.js","sourceRoot":"","sources":["../../../../../src/client/uploader/utils/uploaderUtils.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,iBAAiB,CAAC,MAA8B;IAC5D,OAAO;QACH,2BAA2B,EAAE,MAAM,CAAC,2BAA2B;QAC/D,wBAAwB,EAAE,MAAM,CAAC,wBAAwB;QACzD,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,UAAU,EAAE,MAAM,CAAC,UAAU;KAChC,CAAC;AACN,CAAC;AAED,sCAAsC;AACtC,MAAM,UAAU,eAAe,CAAI,YAAiE;IAChG,IAAI,4BAA4B,CAAC,YAAY,CAAC;QAC1C,YAAY,CAAC,qBAAqB,GAAG,IAAI,GAAG,CAAC,eAAe,EAAE,YAAY,CAAC,qBAAqB,CAAC,CAAC,IAAI,CAAC;AAC/G,CAAC;AAED,MAAM,UAAU,4BAA4B,CAAI,IAAyD;IACrG,OAAQ,IAAoC,CAAC,WAAW,KAAK,SAAS,CAAC;AAC3E,CAAC;AAED,MAAM,UAAU,cAAc,CAAwB,wBAA6G;IAC/J,MAAM,oBAAoB,GAAG,wBAA+E,CAAC;IAC7G,OAAO,oBAAoB,CAAC,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,OAAO,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC;AACjG,CAAC","sourcesContent":["import type { TransferUploadExportData } from \"../../../uploader/export/transferUploadExportData.js\";\nimport type { TransferUploadAppendInfo } from \"../../../uploader/options/transferUploadAppendInfo.js\";\nimport type TransferUploadConfig from \"../../../uploader/options/transferUploadConfig.js\";\nimport type TransferUploadInfo from \"../../../uploader/options/transferUploadInfo.js\";\nimport type FileDetails from \"../../../utils/fileSystem/fileDetails.js\";\nimport type TransferUploaderConfig from \"../transferUploaderConfig.js\";\n\nexport function buildUploadConfig(config: TransferUploaderConfig): TransferUploadConfig {\n return {\n progressEventThrottlingInMs: config.progressEventThrottlingInMs,\n currentRatesTimespanInMs: config.currentRatesTimespanInMs,\n forceUdp: config.forceUdp,\n turnOffUdp: config.turnOffUdp,\n };\n}\n\n/* eslint-disable no-param-reassign */\nexport function fixTransferInfo<T>(transferInfo: TransferUploadInfo<T> | TransferUploadAppendInfo<T>): void {\n if (isTransferUploaderAppendInfo(transferInfo))\n transferInfo.transferFileServerUrl = new URL(`savefile.ashx`, transferInfo.transferFileServerUrl).href;\n}\n\nexport function isTransferUploaderAppendInfo<T>(info: TransferUploadInfo<T> | TransferUploadAppendInfo<T>): info is TransferUploadAppendInfo<T> {\n return (info as TransferUploadAppendInfo<T>).transferKey !== undefined;\n}\n\nexport function isTransferInfo<T extends FileDetails>(transferInfoOrExportData: (TransferUploadInfo<T> | TransferUploadAppendInfo<T>) | TransferUploadExportData<T>): transferInfoOrExportData is TransferUploadInfo<T> | TransferUploadAppendInfo<T> {\n const possiblyTransferInfo = transferInfoOrExportData as TransferUploadInfo<T> | TransferUploadAppendInfo<T>;\n return possiblyTransferInfo.files !== undefined && Array.isArray(possiblyTransferInfo.files);\n}"]}
|
|
1
|
+
{"version":3,"file":"uploaderUtils.js","sourceRoot":"","sources":["../../../../../src/client/uploader/utils/uploaderUtils.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,iBAAiB,CAAC,MAA8B;IAC5D,OAAO;QACH,2BAA2B,EAAE,MAAM,CAAC,2BAA2B;QAC/D,wBAAwB,EAAE,MAAM,CAAC,wBAAwB;QACzD,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,UAAU,EAAE,MAAM,CAAC,UAAU;KAChC,CAAC;AACN,CAAC;AAED,sCAAsC;AACtC,MAAM,UAAU,eAAe,CAAI,YAAiE;IAChG,IAAI,4BAA4B,CAAC,YAAY,CAAC;QAC1C,YAAY,CAAC,qBAAqB,GAAG,IAAI,GAAG,CAAC,eAAe,EAAE,YAAY,CAAC,qBAAqB,CAAC,CAAC,IAAI,CAAC;AAC/G,CAAC;AAED,MAAM,UAAU,4BAA4B,CAAI,IAAyD;IACrG,OAAQ,IAAoC,CAAC,WAAW,KAAK,SAAS,CAAC;AAC3E,CAAC;AAED,MAAM,UAAU,cAAc,CAAwB,wBAA6G;IAC/J,MAAM,oBAAoB,GAAG,wBAA+E,CAAC;IAC7G,OAAO,oBAAoB,CAAC,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,OAAO,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC;AACjG,CAAC","sourcesContent":["import type { TransferUploadExportData } from \"../../../uploader/export/transferUploadExportData.js\";\r\nimport type { TransferUploadAppendInfo } from \"../../../uploader/options/transferUploadAppendInfo.js\";\r\nimport type TransferUploadConfig from \"../../../uploader/options/transferUploadConfig.js\";\r\nimport type TransferUploadInfo from \"../../../uploader/options/transferUploadInfo.js\";\r\nimport type FileDetails from \"../../../utils/fileSystem/fileDetails.js\";\r\nimport type TransferUploaderConfig from \"../transferUploaderConfig.js\";\r\n\r\nexport function buildUploadConfig(config: TransferUploaderConfig): TransferUploadConfig {\r\n return {\r\n progressEventThrottlingInMs: config.progressEventThrottlingInMs,\r\n currentRatesTimespanInMs: config.currentRatesTimespanInMs,\r\n forceUdp: config.forceUdp,\r\n turnOffUdp: config.turnOffUdp,\r\n };\r\n}\r\n\r\n/* eslint-disable no-param-reassign */\r\nexport function fixTransferInfo<T>(transferInfo: TransferUploadInfo<T> | TransferUploadAppendInfo<T>): void {\r\n if (isTransferUploaderAppendInfo(transferInfo))\r\n transferInfo.transferFileServerUrl = new URL(`savefile.ashx`, transferInfo.transferFileServerUrl).href;\r\n}\r\n\r\nexport function isTransferUploaderAppendInfo<T>(info: TransferUploadInfo<T> | TransferUploadAppendInfo<T>): info is TransferUploadAppendInfo<T> {\r\n return (info as TransferUploadAppendInfo<T>).transferKey !== undefined;\r\n}\r\n\r\nexport function isTransferInfo<T extends FileDetails>(transferInfoOrExportData: (TransferUploadInfo<T> | TransferUploadAppendInfo<T>) | TransferUploadExportData<T>): transferInfoOrExportData is TransferUploadInfo<T> | TransferUploadAppendInfo<T> {\r\n const possiblyTransferInfo = transferInfoOrExportData as TransferUploadInfo<T> | TransferUploadAppendInfo<T>;\r\n return possiblyTransferInfo.files !== undefined && Array.isArray(possiblyTransferInfo.files);\r\n}"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webTransferUploader.js","sourceRoot":"","sources":["../../../../../src/client/uploader/web/webTransferUploader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,cAAc,MAAM,qCAAqC,CAAC;AACjE,OAAO,uBAAuB,MAAM,wDAAwD,CAAC;AAC7F,OAAO,uCAAuC,MAAM,mFAAmF,CAAC;AACxI,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,oBAAoB,MAAM,4BAA4B,CAAC;AAC9D,OAAO,eAAe,MAAM,8CAA8C,CAAC;AAC3E,OAAO,gDAAgD,MAAM,kGAAkG,CAAC;AAChK,OAAO,uBAAuB,MAAM,sDAAsD,CAAC;AAC3F,OAAO,0BAA0B,MAAM,sDAAsD,CAAC;AAC9F,OAAO,YAAY,MAAM,wCAAwC,CAAC;AAClE,OAAO,gBAAgB,MAAM,uDAAuD,CAAC;AACrF,OAAO,6BAA6B,MAAM,sDAAs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AS,EAAE,YAAY,CAAC,CAAC;QAEvK,KAAK,CAAC,QAAQ,EAAE,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC;IAC9F,CAAC;CACJ","sourcesContent":["import { v4 as guid } from 'uuid';\n\nimport TransferUpload from \"../../../uploader/transferUpload.js\";\nimport TransferUploadOptimizer from \"../../../uploader/optimizer/transferUploadOptimizer.js\";\nimport UdpConcurrencyBasedOptimizationStrategy from \"../../../uploader/optimizer/strategies/udpConcurrencyBasedOptimizationStrategy.js\";\nimport { buildUploadConfig, fixTransferInfo } from '../utils/uploaderUtils.js';\nimport TransferUploaderBase from \"../transferUploaderBase.js\";\nimport WebEventsEngine from '../../../utils/events/web/webEventsEngine.js';\nimport WebFileDetailsUploaderChunkStreamProviderFactory from '../../../uploader/chunkStreamProviderFactory/webFileDetailsUploaderChunkStreamProviderFactory.js';\nimport WebCryptographyProvider from '../../../utils/crypto/web/webCryptographyProvider.js';\nimport WebFileServerClientFactory from '../../../utils/api/web/webFileServerClientFactory.js';\nimport WebApiClient from '../../../utils/api/web/webApiClient.js';\nimport WebOnlineChecker from '../../healthMonitor/onlineChecker/webOnlineChecker.js';\nimport TransferUploaderHealthMonitor from '../../healthMonitor/transferUploaderHealthMonitor.js';\n\nimport type Logger from \"../../loggers/logger.js\";\nimport type EnvironmentVariables from \"../../environmentVariables.js\";\nimport type TransferUploadInfo from \"../../../uploader/options/transferUploadInfo.js\";\nimport type { TransferUploadAppendInfo } from \"../../../uploader/options/transferUploadAppendInfo.js\";\nimport type TransferUploaderConfig from \"../transferUploaderConfig.js\";\nimport type WebFileDetails from \"../../../utils/fileSystem/web/webFileDetails.js\";\n\nexport default class WebTransferUploader extends TransferUploaderBase<WebFileDetails> {\n constructor(transferInfo: TransferUploadInfo<WebFileDetails> | TransferUploadAppendInfo<WebFileDetails>, config: TransferUploaderConfig, envValues: EnvironmentVariables, logger: Logger) {\n const trackingId = config.trackingId || guid();\n\n const eventsEngine = new WebEventsEngine();\n const chunkStreamProviderFactory = new WebFileDetailsUploaderChunkStreamProviderFactory();\n const optimizer = new TransferUploadOptimizer(config.tcpChunkSizeInBytes, config.tcpChunksUploadInParallel, eventsEngine, new UdpConcurrencyBasedOptimizationStrategy());\n const fileServerClientFactory = new WebFileServerClientFactory(envValues.source, envValues.sourceDetails, config.uploadIdleTimeoutInMs, config.chunkUploadRetryLimit);\n const cryptography = new WebCryptographyProvider();\n const uploadConfig = buildUploadConfig(config);\n const healthMonitor = new TransferUploaderHealthMonitor(new WebOnlineChecker(envValues.apiBaseUrl), eventsEngine);\n\n const apiClient = new WebApiClient(envValues.apiBaseUrl, envValues.source, envValues.sourceDetails, config.apiRequestTotalTimeoutInMs, config.apiRetryLimit);\n\n if (config.logintoken)\n apiClient.setLoginToken(config.logintoken);\n\n fixTransferInfo(transferInfo);\n\n const transfer = new TransferUpload(chunkStreamProviderFactory, apiClient, fileServerClientFactory, eventsEngine, transferInfo, uploadConfig, optimizer, cryptography);\n\n super(transfer, transferInfo.files, config, envValues, logger, healthMonitor, trackingId);\n }\n}"]}
|
|
1
|
+
{"version":3,"file":"webTransferUploader.js","sourceRoot":"","sources":["../../../../../src/client/uploader/web/webTransferUploader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,cAAc,MAAM,qCAAqC,CAAC;AACjE,OAAO,uBAAuB,MAAM,wDAAwD,CAAC;AAC7F,OAAO,uCAAuC,MAAM,mFAAmF,CAAC;AACxI,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,oBAAoB,MAAM,4BAA4B,CAAC;AAC9D,OAAO,eAAe,MAAM,8CAA8C,CAAC;AAC3E,OAAO,gDAAgD,MAAM,kGAAkG,CAAC;AAChK,OAAO,uBAAuB,MAAM,sDAAsD,CAAC;AAC3F,OAAO,0BAA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,CAAC,CAAC;QAE9B,MAAM,QAAQ,GAAG,IAAI,cAAc,CAAC,0BAA0B,EAAE,SAAS,EAAE,uBAAuB,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC;QAEvK,KAAK,CAAC,QAAQ,EAAE,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC;IAC9F,CAAC;CACJ","sourcesContent":["import { v4 as guid } from 'uuid';\r\n\r\nimport TransferUpload from \"../../../uploader/transferUpload.js\";\r\nimport TransferUploadOptimizer from \"../../../uploader/optimizer/transferUploadOptimizer.js\";\r\nimport UdpConcurrencyBasedOptimizationStrategy from \"../../../uploader/optimizer/strategies/udpConcurrencyBasedOptimizationStrategy.js\";\r\nimport { buildUploadConfig, fixTransferInfo } from '../utils/uploaderUtils.js';\r\nimport TransferUploaderBase from \"../transferUploaderBase.js\";\r\nimport WebEventsEngine from '../../../utils/events/web/webEventsEngine.js';\r\nimport WebFileDetailsUploaderChunkStreamProviderFactory from '../../../uploader/chunkStreamProviderFactory/webFileDetailsUploaderChunkStreamProviderFactory.js';\r\nimport WebCryptographyProvider from '../../../utils/crypto/web/webCryptographyProvider.js';\r\nimport WebFileServerClientFactory from '../../../utils/api/web/webFileServerClientFactory.js';\r\nimport WebApiClient from '../../../utils/api/web/webApiClient.js';\r\nimport WebOnlineChecker from '../../healthMonitor/onlineChecker/webOnlineChecker.js';\r\nimport TransferUploaderHealthMonitor from '../../healthMonitor/transferUploaderHealthMonitor.js';\r\n\r\nimport type Logger from \"../../loggers/logger.js\";\r\nimport type EnvironmentVariables from \"../../environmentVariables.js\";\r\nimport type TransferUploadInfo from \"../../../uploader/options/transferUploadInfo.js\";\r\nimport type { TransferUploadAppendInfo } from \"../../../uploader/options/transferUploadAppendInfo.js\";\r\nimport type TransferUploaderConfig from \"../transferUploaderConfig.js\";\r\nimport type WebFileDetails from \"../../../utils/fileSystem/web/webFileDetails.js\";\r\n\r\nexport default class WebTransferUploader extends TransferUploaderBase<WebFileDetails> {\r\n constructor(transferInfo: TransferUploadInfo<WebFileDetails> | TransferUploadAppendInfo<WebFileDetails>, config: TransferUploaderConfig, envValues: EnvironmentVariables, logger: Logger) {\r\n const trackingId = config.trackingId || guid();\r\n\r\n const eventsEngine = new WebEventsEngine();\r\n const chunkStreamProviderFactory = new WebFileDetailsUploaderChunkStreamProviderFactory();\r\n const optimizer = new TransferUploadOptimizer(config.tcpChunkSizeInBytes, config.tcpChunksUploadInParallel, eventsEngine, new UdpConcurrencyBasedOptimizationStrategy());\r\n const fileServerClientFactory = new WebFileServerClientFactory(envValues.source, envValues.sourceDetails, config.uploadIdleTimeoutInMs, config.chunkUploadRetryLimit);\r\n const cryptography = new WebCryptographyProvider();\r\n const uploadConfig = buildUploadConfig(config);\r\n const healthMonitor = new TransferUploaderHealthMonitor(new WebOnlineChecker(envValues.apiBaseUrl), eventsEngine);\r\n\r\n const apiClient = new WebApiClient(envValues.apiBaseUrl, envValues.source, envValues.sourceDetails, config.apiRequestTotalTimeoutInMs, config.apiRetryLimit);\r\n\r\n if (config.logintoken)\r\n apiClient.setLoginToken(config.logintoken);\r\n\r\n fixTransferInfo(transferInfo);\r\n\r\n const transfer = new TransferUpload(chunkStreamProviderFactory, apiClient, fileServerClientFactory, eventsEngine, transferInfo, uploadConfig, optimizer, cryptography);\r\n\r\n super(transfer, transferInfo.files, config, envValues, logger, healthMonitor, trackingId);\r\n }\r\n}"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileServerDownloadClient.js","sourceRoot":"","sources":["../../../../src/downloader/api/fileServerDownloadClient.ts"],"names":[],"mappings":"","sourcesContent":["import type GetCompressedFileMetadataResponse from \"../../utils/api/dtos/getCompressedFileMetadataResponse.js\";\nimport type ChunkProgressEvent from \"../../utils/events/chunkProgressEvent.js\";\nimport type ChunkStreamProvider from \"../../utils/fileSystem/chunkStreamProvider.js\";\nimport type { ChunkStreamProviderEncryptionData } from \"../../utils/fileSystem/chunkStreamProvider.js\";\n\n// This should be used as a transient object - a new instance for every chunk\ninterface FileServerDownloadClient {\n download(chunkStreamProvider: ChunkStreamProvider, encryptionData?: ChunkStreamProviderEncryptionData): Promise<void>\n release(): void\n getMd5Checksum(): Promise<string>\n addEventListener(eventName: `progress`, handler: (event: ChunkProgressEvent) => void): void\n removeEventListener(eventName: `progress`, handler: (event: ChunkProgressEvent) => void): void\n getCompressedFileMetadata(): Promise<GetCompressedFileMetadataResponse>\n}\n\nexport default FileServerDownloadClient;"]}
|
|
1
|
+
{"version":3,"file":"fileServerDownloadClient.js","sourceRoot":"","sources":["../../../../src/downloader/api/fileServerDownloadClient.ts"],"names":[],"mappings":"","sourcesContent":["import type GetCompressedFileMetadataResponse from \"../../utils/api/dtos/getCompressedFileMetadataResponse.js\";\r\nimport type ChunkProgressEvent from \"../../utils/events/chunkProgressEvent.js\";\r\nimport type ChunkStreamProvider from \"../../utils/fileSystem/chunkStreamProvider.js\";\r\nimport type { ChunkStreamProviderEncryptionData } from \"../../utils/fileSystem/chunkStreamProvider.js\";\r\n\r\n// This should be used as a transient object - a new instance for every chunk\r\ninterface FileServerDownloadClient {\r\n download(chunkStreamProvider: ChunkStreamProvider, encryptionData?: ChunkStreamProviderEncryptionData): Promise<void>\r\n release(): void\r\n getMd5Checksum(): Promise<string>\r\n addEventListener(eventName: `progress`, handler: (event: ChunkProgressEvent) => void): void\r\n removeEventListener(eventName: `progress`, handler: (event: ChunkProgressEvent) => void): void\r\n getCompressedFileMetadata(): Promise<GetCompressedFileMetadataResponse>\r\n}\r\n\r\nexport default FileServerDownloadClient;"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodeFileServerDownloadClient.js","sourceRoot":"","sources":["../../../../../src/downloader/api/node/nodeFileServerDownloadClient.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,EAAE,EAA8B,OAAO,IAAI,UAAU,EA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AC,SAAS;YACvB,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC;QAEpD,OAAO,GAAG,CAAC,MAAM,CAAC;YACd,SAAS,EAAE,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,YAAY,CAAC;YACpD,OAAO;YACP,KAAK,EAAE;gBACH,GAAG,yBAAyB;aAC/B;SACJ,CAAC,CAAC;IACP,CAAC;CACJ","sourcesContent":["import got, { Got, Headers as GotHeaders, Options as GotOptions, Request as GotRequest } from \"got\";\nimport { pipeline } from \"stream/promises\";\n\nimport type DownloadOptions from \"../../downloadOptions.js\";\nimport type ChunkStreamProvider from \"../../../utils/fileSystem/chunkStreamProvider.js\";\nimport { type BaseResponse, isBaseResponse } from \"../../../utils/api/dtos/baseResponse.js\";\nimport type GetRangehashResponse from \"../../../utils/api/dtos/getRangehashResponse.js\";\nimport type GetCompressedFileMetadataResponse from \"../../../utils/api/dtos/getCompressedFileMetadataResponse.js\";\nimport type FileServerDownloadClient from \"../fileServerDownloadClient.js\";\nimport NodeFileServerClientBase from \"../../../utils/api/node/nodeFileserverClientBase.js\";\nimport UrlUtil from \"../../../utils/api/urlUtil.js\";\nimport { retryEconnresetWorkaround } from \"../../../utils/api/node/gotWorkarounds.js\";\n\nexport default class NodeFileServerDownloadClient extends NodeFileServerClientBase implements FileServerDownloadClient {\n #downloadUrl: string;\n #start: number | null;\n #end: number | null;\n #options: DownloadOptions;\n #fileName: string;\n #transferId: string;\n #fileserverClient: Got;\n #downloadStream: GotRequest | null = null;\n #downloadIdleTimeoutInMs: number;\n\n constructor(downloadUrl: string, start: number | null, end: number | null, transferId: string, fileName: string, options: DownloadOptions, downloadIdleTimeoutInMs: number) {\n super();\n\n this.#downloadUrl = downloadUrl;\n this.#start = start;\n this.#end = end;\n this.#options = options;\n this.#transferId = transferId;\n this.#fileName = fileName;\n this.#fileserverClient = this.#createBaseGotInstance();\n this.#downloadIdleTimeoutInMs = downloadIdleTimeoutInMs;\n }\n\n async download(chunkStreamProvider: ChunkStreamProvider): Promise<void> {\n this.#throwIfRunning();\n\n const downloadRequest = this.#createGotChunkDownloadOptions();\n this.#downloadStream = got.stream(this.#downloadUrl, { ...downloadRequest });\n const { fileStream, decipherStream } = await chunkStreamProvider.getChunkWriteStream();\n\n const progressHandler = this.getDataTransferProgressHandler();\n this.#downloadStream.on(`downloadProgress`, progressHandler);\n\n if (decipherStream) {\n return await pipeline(\n this.#downloadStream,\n decipherStream as unknown as NodeJS.ReadWriteStream,\n fileStream,\n );\n }\n\n return pipeline(\n this.#downloadStream,\n fileStream,\n );\n }\n\n release(): void {\n this.#downloadStream?.destroy();\n this.#downloadStream = null;\n }\n\n async getMd5Checksum(): Promise<string> {\n if (this.#start === null || this.#end === null)\n throw new Error(`MD5 checksum cannot be calculated if the start or end is not known --> ${this.#downloadUrl}:${this.#start}:${this.#end}`);\n\n const rangeHashOptions = this.#crateGotRangeHashOptions();\n const md5response = await this.#fileserverClient(`GetRangehash.ashx`, rangeHashOptions).json<GetRangehashResponse>();\n\n this.#throwIfResponseNotOk(md5response);\n\n if (!md5response.hash)\n throw new Error(`Range hash is empty --> ${this.#downloadUrl}:${this.#start}:${this.#end}`);\n\n return md5response.hash;\n }\n\n async getCompressedFileMetadata(): Promise<GetCompressedFileMetadataResponse> {\n this.#throwIfRunning();\n\n const metadataResponse = await got.head(this.#downloadUrl);\n\n if (metadataResponse.statusCode !== 200)\n throw new Error(`HTTP ${metadataResponse.statusCode}`);\n\n const disposition = metadataResponse.headers[`content-disposition`];\n let fileName = ``;\n if (disposition && disposition.indexOf(`attachment;`) === 0) {\n const filenameRegex = /filename\\*?=['\"]?(?:UTF-\\d['\"]*)?([^;\\r\\n\"']*)['\"]?;?/;\n const matches = filenameRegex.exec(disposition);\n if (matches && matches.length > 1 && matches[1])\n fileName = matches[1];\n }\n return {\n fileSize: parseInt(metadataResponse.headers[`content-length`]!, 10),\n fileName,\n };\n }\n\n #throwIfRunning() {\n if (this.#downloadStream)\n throw new Error(`Attempted to run a chunk download while it is already running`);\n }\n\n #throwIfResponseNotOk(response: BaseResponse<unknown>) {\n if (!isBaseResponse(response))\n throw new Error(`FS response is not a valid base response object --> ${this.#downloadUrl}:${this.#start}:${this.#end}`);\n\n if (response.responsestatus !== `OK`)\n throw new Error(`${response.responsestatus}: ${response.errormessage}`);\n }\n\n #crateGotRangeHashOptions() {\n return {\n searchParams: {\n transferid: this.#transferId,\n thefilename: this.#fileName,\n position: this.#start!,\n length: 1 + this.#end! - this.#start!,\n },\n retry: {\n limit: 5,\n backoffLimit: 10000,\n },\n };\n }\n\n #createGotChunkDownloadOptions(): GotOptions {\n const query = UrlUtil.getQueryStringFromUrl(this.#downloadUrl);\n const headers: GotHeaders = {};\n\n if (this.#options.userAgent)\n headers[`User-Agent`] = this.#options.userAgent;\n\n if (this.#start !== null && this.#end !== null)\n headers.Range = `bytes=${this.#start}-${this.#end}`;\n\n return new GotOptions({\n headers,\n searchParams: {\n ...query, // need to unfold original query - when using url with query included got will replace the query with provided searchParams option\n skipreg: true, // make sure to implement download registrations - figure out a good way for file-by-file scenarios (current desktop v2 is a bit verbose...)\n skipcheck: true,\n },\n timeout: {\n socket: this.#downloadIdleTimeoutInMs > 0 ? this.#downloadIdleTimeoutInMs : undefined,\n },\n });\n }\n\n #createBaseGotInstance(): Got {\n const headers: GotHeaders = {};\n\n if (this.#options.userAgent)\n headers[`User-Agent`] = this.#options.userAgent;\n\n return got.extend({\n prefixUrl: UrlUtil.getHostFromUrl(this.#downloadUrl),\n headers,\n retry: {\n ...retryEconnresetWorkaround,\n },\n });\n }\n}"]}
|
|
1
|
+
{"version":3,"file":"nodeFileServerDownloadClient.js","sourceRoot":"","sources":["../../../../../src/downloader/api/node/nodeFileServerDownloadClient.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,EAAE,EAA8B,OAAO,IAAI,UAAU,EAAyB,MAAM,KAAK,CAAC;AACpG,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAA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CAAC,SAAS,CAAC;QAEpD,OAAO,GAAG,CAAC,MAAM,CAAC;YACd,SAAS,EAAE,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,YAAY,CAAC;YACpD,OAAO;YACP,KAAK,EAAE;gBACH,GAAG,yBAAyB;aAC/B;SACJ,CAAC,CAAC;IACP,CAAC;CACJ","sourcesContent":["import got, { Got, Headers as GotHeaders, Options as GotOptions, Request as GotRequest } from \"got\";\r\nimport { pipeline } from \"stream/promises\";\r\n\r\nimport type DownloadOptions from \"../../downloadOptions.js\";\r\nimport type ChunkStreamProvider from \"../../../utils/fileSystem/chunkStreamProvider.js\";\r\nimport { type BaseResponse, isBaseResponse } from \"../../../utils/api/dtos/baseResponse.js\";\r\nimport type GetRangehashResponse from \"../../../utils/api/dtos/getRangehashResponse.js\";\r\nimport type GetCompressedFileMetadataResponse from \"../../../utils/api/dtos/getCompressedFileMetadataResponse.js\";\r\nimport type FileServerDownloadClient from \"../fileServerDownloadClient.js\";\r\nimport NodeFileServerClientBase from \"../../../utils/api/node/nodeFileserverClientBase.js\";\r\nimport UrlUtil from \"../../../utils/api/urlUtil.js\";\r\nimport { retryEconnresetWorkaround } from \"../../../utils/api/node/gotWorkarounds.js\";\r\n\r\nexport default class NodeFileServerDownloadClient extends NodeFileServerClientBase implements FileServerDownloadClient {\r\n #downloadUrl: string;\r\n #start: number | null;\r\n #end: number | null;\r\n #options: DownloadOptions;\r\n #fileName: string;\r\n #transferId: string;\r\n #fileserverClient: Got;\r\n #downloadStream: GotRequest | null = null;\r\n #downloadIdleTimeoutInMs: number;\r\n\r\n constructor(downloadUrl: string, start: number | null, end: number | null, transferId: string, fileName: string, options: DownloadOptions, downloadIdleTimeoutInMs: number) {\r\n super();\r\n\r\n this.#downloadUrl = downloadUrl;\r\n this.#start = start;\r\n this.#end = end;\r\n this.#options = options;\r\n this.#transferId = transferId;\r\n this.#fileName = fileName;\r\n this.#fileserverClient = this.#createBaseGotInstance();\r\n this.#downloadIdleTimeoutInMs = downloadIdleTimeoutInMs;\r\n }\r\n\r\n async download(chunkStreamProvider: ChunkStreamProvider): Promise<void> {\r\n this.#throwIfRunning();\r\n\r\n const downloadRequest = this.#createGotChunkDownloadOptions();\r\n this.#downloadStream = got.stream(this.#downloadUrl, { ...downloadRequest });\r\n const { fileStream, decipherStream } = await chunkStreamProvider.getChunkWriteStream();\r\n\r\n const progressHandler = this.getDataTransferProgressHandler();\r\n this.#downloadStream.on(`downloadProgress`, progressHandler);\r\n\r\n if (decipherStream) {\r\n return await pipeline(\r\n this.#downloadStream,\r\n decipherStream as unknown as NodeJS.ReadWriteStream,\r\n fileStream,\r\n );\r\n }\r\n\r\n return pipeline(\r\n this.#downloadStream,\r\n fileStream,\r\n );\r\n }\r\n\r\n release(): void {\r\n this.#downloadStream?.destroy();\r\n this.#downloadStream = null;\r\n }\r\n\r\n async getMd5Checksum(): Promise<string> {\r\n if (this.#start === null || this.#end === null)\r\n throw new Error(`MD5 checksum cannot be calculated if the start or end is not known --> ${this.#downloadUrl}:${this.#start}:${this.#end}`);\r\n\r\n const rangeHashOptions = this.#crateGotRangeHashOptions();\r\n const md5response = await this.#fileserverClient(`GetRangehash.ashx`, rangeHashOptions).json<GetRangehashResponse>();\r\n\r\n this.#throwIfResponseNotOk(md5response);\r\n\r\n if (!md5response.hash)\r\n throw new Error(`Range hash is empty --> ${this.#downloadUrl}:${this.#start}:${this.#end}`);\r\n\r\n return md5response.hash;\r\n }\r\n\r\n async getCompressedFileMetadata(): Promise<GetCompressedFileMetadataResponse> {\r\n this.#throwIfRunning();\r\n\r\n const metadataResponse = await got.head(this.#downloadUrl);\r\n\r\n if (metadataResponse.statusCode !== 200)\r\n throw new Error(`HTTP ${metadataResponse.statusCode}`);\r\n\r\n const disposition = metadataResponse.headers[`content-disposition`];\r\n let fileName = ``;\r\n if (disposition && disposition.indexOf(`attachment;`) === 0) {\r\n const filenameRegex = /filename\\*?=['\"]?(?:UTF-\\d['\"]*)?([^;\\r\\n\"']*)['\"]?;?/;\r\n const matches = filenameRegex.exec(disposition);\r\n if (matches && matches.length > 1 && matches[1])\r\n fileName = matches[1];\r\n }\r\n return {\r\n fileSize: parseInt(metadataResponse.headers[`content-length`]!, 10),\r\n fileName,\r\n };\r\n }\r\n\r\n #throwIfRunning() {\r\n if (this.#downloadStream)\r\n throw new Error(`Attempted to run a chunk download while it is already running`);\r\n }\r\n\r\n #throwIfResponseNotOk(response: BaseResponse<unknown>) {\r\n if (!isBaseResponse(response))\r\n throw new Error(`FS response is not a valid base response object --> ${this.#downloadUrl}:${this.#start}:${this.#end}`);\r\n\r\n if (response.responsestatus !== `OK`)\r\n throw new Error(`${response.responsestatus}: ${response.errormessage}`);\r\n }\r\n\r\n #crateGotRangeHashOptions() {\r\n return {\r\n searchParams: {\r\n transferid: this.#transferId,\r\n thefilename: this.#fileName,\r\n position: this.#start!,\r\n length: 1 + this.#end! - this.#start!,\r\n },\r\n retry: {\r\n limit: 5,\r\n backoffLimit: 10000,\r\n },\r\n };\r\n }\r\n\r\n #createGotChunkDownloadOptions(): GotOptions {\r\n const query = UrlUtil.getQueryStringFromUrl(this.#downloadUrl);\r\n const headers: GotHeaders = {};\r\n\r\n if (this.#options.userAgent)\r\n headers[`User-Agent`] = this.#options.userAgent;\r\n\r\n if (this.#start !== null && this.#end !== null)\r\n headers.Range = `bytes=${this.#start}-${this.#end}`;\r\n\r\n return new GotOptions({\r\n headers,\r\n searchParams: {\r\n ...query, // need to unfold original query - when using url with query included got will replace the query with provided searchParams option\r\n skipreg: true, // make sure to implement download registrations - figure out a good way for file-by-file scenarios (current desktop v2 is a bit verbose...)\r\n skipcheck: true,\r\n },\r\n timeout: {\r\n socket: this.#downloadIdleTimeoutInMs > 0 ? this.#downloadIdleTimeoutInMs : undefined,\r\n },\r\n });\r\n }\r\n\r\n #createBaseGotInstance(): Got {\r\n const headers: GotHeaders = {};\r\n\r\n if (this.#options.userAgent)\r\n headers[`User-Agent`] = this.#options.userAgent;\r\n\r\n return got.extend({\r\n prefixUrl: UrlUtil.getHostFromUrl(this.#downloadUrl),\r\n headers,\r\n retry: {\r\n ...retryEconnresetWorkaround,\r\n },\r\n });\r\n }\r\n}"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunkDownloader.d.ts","sourceRoot":"","sources":["../../../src/downloader/chunkDownloader.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,qBAAqB,MAAM,iCAAiC,CAAC;AACzE,OAAO,KAAK,gBAAgB,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,aAAa,MAAM,mCAAmC,CAAC;AACnE,OAAO,KAAK,uBAAuB,MAAM,yCAAyC,CAAC;AACnF,OAAO,KAAK,0BAA0B,MAAM,mDAAmD,CAAC;AAChG,OAAO,KAAK,YAAY,MAAM,iCAAiC,CAAC;AAIhE,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,4CAA4C,CAAC;AAEpG,MAAM,CAAC,OAAO,OAAO,eAAe;;
|
|
1
|
+
{"version":3,"file":"chunkDownloader.d.ts","sourceRoot":"","sources":["../../../src/downloader/chunkDownloader.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,qBAAqB,MAAM,iCAAiC,CAAC;AACzE,OAAO,KAAK,gBAAgB,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,aAAa,MAAM,mCAAmC,CAAC;AACnE,OAAO,KAAK,uBAAuB,MAAM,yCAAyC,CAAC;AACnF,OAAO,KAAK,0BAA0B,MAAM,mDAAmD,CAAC;AAChG,OAAO,KAAK,YAAY,MAAM,iCAAiC,CAAC;AAIhE,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,4CAA4C,CAAC;AAEpG,MAAM,CAAC,OAAO,OAAO,eAAe;;gBAiB5B,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,gBAAgB,EACtB,KAAK,EAAE,qBAAqB,EAC5B,aAAa,EAAE,aAAa,EAC5B,OAAO,EAAE,eAAe,EACxB,uBAAuB,EAAE,uBAAuB,EAChD,0BAA0B,EAAE,0BAA0B,CAAC,MAAM,CAAC,EAC9D,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,cAAc,EACtB,cAAc,CAAC,EAAE,iCAAiC;IAehD,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CA8QlC"}
|
|
@@ -21,6 +21,7 @@ export default class ChunkDownloader {
|
|
|
21
21
|
#encryptionData;
|
|
22
22
|
#bytesTransferred = 0;
|
|
23
23
|
#running = false;
|
|
24
|
+
#consecutiveNetworkErrors = 0;
|
|
24
25
|
constructor(transferId, file, chunk, downloadState, options, fileServerClientFactory, chunkStreamProviderFactory, eventsEngine, logger, encryptionData) {
|
|
25
26
|
this.#transferId = transferId;
|
|
26
27
|
this.#options = options;
|
|
@@ -48,12 +49,18 @@ export default class ChunkDownloader {
|
|
|
48
49
|
try {
|
|
49
50
|
this.#downloadState.chunkDownloadStarted(this.#file, this.#chunk);
|
|
50
51
|
this.#addEventListeners();
|
|
51
|
-
|
|
52
|
+
let fileserverMd5Promise = this.#options.checkChunksMd5
|
|
52
53
|
? this.#chunkDownloadClient.getMd5Checksum()
|
|
53
54
|
: null;
|
|
54
55
|
while (writtenCorrectly === false && this.#canRetry(lastError, writeErrors, networkErrors, apiReturnedNotOkResponseStatus)) {
|
|
55
56
|
attempts += 1;
|
|
56
57
|
this.#bytesTransferred = 0;
|
|
58
|
+
if (this.#isDownloadClientRecreateNeeded()) {
|
|
59
|
+
this.#recreateDownloadClient();
|
|
60
|
+
fileserverMd5Promise = this.#options.checkChunksMd5
|
|
61
|
+
? this.#chunkDownloadClient.getMd5Checksum()
|
|
62
|
+
: null;
|
|
63
|
+
}
|
|
57
64
|
const chunkWriter = this.#chunkStreamProviderFactory.provide(this.#file.temporaryDownloadPath, this.#chunk.start ?? 0, this.#chunk.chunkSize, this.#encryptionData);
|
|
58
65
|
try {
|
|
59
66
|
await this.#chunkDownloadClient.download(chunkWriter, this.#encryptionData);
|
|
@@ -62,6 +69,7 @@ export default class ChunkDownloader {
|
|
|
62
69
|
this.#downloadState.possibleSupersizedFile(this.#file);
|
|
63
70
|
throw new DownloadError(`Download request returned incorrect amount of data. Expected=${this.#chunk.chunkSize} Received=${this.#bytesTransferred}`, undefined, DownloadErrorCode.FileserverResponseWrongSize);
|
|
64
71
|
}
|
|
72
|
+
this.#consecutiveNetworkErrors = 0;
|
|
65
73
|
networkErrors = 0;
|
|
66
74
|
this.#downloadState.networkOk();
|
|
67
75
|
if (this.#downloadState.status !== TransferStatus.Aborting) {
|
|
@@ -90,6 +98,7 @@ export default class ChunkDownloader {
|
|
|
90
98
|
if (this.#isApiNotOkResponseStatusResponse(lastError))
|
|
91
99
|
apiReturnedNotOkResponseStatus = true;
|
|
92
100
|
else {
|
|
101
|
+
this.#consecutiveNetworkErrors += 1;
|
|
93
102
|
networkErrors += 1;
|
|
94
103
|
this.#downloadState.networkFailure();
|
|
95
104
|
}
|
|
@@ -136,6 +145,14 @@ export default class ChunkDownloader {
|
|
|
136
145
|
}
|
|
137
146
|
this.#running = false;
|
|
138
147
|
}
|
|
148
|
+
#isDownloadClientRecreateNeeded() {
|
|
149
|
+
return this.#consecutiveNetworkErrors > 0 && this.#consecutiveNetworkErrors % this.#options.fileserverOfflineAfterConsecutiveAttempts === 0;
|
|
150
|
+
}
|
|
151
|
+
#recreateDownloadClient() {
|
|
152
|
+
this.#chunkDownloadClient.removeEventListener(`progress`, this.#onProgress);
|
|
153
|
+
this.#chunkDownloadClient = this.#fileServerClientFactory.createFileServerTcpDownloadClient(this.#file.url, this.#chunk.start, this.#chunk.end, this.#transferId, this.#file.name, this.#options);
|
|
154
|
+
this.#chunkDownloadClient.addEventListener(`progress`, this.#onProgress);
|
|
155
|
+
}
|
|
139
156
|
#throwIfRunning() {
|
|
140
157
|
if (this.#running)
|
|
141
158
|
throw new DownloadError(`This instance of chunk downloader is already in use. Please create a new one.`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunkDownloader.js","sourceRoot":"","sources":["../../../src/downloader/chunkDownloader.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,KAAK,CAAC;AACnC,OAAO,KAAK,MAAM,iBAAiB,CAAC;AAEpC,OAAO,cAAc,MAAM,kCAAkC,CAAC;AAC9D,OAAO,aAAa,MAAM,yBAAyB,CAAC;AACpD,OAAO,qBAAqB,MAAM,yBAAyB,CAAC;AAC5D,OAAO,iBAAiB,MAAM,6BAA6B,CAAC;AAC5D,OAAO,yBAAyB,MAAM,+CAA+C,CAAC;AACtF,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAenE,MAAM,CAAC,OAAO,OAAO,eAAe;IAChC,OAAO,CAAiB;IACxB,WAAW,CAAS;IACpB,MAAM,CAAwB;IAC9B,KAAK,CAAmB;IACxB,cAAc,CAAgB;IAC9B,QAAQ,CAAkB;IAC1B,wBAAwB,CAA0B;IAClD,2BAA2B,CAAqC;IAChE,aAAa,CAAe;IAC5B,oBAAoB,CAA2B;IAC/C,eAAe,CAAqC;IACpD,iBAAiB,GAAG,CAAC,CAAC;IACtB,QAAQ,GAAG,KAAK,CAAC;IAEjB,YACI,UAAkB,EAClB,IAAsB,EACtB,KAA4B,EAC5B,aAA4B,EAC5B,OAAwB,EACxB,uBAAgD,EAChD,0BAA8D,EAC9D,YAA0B,EAC1B,MAAsB,EACtB,cAAkD;QAElD,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CA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;QAC9B,IAAI,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC;YAC5B,OAAO,iBAAiB,CAAC,QAAQ,CAAC;QAEtC,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,gBAAgB,CAAC,KAAc;QAC3B,IAAI,CAAC,KAAK;YACN,OAAO,KAAK,CAAC;QAEjB,IAAI,OAAO,GAAG,KAAyE,CAAC;QACxF,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,IAAI,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC;YAChD,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ;gBACzB,OAAO,IAAI,CAAC;YAEhB,IAAI,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;gBACzE,OAAO,IAAI,CAAC;YAEhB,OAAO,GAAG,OAAO,CAAC,KAAyE,CAAC;QAChG,CAAC;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ","sourcesContent":["/* eslint-disable no-await-in-loop */\nimport { RequestError } from \"got\";\nimport sleep from \"abortable-sleep\";\n\nimport TransferStatus from \"../utils/types/transferStatus.js\";\nimport DownloadError from \"./dtos/downloadError.js\";\nimport TransferDownloadEvent from \"./dtos/downloadEvent.js\";\nimport DownloadErrorCode from \"./dtos/downloadErrorCode.js\";\nimport DownloadFileChunkProgress from \"./downloadStatus/downloadFileChunkProgress.js\";\nimport { isBaseResponse } from \"../utils/api/dtos/baseResponse.js\";\n\nimport type DownloadFileChunkInfo from \"./dtos/downloadFileChunkInfo.js\";\nimport type DownloadFileInfo from \"./dtos/downloadFileInfo.js\";\nimport type DownloadOptions from \"./downloadOptions.js\";\nimport type DownloadState from \"./downloadStatus/downloadState.js\";\nimport type FileServerClientFactory from \"../utils/api/fileServerClientFactory.js\";\nimport type ChunkStreamProviderFactory from \"../utils/fileSystem/chunkStreamProviderFactory.js\";\nimport type EventsEngine from \"../utils/events/eventsEngine.js\";\nimport type FileServerDownloadClient from \"./api/fileServerDownloadClient.js\";\nimport type ChunkProgressEvent from \"../utils/events/chunkProgressEvent.js\";\nimport type FileDownloadFailedEventArgs from \"./eventArgs/fileDownloadFailedEventArgs.js\";\nimport type DownloadLogger from \"./downloadLogger.js\";\nimport type { ChunkStreamProviderEncryptionData } from \"../utils/fileSystem/chunkStreamProvider.js\";\n\nexport default class ChunkDownloader {\n #logger: DownloadLogger;\n #transferId: string;\n #chunk: DownloadFileChunkInfo;\n #file: DownloadFileInfo;\n #downloadState: DownloadState;\n #options: DownloadOptions;\n #fileServerClientFactory: FileServerClientFactory;\n #chunkStreamProviderFactory: ChunkStreamProviderFactory<string>;\n #eventsEngine: EventsEngine;\n #chunkDownloadClient: FileServerDownloadClient;\n #encryptionData?: ChunkStreamProviderEncryptionData;\n #bytesTransferred = 0;\n #running = false;\n\n constructor(\n transferId: string,\n file: DownloadFileInfo,\n chunk: DownloadFileChunkInfo,\n downloadState: DownloadState,\n options: DownloadOptions,\n fileServerClientFactory: FileServerClientFactory,\n chunkStreamProviderFactory: ChunkStreamProviderFactory<string>,\n eventsEngine: EventsEngine,\n logger: DownloadLogger,\n encryptionData?: ChunkStreamProviderEncryptionData,\n ) {\n this.#transferId = transferId;\n this.#options = options;\n this.#file = file;\n this.#chunk = chunk;\n this.#downloadState = downloadState;\n this.#fileServerClientFactory = fileServerClientFactory;\n this.#chunkStreamProviderFactory = chunkStreamProviderFactory;\n this.#eventsEngine = eventsEngine;\n this.#chunkDownloadClient = this.#fileServerClientFactory.createFileServerTcpDownloadClient(this.#file.url, this.#chunk.start, this.#chunk.end, this.#transferId, this.#file.name, this.#options);\n this.#logger = logger;\n this.#encryptionData = encryptionData;\n }\n\n async download(): Promise<void> {\n this.#throwIfRunning();\n this.#throwIfMissingDownloadPath();\n\n this.#running = true;\n\n let writtenCorrectly = false;\n let attempts = 0;\n let writeErrors = 0;\n let networkErrors = 0;\n let apiReturnedNotOkResponseStatus: boolean = false;\n let lastError: Error | null = null;\n let unhandledError: Error | null = null;\n\n try {\n this.#downloadState.chunkDownloadStarted(this.#file, this.#chunk);\n\n this.#addEventListeners();\n\n const fileserverMd5Promise: Promise<string> | null = this.#options.checkChunksMd5\n ? this.#chunkDownloadClient.getMd5Checksum()\n : null;\n\n while (writtenCorrectly === false && this.#canRetry(lastError as Error, writeErrors, networkErrors, apiReturnedNotOkResponseStatus)) {\n attempts += 1;\n\n this.#bytesTransferred = 0;\n\n const chunkWriter = this.#chunkStreamProviderFactory.provide(this.#file.temporaryDownloadPath!, this.#chunk.start ?? 0, this.#chunk.chunkSize, this.#encryptionData);\n\n try {\n await this.#chunkDownloadClient.download(chunkWriter, this.#encryptionData);\n\n if (this.#bytesTransferred !== this.#chunk.chunkSize) {\n if (this.#bytesTransferred > this.#chunk.chunkSize)\n this.#downloadState.possibleSupersizedFile(this.#file);\n\n throw new DownloadError(`Download request returned incorrect amount of data. Expected=${this.#chunk.chunkSize} Received=${this.#bytesTransferred}`, undefined, DownloadErrorCode.FileserverResponseWrongSize);\n }\n\n networkErrors = 0;\n this.#downloadState.networkOk();\n\n if (this.#downloadState.status !== TransferStatus.Aborting) {\n if (fileserverMd5Promise !== null) {\n const remoteMd5 = await fileserverMd5Promise;\n const localMd5 = await chunkWriter.getMd5Checksum(`hex`);\n if (remoteMd5.toLowerCase() === localMd5.toLowerCase())\n writtenCorrectly = true;\n else {\n writeErrors += 1;\n lastError = new DownloadError(`MD5 checksum incorrect: fileserver=${remoteMd5} local=${localMd5}`);\n }\n }\n else\n writtenCorrectly = true;\n }\n }\n catch (error) {\n // note: getting an exception here may be caused by abort or stop operations\n // both operations immediately interrupt HTTP download request by calling chunkDownloadClient.release()\n if (this.#downloadState.pauseImmediately || this.#downloadState.status === TransferStatus.Aborting)\n lastError = null;\n else {\n lastError = error as Error;\n\n if (lastError instanceof RequestError) {\n if (this.#isApiNotOkResponseStatusResponse(lastError))\n apiReturnedNotOkResponseStatus = true;\n else {\n networkErrors += 1;\n this.#downloadState.networkFailure();\n }\n }\n else\n writeErrors += 1;\n\n this.#logger.logError(lastError, `[CHUNK_DOWNLOADER_ERROR] Error in retry loop when downloading chunk attempt=${attempts} writeerrors=${writeErrors} networkerrors=${networkErrors}`, this.#errorInfoDump());\n }\n }\n finally {\n await chunkWriter?.release();\n this.#chunkDownloadClient?.release();\n\n let sleepTime = 0;\n if (this.#downloadState.isThereNetworkProblem)\n sleepTime = this.#options.fileserverOfflineCheckIntervalMillis;\n else if (networkErrors > 0) {\n const pow = Math.min(networkErrors, this.#options.fileserverOfflineAfterConsecutiveAttempts);\n sleepTime = this.#options.fileserverOfflineCheckIntervalMillis * (2 ** (pow - this.#options.fileserverOfflineAfterConsecutiveAttempts));\n }\n\n if (sleepTime > 0)\n await sleep(sleepTime);\n }\n }\n }\n catch (error) {\n unhandledError = error as Error;\n this.#logger.logError(unhandledError, `[CHUNK_DOWNLOADER_ERROR] Unhandled error when downloading chunk`, this.#errorInfoDump());\n }\n finally {\n this.#removeEventListeners();\n }\n\n if (writtenCorrectly)\n this.#downloadState.chunkDownloadCompleted(this.#file, this.#chunk);\n else {\n let downloadError: DownloadError | null = null;\n const failureCode = this.#toFailureCode(unhandledError ?? lastError);\n\n if (unhandledError)\n downloadError = new DownloadError(`Unhandled chunk download error for file ${this.#file.url} chunk ${this.#chunk.chunkNumber}`, { cause: unhandledError as Error }, failureCode);\n else if (lastError)\n downloadError = new DownloadError(`Chunk download failed for file ${this.#file.url} chunk ${this.#chunk.chunkNumber} attempt ${attempts}.`, { cause: lastError as Error }, failureCode);\n\n if (downloadError !== null) {\n this.#downloadState.chunkDownloadFailed(\n this.#file,\n this.#chunk,\n downloadError,\n );\n }\n }\n\n this.#running = false;\n }\n\n #throwIfRunning() {\n if (this.#running)\n throw new DownloadError(`This instance of chunk downloader is already in use. Please create a new one.`);\n }\n\n #throwIfMissingDownloadPath() {\n if (!this.#file.temporaryDownloadPath)\n throw new DownloadError(`Download file ${this.#file.externalId}/${this.#file.name}/${this.#file.downloadPath} is missing the required \"temporaryDownloadPath\"`);\n }\n\n #addEventListeners() {\n this.#eventsEngine.addEventListener(TransferDownloadEvent.Aborting, this.#onAbortRequested);\n this.#eventsEngine.addEventListener(TransferDownloadEvent.Pausing, this.#onPauseRequested);\n this.#eventsEngine.addEventListener(TransferDownloadEvent.FileDownloadFailed, this.#onFileFailed);\n this.#chunkDownloadClient.addEventListener(`progress`, this.#onProgress);\n }\n\n #removeEventListeners() {\n this.#eventsEngine.removeEventListener(TransferDownloadEvent.Aborting, this.#onAbortRequested);\n this.#eventsEngine.removeEventListener(TransferDownloadEvent.Pausing, this.#onPauseRequested);\n this.#eventsEngine.removeEventListener(TransferDownloadEvent.FileDownloadFailed, this.#onFileFailed);\n this.#chunkDownloadClient.removeEventListener(`progress`, this.#onProgress);\n }\n\n #canRetry(error: Error | null, writeErrors: number, networkErrors: number, apiReturnedNotOkResponseStatus: boolean) {\n if (this.#downloadState.status === TransferStatus.Aborting || this.#downloadState.status === TransferStatus.Pausing)\n return false;\n\n if (this.#file.isFailed)\n return false;\n\n if (apiReturnedNotOkResponseStatus)\n return false;\n\n if (this.#isDiskFullError(error))\n return false;\n\n if (error && error instanceof RequestError)\n return this.#options.fileserverAttemptLimit <= 0 || networkErrors < this.#options.fileserverAttemptLimit!;\n\n return this.#options.maxWriteAttempts! < 0 || writeErrors < this.#options.maxWriteAttempts!;\n }\n\n #isApiNotOkResponseStatusResponse(error: RequestError): boolean {\n try {\n if (typeof error.response?.body !== `string`)\n return false;\n\n const response = JSON.parse(error.response?.body);\n\n if (!isBaseResponse(response))\n return false;\n\n return response.responsestatus !== `OK`;\n }\n catch {\n return false;\n }\n }\n\n /**\n * This method aborts pending download - it can be achieved only by destroying the download client\n * (which in turn destroys the underlying download HTTP request). This operation\n * will throw an expected exception inside download method (in main while loop). See {@link download} method.\n */\n #interruptDownload = () => {\n this.#chunkDownloadClient?.release();\n };\n\n #onAbortRequested = () => {\n this.#interruptDownload();\n };\n\n #onPauseRequested = () => {\n if (this.#downloadState.pauseImmediately)\n this.#interruptDownload();\n };\n\n #onFileFailed = (args: FileDownloadFailedEventArgs) => {\n if (this.#file.externalId === args.file.id)\n this.#chunkDownloadClient?.release();\n };\n\n #onProgress = (args: ChunkProgressEvent) => {\n this.#bytesTransferred = args.transferredBytesTotal;\n this.#downloadState.chunkDownloadProgressed(this.#file, this.#chunk, args);\n };\n\n #errorInfoDump() {\n return {\n fileid: this.#file.externalId,\n filename: this.#file.name,\n chunk: DownloadFileChunkProgress.FromChunkInfo(this.#chunk),\n };\n }\n\n #toFailureCode(error: Error | null): DownloadErrorCode | undefined {\n if (this.#isDiskFullError(error))\n return DownloadErrorCode.DiskFull;\n\n return undefined;\n }\n\n #isDiskFullError(error: unknown): boolean {\n if (!error)\n return false;\n\n let current = error as { message?: string, code?: string, cause?: unknown } | undefined;\n for (let depth = 0; depth < 8 && current; depth++) {\n if (current.code === `ENOSPC`)\n return true;\n\n if (typeof current.message === `string` && current.message.includes(`ENOSPC`))\n return true;\n\n current = current.cause as { message?: string, code?: string, cause?: unknown } | undefined;\n }\n\n return false;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"chunkDownloader.js","sourceRoot":"","sources":["../../../src/downloader/chunkDownloader.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,KAAK,CAAC;AACnC,OAAO,KAAK,MAAM,iBAAiB,CAAC;AAEpC,OAAO,cAAc,MAAM,kCAAkC,CAAC;AAC9D,OAAO,aAAa,MAAM,yBAAyB,CAAC;AACpD,OAAO,qBAAqB,MAAM,yBAAyB,CAAC;AAC5D,OAAO,iBAAiB,MAAM,6BAA6B,CAAC;AAC5D,OAAO,yBAAyB,MAAM,+CAA+C,CAAC;AACtF,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAenE,MAAM,CAAC,OAAO,OAAO,eAAe;IAChC,OAAO,CAAiB;IACxB,WAAW,CAAS;IACpB,MA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cAAc,CAAC,uBAAuB,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC/E,CAAC,CAAC;IAEF,cAAc;QACV,OAAO;YACH,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU;YAC7B,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI;YACzB,KAAK,EAAE,yBAAyB,CAAC,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC;SAC9D,CAAC;IACN,CAAC;IAED,cAAc,CAAC,KAAmB;QAC9B,IAAI,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC;YAC5B,OAAO,iBAAiB,CAAC,QAAQ,CAAC;QAEtC,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,gBAAgB,CAAC,KAAc;QAC3B,IAAI,CAAC,KAAK;YACN,OAAO,KAAK,CAAC;QAEjB,IAAI,OAAO,GAAG,KAAyE,CAAC;QACxF,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,IAAI,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC;YAChD,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ;gBACzB,OAAO,IAAI,CAAC;YAEhB,IAAI,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;gBACzE,OAAO,IAAI,CAAC;YAEhB,OAAO,GAAG,OAAO,CAAC,KAAyE,CAAC;QAChG,CAAC;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ","sourcesContent":["/* eslint-disable no-await-in-loop */\r\nimport { RequestError } from \"got\";\r\nimport sleep from \"abortable-sleep\";\r\n\r\nimport TransferStatus from \"../utils/types/transferStatus.js\";\r\nimport DownloadError from \"./dtos/downloadError.js\";\r\nimport TransferDownloadEvent from \"./dtos/downloadEvent.js\";\r\nimport DownloadErrorCode from \"./dtos/downloadErrorCode.js\";\r\nimport DownloadFileChunkProgress from \"./downloadStatus/downloadFileChunkProgress.js\";\r\nimport { isBaseResponse } from \"../utils/api/dtos/baseResponse.js\";\r\n\r\nimport type DownloadFileChunkInfo from \"./dtos/downloadFileChunkInfo.js\";\r\nimport type DownloadFileInfo from \"./dtos/downloadFileInfo.js\";\r\nimport type DownloadOptions from \"./downloadOptions.js\";\r\nimport type DownloadState from \"./downloadStatus/downloadState.js\";\r\nimport type FileServerClientFactory from \"../utils/api/fileServerClientFactory.js\";\r\nimport type ChunkStreamProviderFactory from \"../utils/fileSystem/chunkStreamProviderFactory.js\";\r\nimport type EventsEngine from \"../utils/events/eventsEngine.js\";\r\nimport type FileServerDownloadClient from \"./api/fileServerDownloadClient.js\";\r\nimport type ChunkProgressEvent from \"../utils/events/chunkProgressEvent.js\";\r\nimport type FileDownloadFailedEventArgs from \"./eventArgs/fileDownloadFailedEventArgs.js\";\r\nimport type DownloadLogger from \"./downloadLogger.js\";\r\nimport type { ChunkStreamProviderEncryptionData } from \"../utils/fileSystem/chunkStreamProvider.js\";\r\n\r\nexport default class ChunkDownloader {\r\n #logger: DownloadLogger;\r\n #transferId: string;\r\n #chunk: DownloadFileChunkInfo;\r\n #file: DownloadFileInfo;\r\n #downloadState: DownloadState;\r\n #options: DownloadOptions;\r\n #fileServerClientFactory: FileServerClientFactory;\r\n #chunkStreamProviderFactory: ChunkStreamProviderFactory<string>;\r\n #eventsEngine: EventsEngine;\r\n #chunkDownloadClient: FileServerDownloadClient;\r\n #encryptionData?: ChunkStreamProviderEncryptionData;\r\n #bytesTransferred = 0;\r\n #running = false;\r\n #consecutiveNetworkErrors = 0;\r\n\r\n constructor(\r\n transferId: string,\r\n file: DownloadFileInfo,\r\n chunk: DownloadFileChunkInfo,\r\n downloadState: DownloadState,\r\n options: DownloadOptions,\r\n fileServerClientFactory: FileServerClientFactory,\r\n chunkStreamProviderFactory: ChunkStreamProviderFactory<string>,\r\n eventsEngine: EventsEngine,\r\n logger: DownloadLogger,\r\n encryptionData?: ChunkStreamProviderEncryptionData,\r\n ) {\r\n this.#transferId = transferId;\r\n this.#options = options;\r\n this.#file = file;\r\n this.#chunk = chunk;\r\n this.#downloadState = downloadState;\r\n this.#fileServerClientFactory = fileServerClientFactory;\r\n this.#chunkStreamProviderFactory = chunkStreamProviderFactory;\r\n this.#eventsEngine = eventsEngine;\r\n this.#chunkDownloadClient = this.#fileServerClientFactory.createFileServerTcpDownloadClient(this.#file.url, this.#chunk.start, this.#chunk.end, this.#transferId, this.#file.name, this.#options);\r\n this.#logger = logger;\r\n this.#encryptionData = encryptionData;\r\n }\r\n\r\n async download(): Promise<void> {\r\n this.#throwIfRunning();\r\n this.#throwIfMissingDownloadPath();\r\n\r\n this.#running = true;\r\n\r\n let writtenCorrectly = false;\r\n let attempts = 0;\r\n let writeErrors = 0;\r\n let networkErrors = 0;\r\n let apiReturnedNotOkResponseStatus: boolean = false;\r\n let lastError: Error | null = null;\r\n let unhandledError: Error | null = null;\r\n\r\n try {\r\n this.#downloadState.chunkDownloadStarted(this.#file, this.#chunk);\r\n\r\n this.#addEventListeners();\r\n\r\n let fileserverMd5Promise: Promise<string> | null = this.#options.checkChunksMd5\r\n ? this.#chunkDownloadClient.getMd5Checksum()\r\n : null;\r\n\r\n while (writtenCorrectly === false && this.#canRetry(lastError as Error, writeErrors, networkErrors, apiReturnedNotOkResponseStatus)) {\r\n attempts += 1;\r\n\r\n this.#bytesTransferred = 0;\r\n\r\n if (this.#isDownloadClientRecreateNeeded()) {\r\n this.#recreateDownloadClient();\r\n\r\n fileserverMd5Promise = this.#options.checkChunksMd5\r\n ? this.#chunkDownloadClient.getMd5Checksum()\r\n : null;\r\n }\r\n\r\n const chunkWriter = this.#chunkStreamProviderFactory.provide(this.#file.temporaryDownloadPath!, this.#chunk.start ?? 0, this.#chunk.chunkSize, this.#encryptionData);\r\n\r\n try {\r\n await this.#chunkDownloadClient.download(chunkWriter, this.#encryptionData);\r\n\r\n if (this.#bytesTransferred !== this.#chunk.chunkSize) {\r\n if (this.#bytesTransferred > this.#chunk.chunkSize)\r\n this.#downloadState.possibleSupersizedFile(this.#file);\r\n\r\n throw new DownloadError(`Download request returned incorrect amount of data. Expected=${this.#chunk.chunkSize} Received=${this.#bytesTransferred}`, undefined, DownloadErrorCode.FileserverResponseWrongSize);\r\n }\r\n\r\n this.#consecutiveNetworkErrors = 0;\r\n networkErrors = 0;\r\n this.#downloadState.networkOk();\r\n\r\n if (this.#downloadState.status !== TransferStatus.Aborting) {\r\n if (fileserverMd5Promise !== null) {\r\n const remoteMd5 = await fileserverMd5Promise;\r\n const localMd5 = await chunkWriter.getMd5Checksum(`hex`);\r\n if (remoteMd5.toLowerCase() === localMd5.toLowerCase())\r\n writtenCorrectly = true;\r\n else {\r\n writeErrors += 1;\r\n lastError = new DownloadError(`MD5 checksum incorrect: fileserver=${remoteMd5} local=${localMd5}`);\r\n }\r\n }\r\n else\r\n writtenCorrectly = true;\r\n }\r\n }\r\n catch (error) {\r\n // note: getting an exception here may be caused by abort or stop operations\r\n // both operations immediately interrupt HTTP download request by calling chunkDownloadClient.release()\r\n if (this.#downloadState.pauseImmediately || this.#downloadState.status === TransferStatus.Aborting)\r\n lastError = null;\r\n else {\r\n lastError = error as Error;\r\n\r\n if (lastError instanceof RequestError) {\r\n if (this.#isApiNotOkResponseStatusResponse(lastError))\r\n apiReturnedNotOkResponseStatus = true;\r\n else {\r\n this.#consecutiveNetworkErrors += 1;\r\n networkErrors += 1;\r\n this.#downloadState.networkFailure();\r\n }\r\n }\r\n else\r\n writeErrors += 1;\r\n\r\n this.#logger.logError(lastError, `[CHUNK_DOWNLOADER_ERROR] Error in retry loop when downloading chunk attempt=${attempts} writeerrors=${writeErrors} networkerrors=${networkErrors}`, this.#errorInfoDump());\r\n }\r\n }\r\n finally {\r\n await chunkWriter?.release();\r\n this.#chunkDownloadClient?.release();\r\n\r\n let sleepTime = 0;\r\n if (this.#downloadState.isThereNetworkProblem)\r\n sleepTime = this.#options.fileserverOfflineCheckIntervalMillis;\r\n else if (networkErrors > 0) {\r\n const pow = Math.min(networkErrors, this.#options.fileserverOfflineAfterConsecutiveAttempts);\r\n sleepTime = this.#options.fileserverOfflineCheckIntervalMillis * (2 ** (pow - this.#options.fileserverOfflineAfterConsecutiveAttempts));\r\n }\r\n\r\n if (sleepTime > 0)\r\n await sleep(sleepTime);\r\n }\r\n }\r\n }\r\n catch (error) {\r\n unhandledError = error as Error;\r\n this.#logger.logError(unhandledError, `[CHUNK_DOWNLOADER_ERROR] Unhandled error when downloading chunk`, this.#errorInfoDump());\r\n }\r\n finally {\r\n this.#removeEventListeners();\r\n }\r\n\r\n if (writtenCorrectly)\r\n this.#downloadState.chunkDownloadCompleted(this.#file, this.#chunk);\r\n else {\r\n let downloadError: DownloadError | null = null;\r\n const failureCode = this.#toFailureCode(unhandledError ?? lastError);\r\n\r\n if (unhandledError)\r\n downloadError = new DownloadError(`Unhandled chunk download error for file ${this.#file.url} chunk ${this.#chunk.chunkNumber}`, { cause: unhandledError as Error }, failureCode);\r\n else if (lastError)\r\n downloadError = new DownloadError(`Chunk download failed for file ${this.#file.url} chunk ${this.#chunk.chunkNumber} attempt ${attempts}.`, { cause: lastError as Error }, failureCode);\r\n\r\n if (downloadError !== null) {\r\n this.#downloadState.chunkDownloadFailed(\r\n this.#file,\r\n this.#chunk,\r\n downloadError,\r\n );\r\n }\r\n }\r\n\r\n this.#running = false;\r\n }\r\n\r\n #isDownloadClientRecreateNeeded(): boolean {\r\n return this.#consecutiveNetworkErrors > 0 && this.#consecutiveNetworkErrors % this.#options.fileserverOfflineAfterConsecutiveAttempts === 0;\r\n }\r\n\r\n #recreateDownloadClient() {\r\n this.#chunkDownloadClient.removeEventListener(`progress`, this.#onProgress);\r\n\r\n this.#chunkDownloadClient = this.#fileServerClientFactory.createFileServerTcpDownloadClient(this.#file.url, this.#chunk.start, this.#chunk.end, this.#transferId, this.#file.name, this.#options);\r\n\r\n this.#chunkDownloadClient.addEventListener(`progress`, this.#onProgress);\r\n }\r\n\r\n #throwIfRunning() {\r\n if (this.#running)\r\n throw new DownloadError(`This instance of chunk downloader is already in use. Please create a new one.`);\r\n }\r\n\r\n #throwIfMissingDownloadPath() {\r\n if (!this.#file.temporaryDownloadPath)\r\n throw new DownloadError(`Download file ${this.#file.externalId}/${this.#file.name}/${this.#file.downloadPath} is missing the required \"temporaryDownloadPath\"`);\r\n }\r\n\r\n #addEventListeners() {\r\n this.#eventsEngine.addEventListener(TransferDownloadEvent.Aborting, this.#onAbortRequested);\r\n this.#eventsEngine.addEventListener(TransferDownloadEvent.Pausing, this.#onPauseRequested);\r\n this.#eventsEngine.addEventListener(TransferDownloadEvent.FileDownloadFailed, this.#onFileFailed);\r\n this.#chunkDownloadClient.addEventListener(`progress`, this.#onProgress);\r\n }\r\n\r\n #removeEventListeners() {\r\n this.#eventsEngine.removeEventListener(TransferDownloadEvent.Aborting, this.#onAbortRequested);\r\n this.#eventsEngine.removeEventListener(TransferDownloadEvent.Pausing, this.#onPauseRequested);\r\n this.#eventsEngine.removeEventListener(TransferDownloadEvent.FileDownloadFailed, this.#onFileFailed);\r\n this.#chunkDownloadClient.removeEventListener(`progress`, this.#onProgress);\r\n }\r\n\r\n #canRetry(error: Error | null, writeErrors: number, networkErrors: number, apiReturnedNotOkResponseStatus: boolean) {\r\n if (this.#downloadState.status === TransferStatus.Aborting || this.#downloadState.status === TransferStatus.Pausing)\r\n return false;\r\n\r\n if (this.#file.isFailed)\r\n return false;\r\n\r\n if (apiReturnedNotOkResponseStatus)\r\n return false;\r\n\r\n if (this.#isDiskFullError(error))\r\n return false;\r\n\r\n if (error && error instanceof RequestError)\r\n return this.#options.fileserverAttemptLimit <= 0 || networkErrors < this.#options.fileserverAttemptLimit!;\r\n\r\n return this.#options.maxWriteAttempts! < 0 || writeErrors < this.#options.maxWriteAttempts!;\r\n }\r\n\r\n #isApiNotOkResponseStatusResponse(error: RequestError): boolean {\r\n try {\r\n if (typeof error.response?.body !== `string`)\r\n return false;\r\n\r\n const response = JSON.parse(error.response?.body);\r\n\r\n if (!isBaseResponse(response))\r\n return false;\r\n\r\n return response.responsestatus !== `OK`;\r\n }\r\n catch {\r\n return false;\r\n }\r\n }\r\n\r\n /**\r\n * This method aborts pending download - it can be achieved only by destroying the download client\r\n * (which in turn destroys the underlying download HTTP request). This operation\r\n * will throw an expected exception inside download method (in main while loop). See {@link download} method.\r\n */\r\n #interruptDownload = () => {\r\n this.#chunkDownloadClient?.release();\r\n };\r\n\r\n #onAbortRequested = () => {\r\n this.#interruptDownload();\r\n };\r\n\r\n #onPauseRequested = () => {\r\n if (this.#downloadState.pauseImmediately)\r\n this.#interruptDownload();\r\n };\r\n\r\n #onFileFailed = (args: FileDownloadFailedEventArgs) => {\r\n if (this.#file.externalId === args.file.id)\r\n this.#chunkDownloadClient?.release();\r\n };\r\n\r\n #onProgress = (args: ChunkProgressEvent) => {\r\n this.#bytesTransferred = args.transferredBytesTotal;\r\n this.#downloadState.chunkDownloadProgressed(this.#file, this.#chunk, args);\r\n };\r\n\r\n #errorInfoDump() {\r\n return {\r\n fileid: this.#file.externalId,\r\n filename: this.#file.name,\r\n chunk: DownloadFileChunkProgress.FromChunkInfo(this.#chunk),\r\n };\r\n }\r\n\r\n #toFailureCode(error: Error | null): DownloadErrorCode | undefined {\r\n if (this.#isDiskFullError(error))\r\n return DownloadErrorCode.DiskFull;\r\n\r\n return undefined;\r\n }\r\n\r\n #isDiskFullError(error: unknown): boolean {\r\n if (!error)\r\n return false;\r\n\r\n let current = error as { message?: string, code?: string, cause?: unknown } | undefined;\r\n for (let depth = 0; depth < 8 && current; depth++) {\r\n if (current.code === `ENOSPC`)\r\n return true;\r\n\r\n if (typeof current.message === `string` && current.message.includes(`ENOSPC`))\r\n return true;\r\n\r\n current = current.cause as { message?: string, code?: string, cause?: unknown } | undefined;\r\n }\r\n\r\n return false;\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"downloadFolderResolver.js","sourceRoot":"","s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,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC","sourcesContent":["import SimpleDateFormatter from \"../utils/dateAndTime/simpleDateFormatter.js\";\nimport type GetTransferResponse from \"../utils/api/dtos/getTransferResponse.js\";\n\nconst DefaultMaxPlaceholderLength = 60;\n\nexport default class DownloadFolderResolver {\n static #pathFriendlyDate(date: string): string {\n return date\n .replace(/:+/g, `-`)\n .replace(/-+/g, `-`);\n }\n\n static #sanitizePathElement(value: string | null | undefined): string {\n if (!value)\n return ``;\n\n return value\n .replaceAll(`..\\\\`, ``)\n .replaceAll(`../`, ``)\n .replaceAll(`..`, ``)\n .replaceAll(`:`, ``)\n .replaceAll(`<`, ``)\n .replaceAll(`>`, ``)\n .replaceAll(`\\\\`, ``)\n .replaceAll(`/`, ``)\n .replace(/(\\n|\\r\\n){1,}/g, ` `);\n }\n\n static #getDomain(fromEmail: string | null | undefined) {\n if (fromEmail) {\n const idx = fromEmail.indexOf(`@`);\n if (idx > -1)\n return fromEmail.substring(idx + 1);\n }\n return `[missing_domain]`;\n }\n\n static #escapeRegExp(str: string): string {\n return str.replace(/[.*+?^${}()|[\\]\\\\/-]/g, `\\\\$&`);\n }\n\n static #placeholderRegexForSubstring = (token: string) => {\n // eslint-disable-next-line no-param-reassign\n token = this.#escapeRegExp(token);\n return new RegExp(`<${token}(:(.*?))?>`, `g`);\n };\n\n static #replacePlaceholderWithMaxLength(input: string, rx: RegExp, replaceValue: string): string {\n return input.replace(rx, (_0: any, _1: any, maxLength: string | undefined): string => {\n let substringLength = DefaultMaxPlaceholderLength;\n if (!!maxLength && maxLength.length > 0) {\n try {\n substringLength = parseInt(maxLength, 10);\n if (Number.isNaN(substringLength))\n substringLength = DefaultMaxPlaceholderLength;\n }\n catch {\n substringLength = DefaultMaxPlaceholderLength;\n }\n }\n\n const sanitized = DownloadFolderResolver.#sanitizePathElement(replaceValue);\n\n if (substringLength < 0)\n return sanitized.substring(sanitized.length + substringLength);\n\n return sanitized.substring(0, substringLength);\n });\n }\n\n static prepareDownloadFolder(template: string, transfer: GetTransferResponse) {\n let result = template;\n if (transfer.from) {\n const domain = DownloadFolderResolver.#getDomain(transfer.from);\n result = result\n .replaceAll(`<domain>`, DownloadFolderResolver.#sanitizePathElement(domain))\n .replaceAll(`<emailfrom>`, DownloadFolderResolver.#sanitizePathElement(transfer.from));\n }\n result = result.replaceAll(`<id>`, transfer.id);\n\n // datesent\n result = result.replace(/<datesent(:(.*?))?>/g, (_0: any, _1: any, dateFormatString: string | undefined): string => {\n const dateFormatted = SimpleDateFormatter.formatDateAndTimeLocal(transfer.sentdate, dateFormatString);\n return DownloadFolderResolver.#sanitizePathElement(DownloadFolderResolver.#pathFriendlyDate(dateFormatted));\n });\n\n if (transfer.message) {\n result = DownloadFolderResolver.#replacePlaceholderWithMaxLength(\n result,\n DownloadFolderResolver.#placeholderRegexForSubstring(`description`),\n transfer.message,\n );\n }\n\n if (transfer.subject) {\n result = DownloadFolderResolver.#replacePlaceholderWithMaxLength(\n result,\n DownloadFolderResolver.#placeholderRegexForSubstring(`subject`),\n transfer.subject,\n );\n }\n\n if (transfer.to && transfer.to.length) {\n result = DownloadFolderResolver.#replacePlaceholderWithMaxLength(\n result,\n DownloadFolderResolver.#placeholderRegexForSubstring(`emailto`),\n transfer.to.join(`,`),\n );\n }\n\n if (transfer.customfields && transfer.customfields.length) {\n for (const cf of transfer.customfields) {\n if (cf.label && cf.value) {\n result = DownloadFolderResolver.#replacePlaceholderWithMaxLength(\n result,\n DownloadFolderResolver.#placeholderRegexForSubstring(cf.label),\n cf.value,\n );\n }\n }\n }\n // remaining custom fields which have not bee replaced from transfer - remove them\n /*\n if (company && company.customfields && company.customfields.length) {\n for (const cf of company.customfields)\n result = result.replace(new RegExp(`<${cf.label}>`, `ig`), ``);\n }\n */\n\n // replace remaining < and > (they are used as placeholder boundaries) and other chars which are not allowed in Windows folder paths\n result = result.replace(/<([^:>]+)(?::([^>]*))?>/g, (_match, name) => {\n // Remove backslashes from the captured name\n const clean = String(name).replace(/\\\\/g, ``);\n return `[missing_${clean}]`;\n });\n\n if (process.platform === `win32`)\n result = DownloadFolderResolver.#trimFolders(result);\n\n return result;\n }\n\n static #trimFolders(template: string) {\n const folders = template.replaceAll(`/`, `\\\\`).split(`\\\\`);\n\n for (let i = 0; i < folders.length; i++)\n folders[i] = folders[i]!.trim();\n\n return folders.join(`\\\\`);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"downloadFolderResolver.js","sourceRoot":"","sources":["../../../src/downloader/downloadFolderResolver.ts"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,MAAM,6CAA6C,CAAC;AAG9E,MAAM,2BAA2B,GAAG,EAAE,CAAC;AAEvC,MAAM,CAAC,OAAO,OAAO,sBAAsB;IACvC,MAAM,CAAC,iBAAiB,CAAC,IAAY;QACjC,OAAO,IAAI;aACN,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;aACnB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC7B,CAAC;IAED,MAAM,CAAC,oBAAoB,CAAC,KAAgC;QACxD,IAAI,CAAC,KAAK;YACN,OAAO,EAAE,CAAC;QAEd,OAAO,KAAK;aACP,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC;aACtB,UAAU,CAAC,KAAK,EAAE,EAAE,CAAC;aACrB,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC;aACpB,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC;aACnB,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC;aACnB,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC;aACnB,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC;aACpB,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC;aACnB,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAC;IACxC,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,SAAoC;QAClD,IAAI,SAAS,EAAE,CAAC;YACZ,MAAM,GAAG,GAA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M,CAAC,YAAY,CAAC,QAAgB;QAChC,MAAM,OAAO,GAAG,QAAQ,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAE3D,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE;YACnC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAE,CAAC,IAAI,EAAE,CAAC;QAEpC,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC","sourcesContent":["import SimpleDateFormatter from \"../utils/dateAndTime/simpleDateFormatter.js\";\r\nimport type GetTransferResponse from \"../utils/api/dtos/getTransferResponse.js\";\r\n\r\nconst DefaultMaxPlaceholderLength = 60;\r\n\r\nexport default class DownloadFolderResolver {\r\n static #pathFriendlyDate(date: string): string {\r\n return date\r\n .replace(/:+/g, `-`)\r\n .replace(/-+/g, `-`);\r\n }\r\n\r\n static #sanitizePathElement(value: string | null | undefined): string {\r\n if (!value)\r\n return ``;\r\n\r\n return value\r\n .replaceAll(`..\\\\`, ``)\r\n .replaceAll(`../`, ``)\r\n .replaceAll(`..`, ``)\r\n .replaceAll(`:`, ``)\r\n .replaceAll(`<`, ``)\r\n .replaceAll(`>`, ``)\r\n .replaceAll(`\\\\`, ``)\r\n .replaceAll(`/`, ``)\r\n .replace(/(\\n|\\r\\n){1,}/g, ` `);\r\n }\r\n\r\n static #getDomain(fromEmail: string | null | undefined) {\r\n if (fromEmail) {\r\n const idx = fromEmail.indexOf(`@`);\r\n if (idx > -1)\r\n return fromEmail.substring(idx + 1);\r\n }\r\n return `[missing_domain]`;\r\n }\r\n\r\n static #escapeRegExp(str: string): string {\r\n return str.replace(/[.*+?^${}()|[\\]\\\\/-]/g, `\\\\$&`);\r\n }\r\n\r\n static #placeholderRegexForSubstring = (token: string) => {\r\n // eslint-disable-next-line no-param-reassign\r\n token = this.#escapeRegExp(token);\r\n return new RegExp(`<${token}(:(.*?))?>`, `g`);\r\n };\r\n\r\n static #replacePlaceholderWithMaxLength(input: string, rx: RegExp, replaceValue: string): string {\r\n return input.replace(rx, (_0: any, _1: any, maxLength: string | undefined): string => {\r\n let substringLength = DefaultMaxPlaceholderLength;\r\n if (!!maxLength && maxLength.length > 0) {\r\n try {\r\n substringLength = parseInt(maxLength, 10);\r\n if (Number.isNaN(substringLength))\r\n substringLength = DefaultMaxPlaceholderLength;\r\n }\r\n catch {\r\n substringLength = DefaultMaxPlaceholderLength;\r\n }\r\n }\r\n\r\n const sanitized = DownloadFolderResolver.#sanitizePathElement(replaceValue);\r\n\r\n if (substringLength < 0)\r\n return sanitized.substring(sanitized.length + substringLength);\r\n\r\n return sanitized.substring(0, substringLength);\r\n });\r\n }\r\n\r\n static prepareDownloadFolder(template: string, transfer: GetTransferResponse) {\r\n let result = template;\r\n if (transfer.from) {\r\n const domain = DownloadFolderResolver.#getDomain(transfer.from);\r\n result = result\r\n .replaceAll(`<domain>`, DownloadFolderResolver.#sanitizePathElement(domain))\r\n .replaceAll(`<emailfrom>`, DownloadFolderResolver.#sanitizePathElement(transfer.from));\r\n }\r\n result = result.replaceAll(`<id>`, transfer.id);\r\n\r\n // datesent\r\n result = result.replace(/<datesent(:(.*?))?>/g, (_0: any, _1: any, dateFormatString: string | undefined): string => {\r\n const dateFormatted = SimpleDateFormatter.formatDateAndTimeLocal(transfer.sentdate, dateFormatString);\r\n return DownloadFolderResolver.#sanitizePathElement(DownloadFolderResolver.#pathFriendlyDate(dateFormatted));\r\n });\r\n\r\n if (transfer.message) {\r\n result = DownloadFolderResolver.#replacePlaceholderWithMaxLength(\r\n result,\r\n DownloadFolderResolver.#placeholderRegexForSubstring(`description`),\r\n transfer.message,\r\n );\r\n }\r\n\r\n if (transfer.subject) {\r\n result = DownloadFolderResolver.#replacePlaceholderWithMaxLength(\r\n result,\r\n DownloadFolderResolver.#placeholderRegexForSubstring(`subject`),\r\n transfer.subject,\r\n );\r\n }\r\n\r\n if (transfer.to && transfer.to.length) {\r\n result = DownloadFolderResolver.#replacePlaceholderWithMaxLength(\r\n result,\r\n DownloadFolderResolver.#placeholderRegexForSubstring(`emailto`),\r\n transfer.to.join(`,`),\r\n );\r\n }\r\n\r\n if (transfer.customfields && transfer.customfields.length) {\r\n for (const cf of transfer.customfields) {\r\n if (cf.label && cf.value) {\r\n result = DownloadFolderResolver.#replacePlaceholderWithMaxLength(\r\n result,\r\n DownloadFolderResolver.#placeholderRegexForSubstring(cf.label),\r\n cf.value,\r\n );\r\n }\r\n }\r\n }\r\n // remaining custom fields which have not bee replaced from transfer - remove them\r\n /*\r\n if (company && company.customfields && company.customfields.length) {\r\n for (const cf of company.customfields)\r\n result = result.replace(new RegExp(`<${cf.label}>`, `ig`), ``);\r\n }\r\n */\r\n\r\n // replace remaining < and > (they are used as placeholder boundaries) and other chars which are not allowed in Windows folder paths\r\n result = result.replace(/<([^:>]+)(?::([^>]*))?>/g, (_match, name) => {\r\n // Remove backslashes from the captured name\r\n const clean = String(name).replace(/\\\\/g, ``);\r\n return `[missing_${clean}]`;\r\n });\r\n\r\n if (process.platform === `win32`)\r\n result = DownloadFolderResolver.#trimFolders(result);\r\n\r\n return result;\r\n }\r\n\r\n static #trimFolders(template: string) {\r\n const folders = template.replaceAll(`/`, `\\\\`).split(`\\\\`);\r\n\r\n for (let i = 0; i < folders.length; i++)\r\n folders[i] = folders[i]!.trim();\r\n\r\n return folders.join(`\\\\`);\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"downloadLogger.js","sourceRoot":"","sources":["../../../src/downloader/downloadLogger.ts"],"names":[],"mappings":"AACA,OAAO,oBAAoB,MAAM,2CAA2C,CAAC;AAE7E,MAAM,CAAC,OAAO,OAAO,cAAc;IAC/B,OAAO,CAAS;IAChB,WAAW,CAAkB;IAC7B,WAAW,CAAqB;IAChC,WAAW,CAAqB;IAEhC,YAAY,MAA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gBAAgB,CAAC,cAAc,CAAC,CAAC,CAAC;IACpG,CAAC;IAED,OAAO,CAAC,OAAe,EAAE,IAAU,EAAE,cAAwC;QACzE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,gBAAgB,CAAC,cAAc,CAAC,CAAC,CAAC;IACnG,CAAC;IAED,UAAU,CAAC,OAAe,EAAE,IAAU,EAAE,cAAwC;QAC5E,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,gBAAgB,CAAC,cAAc,CAAC,CAAC,CAAC;IACtG,CAAC;IAED,QAAQ,CAAC,KAAY,EAAE,OAAgB,EAAE,IAAU,EAAE,cAAwC;QACzF,MAAM,iBAAiB,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACnF,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,EAAE,iBAAiB,EAAE,IAAI,CAAC,gBAAgB,CAAC,cAAc,CAAC,CAAC,CAAC;IAC3F,CAAC;CACJ","sourcesContent":["import type Logger from \"../client/loggers/logger.js\";\nimport logEventPropertyName from \"../utils/logging/logEventPropertyNames.js\";\n\nexport default class DownloadLogger implements Logger {\n #logger: Logger;\n #trackingId: string | number;\n #transferId: string | undefined;\n #downloadId: string | undefined;\n\n constructor(logger: Logger, trackingId: string | number) {\n this.#logger = logger;\n this.#trackingId = trackingId;\n }\n\n applyTransferId(id: string) {\n this.#transferId = id;\n }\n\n applyDownloadId(id: string) {\n this.#downloadId = id;\n }\n\n #buildCustomData(additionalArgs?: Record<string, unknown>) {\n const customData: Record<string, unknown> = {\n [logEventPropertyName.TrackingIdPropertyName]: this.#trackingId,\n ...additionalArgs,\n };\n\n if (this.#transferId)\n customData[logEventPropertyName.TransferIdPropertyName] = this.#transferId;\n\n if (this.#downloadId)\n customData[logEventPropertyName.DownloadIdPropertyName] = this.#downloadId;\n\n return customData;\n }\n\n #buildMessage(message: string, json?: any) {\n if (json)\n return `${message}\\n${JSON.stringify(json, null, 2)}`;\n return message;\n }\n\n logTrace(message: string, json?: any, additionalArgs?: Record<string, unknown>) {\n this.#logger.logTrace(this.#buildMessage(message, json), this.#buildCustomData(additionalArgs));\n }\n\n logDebug(message: string, json?: any, additionalArgs?: Record<string, unknown>) {\n this.#logger.logDebug(this.#buildMessage(message, json), this.#buildCustomData(additionalArgs));\n }\n\n logInfo(message: string, json?: any, additionalArgs?: Record<string, unknown>) {\n this.#logger.logInfo(this.#buildMessage(message, json), this.#buildCustomData(additionalArgs));\n }\n\n logWarning(message: string, json?: any, additionalArgs?: Record<string, unknown>) {\n this.#logger.logWarning(this.#buildMessage(message, json), this.#buildCustomData(additionalArgs));\n }\n\n logError(error: Error, message?: string, json?: any, additionalArgs?: Record<string, unknown>) {\n const messageToBeLogged = !message ? undefined : this.#buildMessage(message, json);\n this.#logger.logError(error, messageToBeLogged, this.#buildCustomData(additionalArgs));\n }\n}"]}
|
|
1
|
+
{"version":3,"file":"downloadLogger.js","sourceRoot":"","sources":["../../../src/downloader/downloadLogger.ts"],"names":[],"mappings":"AACA,OAAO,oBAAoB,MAAM,2CAA2C,CAAC;AAE7E,MAAM,CAAC,OAAO,OAAO,cAAc;IAC/B,OAAO,CAAS;IAChB,WAAW,CAAkB;IAC7B,WAAW,CAAqB;IAChC,WAAW,CAAqB;IAEhC,YAAY,MAAc,EAAE,UAA2B;QACnD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAClC,CAAC;IAED,eAAe,CAAC,EAAU;QACtB,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;IAC1B,CAAC;IAED,eAAe,CAAC,EAAU;QACtB,IAAI,CAAC,WAA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AAC,CAAC;IACnG,CAAC;IAED,UAAU,CAAC,OAAe,EAAE,IAAU,EAAE,cAAwC;QAC5E,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,gBAAgB,CAAC,cAAc,CAAC,CAAC,CAAC;IACtG,CAAC;IAED,QAAQ,CAAC,KAAY,EAAE,OAAgB,EAAE,IAAU,EAAE,cAAwC;QACzF,MAAM,iBAAiB,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACnF,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,EAAE,iBAAiB,EAAE,IAAI,CAAC,gBAAgB,CAAC,cAAc,CAAC,CAAC,CAAC;IAC3F,CAAC;CACJ","sourcesContent":["import type Logger from \"../client/loggers/logger.js\";\r\nimport logEventPropertyName from \"../utils/logging/logEventPropertyNames.js\";\r\n\r\nexport default class DownloadLogger implements Logger {\r\n #logger: Logger;\r\n #trackingId: string | number;\r\n #transferId: string | undefined;\r\n #downloadId: string | undefined;\r\n\r\n constructor(logger: Logger, trackingId: string | number) {\r\n this.#logger = logger;\r\n this.#trackingId = trackingId;\r\n }\r\n\r\n applyTransferId(id: string) {\r\n this.#transferId = id;\r\n }\r\n\r\n applyDownloadId(id: string) {\r\n this.#downloadId = id;\r\n }\r\n\r\n #buildCustomData(additionalArgs?: Record<string, unknown>) {\r\n const customData: Record<string, unknown> = {\r\n [logEventPropertyName.TrackingIdPropertyName]: this.#trackingId,\r\n ...additionalArgs,\r\n };\r\n\r\n if (this.#transferId)\r\n customData[logEventPropertyName.TransferIdPropertyName] = this.#transferId;\r\n\r\n if (this.#downloadId)\r\n customData[logEventPropertyName.DownloadIdPropertyName] = this.#downloadId;\r\n\r\n return customData;\r\n }\r\n\r\n #buildMessage(message: string, json?: any) {\r\n if (json)\r\n return `${message}\\n${JSON.stringify(json, null, 2)}`;\r\n return message;\r\n }\r\n\r\n logTrace(message: string, json?: any, additionalArgs?: Record<string, unknown>) {\r\n this.#logger.logTrace(this.#buildMessage(message, json), this.#buildCustomData(additionalArgs));\r\n }\r\n\r\n logDebug(message: string, json?: any, additionalArgs?: Record<string, unknown>) {\r\n this.#logger.logDebug(this.#buildMessage(message, json), this.#buildCustomData(additionalArgs));\r\n }\r\n\r\n logInfo(message: string, json?: any, additionalArgs?: Record<string, unknown>) {\r\n this.#logger.logInfo(this.#buildMessage(message, json), this.#buildCustomData(additionalArgs));\r\n }\r\n\r\n logWarning(message: string, json?: any, additionalArgs?: Record<string, unknown>) {\r\n this.#logger.logWarning(this.#buildMessage(message, json), this.#buildCustomData(additionalArgs));\r\n }\r\n\r\n logError(error: Error, message?: string, json?: any, additionalArgs?: Record<string, unknown>) {\r\n const messageToBeLogged = !message ? undefined : this.#buildMessage(message, json);\r\n this.#logger.logError(error, messageToBeLogged, this.#buildCustomData(additionalArgs));\r\n }\r\n}"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"downloadOptions.js","sourceRoot":"","sources":["../../../src/downloader/downloadOptions.ts"],"names":[],"mappings":"AAAA,MAAM,eAAe;IACjB;;;OAGG;IACH,UAAU,GAAkB,IAAI,CAAC;IACjC;;;;;;;;;;;;OAYG;IACH,sBAAsB,GAAkB,IAAI,CAAC;IAC7C;;;;OAIG;IACH,cAAc,GAAkB,IAAI,CAAC;IACrC;;;OAGG;IACH,0BAA0B,GAAG,KAAK,CAAC;IACnC;;;;OAIG;IACH,aAAa,GAAG,CAAC,CAAC;IAClB;;;;;OAKG;IACH,cAAc,GAAG,CAAC,CAAC;IACnB;;;OAGG;IACH,gBAAgB,GAAG,EAAE,CAAC;IACtB;;;OAGG;IACH,SAAS,GAAkB,IAAI,CAAC;IAChC;;;OAGG;IACH,YAAY,GAAkB,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;IAC/C;;;OAGG;IACH,cAAc,GAAG,IAAI,CAAC;IACtB;;;OAGG;IACH,YAAY,GAAG,KAAK,CAAC;IACrB;;;OAGG;IACH,4BAA4B,GAAG,KAAK,CAAC;IACrC;;;;;OAKG;IACH,sBAAsB,GAAG,CAAC,CAAC;IAC3B;;;;OAIG;IACH,yCAAyC,GAAG,EAAE,CAAC;IAC/C;;;;;OAKG;IACH,oCAAoC,GAAG,IAAI,CAAC;IAC5C;;;OAGG;IACH,kBAAkB,GAAG,GAAG,CAAC;IACzB;;;OAGG;IACH,yBAAyB,GAAG,IAAI,CAAC;IACjC;;;OAGG;IACH,8BAA8B,GAAG,IAAI,CAAC;IACtC;;;;;OAKG;IACH,uCAAuC,GAAG,KAAK,CAAC;IAChD;;;;;;OAMG;IACH,0BAA0B,GAAkB,IAAI,CAAC;IACjD;;;OAGG;IACH,8BAA8B,GAAG,IAAI,CAAC;IACtC;;;OAGG;IACH,oCAAoC,GAAG,IAAI,CAAC;IAC5C;;OAEG;IACH,UAAU,CAA8B;IACxC;;;OAGG;IACH,gBAAgB,GAAG,KAAK,CAAC;CAC5B;AAED,eAAe,eAAe,CAAC","sourcesContent":["class DownloadOptions {\n /**\n * logintoken of the current user - used to fetch transfer (optionally also pwd-protected), company setup, register download\n * @default null\n */\n logintoken: string | null = null;\n /**\n * Path template where files should be downloaded. Provide this OR {@link downloadFolder}. Supports placeholders:\n * <id> - transferId\n * <subject>\n * <description>\n * <domain> - domain based on \"from\" email (e.g. user@example.com --> example.com)\n * <emailfrom>\n * <datesent> - will be formatted as \"YYYY-MM-DD-hh-mm\"\n * <datesent:format> - will be formatted according to \"format\"; supported placeholders in \"format\": YYYY, MM, DD, hh, mm\n * <emailto> - all recipients emails comma-separated\n * <{custom_field_label}> - specified custom field named by label will replaced with that custom field's value\n * @default null\n */\n downloadFolderTemplate: string | null = null;\n /**\n * The path where files should be downloaded. No placeholders. Provide this OR {@link downloadFolderTemplate}.\n * When {@link downloadFolderTemplate} is specified this value will be overwritten with the resolved (final) path.\n * @default null\n */\n downloadFolder: string | null = null;\n /**\n * HTTP request timeout for web api (not Fileserver) in milliseconds.\n * @default 60000\n */\n apiRequestTotalTimeoutInMs = 60000;\n /**\n * How many times to attempt HTTP requests towards web API (not Fileserver) e.g. when getting a transfer from the API.\n * @see https://github.com/sindresorhus/got#documentation\n * @default 3\n */\n apiRetryLimit = 3;\n /**\n * Maximum number (N) of chunks that can be downloaded in parallel. As soon as any single chunk is complete then next available chunk is started (to keep parallel chunks always at N).\n * - If there is one huge file with X chunks (X>N) - first N chunks will be picked up.\n * - If there are 2 files, each with 3 chunks and N=4 - both files will be started (all 3 chunks of first file and only 1st chunk of the 2nd file).\n * @default 8\n */\n parallelChunks = 8;\n /**\n * How many times to try write downloaded bytes of a chunk and optionally verify its MD5. Set to -1 to keep trying forever.\n * @default 20\n */\n maxWriteAttempts = 20;\n /**\n * The user-agent header that will be used for all fileserver GetFile requests.\n * @default null\n */\n userAgent: string | null = null;\n /**\n * Maximum size (S) of a chunk in bytes. When set to a number - downloader will split files into chunks of this size (size of last chunk) <= S. Set to null to download every file in one HTTPS request.\n * @default 50 * 1024 * 1024 (50MB) - this matches the default pre-calculated rangehashes on Fileservers.\n */\n maxChunkSize: number | null = 50 * 1024 * 1024;\n /**\n * When set to **true** downloader will verify MD5 after every chunk. This doesn't work for end to end encrypted transfers.\n * @efault true\n */\n checkChunksMd5 = true;\n /**\n * When set to **true** downloader will verify MD5 for every completed file (entire file). To use this feature provided the MD5 value in DownloadFileInfo passed to the downloader. This doesn't work for end to end encrypted transfers.\n * @note NOT SUPPORTED (YET)\n */\n checkFileMd5 = false;\n /**\n * How long should it take for HTTP library to throw error when no download data is pumped to response (milliseconds).\n * @default 30000\n */\n fileserverDownloadIdleTimeMs = 30000;\n /**\n * How many times to attempt a single HTTP download request against Fileserver's GetFile. Set this options to 0 to keep trying forever.\n * When set to 0 (retring forever) the downloader will report \"network problem\" after 10 failed attempts (via event and a status field).\n * When connectivity is back it will be reported with an event as well.\n * @default 0\n */\n fileserverAttemptLimit = 0;\n /**\n * Downloader will assume there is a \"network problem\" after this many consecutive network errors without any successful progress.\n * Set to -1 to disable this feature.\n * @default 10;\n */\n fileserverOfflineAfterConsecutiveAttempts = 10;\n /**\n * Once downloader sees a \"network problem\" it will retry every pending chunk with this interval (in milliseconds).\n * This interval will be also used to calculate exponential backoff between first network error and getting into \"network problem\" state\n * and also is the maximum interval of the exponential backoff.\n * @default 5000;\n */\n fileserverOfflineCheckIntervalMillis = 5000;\n /**\n * Number of milliseconds between progress events emitted by the downloader (throttling - they won't be emitted more often that this amount of time).\n * @default 100\n */\n progressTickMillis = 100;\n /**\n * If set to **true** ==> the downloader will delete those files which were being downloaded, but failed.\n * @default true\n */\n deleteFailedFilesFromDisk = true;\n /**\n * When set to **true** ==> after user requests download abort - the downloader will delete all files which it tried to download, no matter their size and status.\n * @default true\n */\n deleteAbortedDownloadsFromDisk = true;\n /**\n * When set to **true** ==> after download completes or is aborted - the downloader will delete the main download folder if it is empty (no files have been downloaded and there are no other files left over).\n * Default is false as usually the download folder is set to be the OS-special (e.g. on windows --> c:\\users\\jane\\Downloads). We don't want to try removing that.\n * Set this to **true** only if specifying custom download folders.\n * @default false\n */\n deleteEmptyDownloadFoldersAfterDownload = false;\n /**\n * When this path is specified (not null) then downloader will track download progress of each file within this folder.\n * Every download gets own subfolder (transferID_downloadID) with dumped options of the download (options.json) and files.json\n * which tracks all pending files. It will not contain completed files or those that have not started yet. Tracking is performed with\n * chunk-precision (not byte-precision). Worst case the download tracker may lose N chunks (N being the number of {@link parallelChunks}).\n * @default null\n */\n downloadTrackingBaseFolder: string | null = null;\n /**\n * Minimum time interval (in milliseconds) between consecutive dumps of downloader state to disk.\n * @default 5000\n */\n downloadTrackingIntervalMillis = 5000;\n /**\n * Time window length (in milliseconds) over which the downloader calculates momentary download speed.\n * @default 2000\n */\n momentaryDownloadSpeedTimespanMillis = 2000;\n /**\n * A value that will be appended to all log events.\n */\n trackingId: number | string | undefined;\n /**\n * Skips download registration if set to true\n * @default false\n */\n skipRegistration = false;\n}\n\nexport default DownloadOptions;\n"]}
|
|
1
|
+
{"version":3,"file":"downloadOptions.js","sourceRoot":"","sources":["../../../src/downloader/downloadOptions.ts"],"names":[],"mappings":"AAAA,MAAM,eAAe;IACjB;;;OAGG;IACH,UAAU,GAAkB,IAAI,CAAC;IACjC;;;;;;;;;;;;OAYG;IACH,sBAAsB,GAAkB,IAAI,CAAC;IAC7C;;;;OAIG;IACH,cAAc,GAAkB,IAAI,CAAC;IACrC;;;OAGG;IACH,0BAA0B,GAAG,KAAK,CAAC;IACnC;;;;OAIG;IACH,aAAa,GAAG,CAAC,CAAC;IAClB;;;;;OAKG;IACH,cAAc,GAAG,CAAC,CAAC;IACnB;;;OAGG;IACH,gBAAgB,GAAG,EAAE,CAAC;IACtB;;;OAGG;IACH,SAAS,GAAkB,IAAI,CAAC;IAChC;;;OAGG;IACH,YAAY,GAAkB,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;IAC/C;;;OAGG;IACH,cAAc,GAAG,IAAI,CAAC;IACtB;;;OAGG;IACH,YAAY,GAAG,KAAK,CAAC;IACrB;;;OAGG;IACH,4BAA4B,GAAG,KAAK,CAAC;IACrC;;;;;OAKG;IACH,sBAAsB,GAAG,CAAC,CAAC;IAC3B;;;;OAIG;IACH,yCAAyC,GAAG,EAAE,CAAC;IAC/C;;;;;OAKG;IACH,oCAAoC,GAAG,IAAI,CAAC;IAC5C;;;OAGG;IACH,kBAAkB,GAAG,GAAG,CAAC;IACzB;;;OAGG;IACH,yBAAyB,GAAG,IAAI,CAAC;IACjC;;;OAGG;IACH,8BAA8B,GAAG,IAAI,CAAC;IACtC;;;;;OAKG;IACH,uCAAuC,GAAG,KAAK,CAAC;IAChD;;;;;;OAMG;IACH,0BAA0B,GAAkB,IAAI,CAAC;IACjD;;;OAGG;IACH,8BAA8B,GAAG,IAAI,CAAC;IACtC;;;OAGG;IACH,oCAAoC,GAAG,IAAI,CAAC;IAC5C;;OAEG;IACH,UAAU,CAA8B;IACxC;;;OAGG;IACH,gBAAgB,GAAG,KAAK,CAAC;CAC5B;AAED,eAAe,eAAe,CAAC","sourcesContent":["class DownloadOptions {\r\n /**\r\n * logintoken of the current user - used to fetch transfer (optionally also pwd-protected), company setup, register download\r\n * @default null\r\n */\r\n logintoken: string | null = null;\r\n /**\r\n * Path template where files should be downloaded. Provide this OR {@link downloadFolder}. Supports placeholders:\r\n * <id> - transferId\r\n * <subject>\r\n * <description>\r\n * <domain> - domain based on \"from\" email (e.g. user@example.com --> example.com)\r\n * <emailfrom>\r\n * <datesent> - will be formatted as \"YYYY-MM-DD-hh-mm\"\r\n * <datesent:format> - will be formatted according to \"format\"; supported placeholders in \"format\": YYYY, MM, DD, hh, mm\r\n * <emailto> - all recipients emails comma-separated\r\n * <{custom_field_label}> - specified custom field named by label will replaced with that custom field's value\r\n * @default null\r\n */\r\n downloadFolderTemplate: string | null = null;\r\n /**\r\n * The path where files should be downloaded. No placeholders. Provide this OR {@link downloadFolderTemplate}.\r\n * When {@link downloadFolderTemplate} is specified this value will be overwritten with the resolved (final) path.\r\n * @default null\r\n */\r\n downloadFolder: string | null = null;\r\n /**\r\n * HTTP request timeout for web api (not Fileserver) in milliseconds.\r\n * @default 60000\r\n */\r\n apiRequestTotalTimeoutInMs = 60000;\r\n /**\r\n * How many times to attempt HTTP requests towards web API (not Fileserver) e.g. when getting a transfer from the API.\r\n * @see https://github.com/sindresorhus/got#documentation\r\n * @default 3\r\n */\r\n apiRetryLimit = 3;\r\n /**\r\n * Maximum number (N) of chunks that can be downloaded in parallel. As soon as any single chunk is complete then next available chunk is started (to keep parallel chunks always at N).\r\n * - If there is one huge file with X chunks (X>N) - first N chunks will be picked up.\r\n * - If there are 2 files, each with 3 chunks and N=4 - both files will be started (all 3 chunks of first file and only 1st chunk of the 2nd file).\r\n * @default 8\r\n */\r\n parallelChunks = 8;\r\n /**\r\n * How many times to try write downloaded bytes of a chunk and optionally verify its MD5. Set to -1 to keep trying forever.\r\n * @default 20\r\n */\r\n maxWriteAttempts = 20;\r\n /**\r\n * The user-agent header that will be used for all fileserver GetFile requests.\r\n * @default null\r\n */\r\n userAgent: string | null = null;\r\n /**\r\n * Maximum size (S) of a chunk in bytes. When set to a number - downloader will split files into chunks of this size (size of last chunk) <= S. Set to null to download every file in one HTTPS request.\r\n * @default 50 * 1024 * 1024 (50MB) - this matches the default pre-calculated rangehashes on Fileservers.\r\n */\r\n maxChunkSize: number | null = 50 * 1024 * 1024;\r\n /**\r\n * When set to **true** downloader will verify MD5 after every chunk. This doesn't work for end to end encrypted transfers.\r\n * @efault true\r\n */\r\n checkChunksMd5 = true;\r\n /**\r\n * When set to **true** downloader will verify MD5 for every completed file (entire file). To use this feature provided the MD5 value in DownloadFileInfo passed to the downloader. This doesn't work for end to end encrypted transfers.\r\n * @note NOT SUPPORTED (YET)\r\n */\r\n checkFileMd5 = false;\r\n /**\r\n * How long should it take for HTTP library to throw error when no download data is pumped to response (milliseconds).\r\n * @default 30000\r\n */\r\n fileserverDownloadIdleTimeMs = 30000;\r\n /**\r\n * How many times to attempt a single HTTP download request against Fileserver's GetFile. Set this options to 0 to keep trying forever.\r\n * When set to 0 (retring forever) the downloader will report \"network problem\" after 10 failed attempts (via event and a status field).\r\n * When connectivity is back it will be reported with an event as well.\r\n * @default 0\r\n */\r\n fileserverAttemptLimit = 0;\r\n /**\r\n * Downloader will assume there is a \"network problem\" after this many consecutive network errors without any successful progress.\r\n * Set to -1 to disable this feature.\r\n * @default 10;\r\n */\r\n fileserverOfflineAfterConsecutiveAttempts = 10;\r\n /**\r\n * Once downloader sees a \"network problem\" it will retry every pending chunk with this interval (in milliseconds).\r\n * This interval will be also used to calculate exponential backoff between first network error and getting into \"network problem\" state\r\n * and also is the maximum interval of the exponential backoff.\r\n * @default 5000;\r\n */\r\n fileserverOfflineCheckIntervalMillis = 5000;\r\n /**\r\n * Number of milliseconds between progress events emitted by the downloader (throttling - they won't be emitted more often that this amount of time).\r\n * @default 100\r\n */\r\n progressTickMillis = 100;\r\n /**\r\n * If set to **true** ==> the downloader will delete those files which were being downloaded, but failed.\r\n * @default true\r\n */\r\n deleteFailedFilesFromDisk = true;\r\n /**\r\n * When set to **true** ==> after user requests download abort - the downloader will delete all files which it tried to download, no matter their size and status.\r\n * @default true\r\n */\r\n deleteAbortedDownloadsFromDisk = true;\r\n /**\r\n * When set to **true** ==> after download completes or is aborted - the downloader will delete the main download folder if it is empty (no files have been downloaded and there are no other files left over).\r\n * Default is false as usually the download folder is set to be the OS-special (e.g. on windows --> c:\\users\\jane\\Downloads). We don't want to try removing that.\r\n * Set this to **true** only if specifying custom download folders.\r\n * @default false\r\n */\r\n deleteEmptyDownloadFoldersAfterDownload = false;\r\n /**\r\n * When this path is specified (not null) then downloader will track download progress of each file within this folder.\r\n * Every download gets own subfolder (transferID_downloadID) with dumped options of the download (options.json) and files.json\r\n * which tracks all pending files. It will not contain completed files or those that have not started yet. Tracking is performed with\r\n * chunk-precision (not byte-precision). Worst case the download tracker may lose N chunks (N being the number of {@link parallelChunks}).\r\n * @default null\r\n */\r\n downloadTrackingBaseFolder: string | null = null;\r\n /**\r\n * Minimum time interval (in milliseconds) between consecutive dumps of downloader state to disk.\r\n * @default 5000\r\n */\r\n downloadTrackingIntervalMillis = 5000;\r\n /**\r\n * Time window length (in milliseconds) over which the downloader calculates momentary download speed.\r\n * @default 2000\r\n */\r\n momentaryDownloadSpeedTimespanMillis = 2000;\r\n /**\r\n * A value that will be appended to all log events.\r\n */\r\n trackingId: number | string | undefined;\r\n /**\r\n * Skips download registration if set to true\r\n * @default false\r\n */\r\n skipRegistration = false;\r\n}\r\n\r\nexport default DownloadOptions;\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"downloadFileChunkProgress.js","sourceRoot":"","sources":["../../../../src/downloader/downloadStatus/downloadFileChunkProgress.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,OAAO,yBAAyB;IAC1C,EAAE,CAAS;IACX,WAAW,CAAS;IACpB,KAAK,CAAgB;IACrB,GAAG,CAAgB;IACnB,IAAI,CAAS;IACb,UAAU,CAAS;IACnB,OAAO,CAAS;IAChB,SAAS,CAAU;IACnB,MAAM,CAAU;IAEhB,YAAY,EAAU,EAAE,WAAmB,EAAE,KAAoB,EAAE,GAAkB,EAAE,IAAY,EAAE,UAAkB,EAAE,OAAe,EAAE,SAAkB,EAAE,MAAe;QACzK,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAEM,MAAM,CAAC,aAAa,CAAC,KAA4B;QACpD,OAAO,IAAI,yBAAyB,CAChC,KAAK,CAAC,EAAE,EACR,KAAK,CAAC,WAAW,EACjB,KAAK,CAAC,KAAK,EACX,KAAK,CAAC,GAAG,EACT,KAAK,CAAC,SAAS,EACf,KAAK,CAAC,eAAe,EACrB,KAAK,CAAC,OAAO,EACb,KAAK,CAAC,WAAW,EACjB,KAAK,CAAC,QAAQ,CACjB,CAAC;IACN,CAAC;CACJ","sourcesContent":["import type DownloadFileChunkInfo from \"../dtos/downloadFileChunkInfo.js\";\n\nexport default class DownloadFileChunkProgress {\n id: string;\n chunkNumber: number;\n start: number | null;\n end: number | null;\n size: number;\n downloaded: number;\n percent: number;\n completed: boolean;\n failed: boolean;\n\n constructor(id: string, chunkNumber: number, start: number | null, end: number | null, size: number, downloaded: number, percent: number, completed: boolean, failed: boolean) {\n this.id = id;\n this.chunkNumber = chunkNumber;\n this.start = start;\n this.end = end;\n this.size = size;\n this.downloaded = downloaded;\n this.percent = percent;\n this.completed = completed;\n this.failed = failed;\n }\n\n public static FromChunkInfo(chunk: DownloadFileChunkInfo): DownloadFileChunkProgress {\n return new DownloadFileChunkProgress(\n chunk.id,\n chunk.chunkNumber,\n chunk.start,\n chunk.end,\n chunk.chunkSize,\n chunk.downloadedBytes,\n chunk.percent,\n chunk.isCompleted,\n chunk.isFailed,\n );\n }\n}"]}
|
|
1
|
+
{"version":3,"file":"downloadFileChunkProgress.js","sourceRoot":"","sources":["../../../../src/downloader/downloadStatus/downloadFileChunkProgress.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,OAAO,yBAAyB;IAC1C,EAAE,CAAS;IACX,WAAW,CAAS;IACpB,KAAK,CAAgB;IACrB,GAAG,CAAgB;IACnB,IAAI,CAAS;IACb,UAAU,CAAS;IACnB,OAAO,CAAS;IAChB,SAAS,CAAU;IACnB,MAAM,CAAU;IAEhB,YAAY,EAAU,EAAE,WAAmB,EAAE,KAAoB,EAAE,GAAkB,EAAE,IAAY,EAAE,UAAkB,EAAE,OAAe,EAAE,SAAkB,EAAE,MAAe;QACzK,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAEM,MAAM,CAAC,aAAa,CAAC,KAA4B;QACpD,OAAO,IAAI,yBAAyB,CAChC,KAAK,CAAC,EAAE,EACR,KAAK,CAAC,WAAW,EACjB,KAAK,CAAC,KAAK,EACX,KAAK,CAAC,GAAG,EACT,KAAK,CAAC,SAAS,EACf,KAAK,CAAC,eAAe,EACrB,KAAK,CAAC,OAAO,EACb,KAAK,CAAC,WAAW,EACjB,KAAK,CAAC,QAAQ,CACjB,CAAC;IACN,CAAC;CACJ","sourcesContent":["import type DownloadFileChunkInfo from \"../dtos/downloadFileChunkInfo.js\";\r\n\r\nexport default class DownloadFileChunkProgress {\r\n id: string;\r\n chunkNumber: number;\r\n start: number | null;\r\n end: number | null;\r\n size: number;\r\n downloaded: number;\r\n percent: number;\r\n completed: boolean;\r\n failed: boolean;\r\n\r\n constructor(id: string, chunkNumber: number, start: number | null, end: number | null, size: number, downloaded: number, percent: number, completed: boolean, failed: boolean) {\r\n this.id = id;\r\n this.chunkNumber = chunkNumber;\r\n this.start = start;\r\n this.end = end;\r\n this.size = size;\r\n this.downloaded = downloaded;\r\n this.percent = percent;\r\n this.completed = completed;\r\n this.failed = failed;\r\n }\r\n\r\n public static FromChunkInfo(chunk: DownloadFileChunkInfo): DownloadFileChunkProgress {\r\n return new DownloadFileChunkProgress(\r\n chunk.id,\r\n chunk.chunkNumber,\r\n chunk.start,\r\n chunk.end,\r\n chunk.chunkSize,\r\n chunk.downloadedBytes,\r\n chunk.percent,\r\n chunk.isCompleted,\r\n chunk.isFailed,\r\n );\r\n }\r\n}"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"downloadFileProgress.js","sourceRoot":"","sources":["../../../../src/downloader/downloadStatus/downloadFileProgress.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,OAAO,oBAAoB;IACrC,EAAE,CAAS;IACX,IAAI,CAAS;IACb,GAAG,CAAS;IACZ,YAAY,CAAS;IACrB,qBAAqB,CAAgB;IACrC,OAAO,CAAS;IAChB,UAAU,CAAS;IACnB,IAAI,CAAS;IACb,SAAS,CAAU;IACnB,MAAM,CAAU;IAChB,QAAQ,GAAyB,EA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ACN,CAAC;CACJ","sourcesContent":["import type DownloadError from \"../dtos/downloadError.js\";\nimport type DownloadFileInfo from \"../dtos/downloadFileInfo.js\";\n\nexport default class DownloadFileProgress {\n id: string;\n name: string;\n url: string;\n downloadPath: string;\n temporaryDownloadPath: string | null;\n percent: number;\n downloaded: number;\n size: number;\n completed: boolean;\n failed: boolean;\n failures: Array<DownloadError> = [];\n chunks: number;\n lastOkChunk: number | null;\n\n constructor(\n externalId: string,\n name: string,\n url: string,\n downloadPath: string,\n temporaryDownloadPath: string | null,\n size: number,\n downloaded: number,\n percent: number,\n completed: boolean,\n failed: boolean,\n failures: Array<DownloadError> | null,\n numberOfChunks: number,\n lastSuccessfulChunk: number | null,\n ) {\n this.id = externalId;\n this.name = name;\n this.url = url;\n this.downloadPath = downloadPath;\n this.temporaryDownloadPath = temporaryDownloadPath;\n this.size = size;\n this.downloaded = downloaded;\n this.percent = percent;\n this.completed = completed;\n this.failed = failed;\n this.chunks = numberOfChunks;\n this.lastOkChunk = lastSuccessfulChunk;\n if (failures)\n this.failures = failures.slice();\n }\n\n public static FromFileDownloadInfo(file: DownloadFileInfo): DownloadFileProgress {\n return new DownloadFileProgress(\n file.externalId,\n file.name,\n file.url,\n file.downloadPath,\n file.temporaryDownloadPath,\n file.sizeInBytes,\n file.downloadedBytes,\n file.percent,\n file.isCompleted,\n file.isFailed,\n file.failures,\n file.chunks.length,\n file.lastSuccessfulChunkNumber,\n );\n }\n}"]}
|
|
1
|
+
{"version":3,"file":"downloadFileProgress.js","sourceRoot":"","sources":["../../../../src/downloader/downloadStatus/downloadFileProgress.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,OAAO,oBAAoB;IACrC,EAAE,CAAS;IACX,IAAI,CAAS;IACb,GAAG,CAAS;IACZ,YAAY,CAAS;IACrB,qBAAqB,CAAgB;IACrC,OAAO,CAAS;IAChB,UAAU,CAAS;IACnB,IAAI,CAAS;IACb,SAAS,CAAU;IACnB,MAAM,CAAU;IAChB,QAAQ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ACjC,CAAC;IACN,CAAC;CACJ","sourcesContent":["import type DownloadError from \"../dtos/downloadError.js\";\r\nimport type DownloadFileInfo from \"../dtos/downloadFileInfo.js\";\r\n\r\nexport default class DownloadFileProgress {\r\n id: string;\r\n name: string;\r\n url: string;\r\n downloadPath: string;\r\n temporaryDownloadPath: string | null;\r\n percent: number;\r\n downloaded: number;\r\n size: number;\r\n completed: boolean;\r\n failed: boolean;\r\n failures: Array<DownloadError> = [];\r\n chunks: number;\r\n lastOkChunk: number | null;\r\n\r\n constructor(\r\n externalId: string,\r\n name: string,\r\n url: string,\r\n downloadPath: string,\r\n temporaryDownloadPath: string | null,\r\n size: number,\r\n downloaded: number,\r\n percent: number,\r\n completed: boolean,\r\n failed: boolean,\r\n failures: Array<DownloadError> | null,\r\n numberOfChunks: number,\r\n lastSuccessfulChunk: number | null,\r\n ) {\r\n this.id = externalId;\r\n this.name = name;\r\n this.url = url;\r\n this.downloadPath = downloadPath;\r\n this.temporaryDownloadPath = temporaryDownloadPath;\r\n this.size = size;\r\n this.downloaded = downloaded;\r\n this.percent = percent;\r\n this.completed = completed;\r\n this.failed = failed;\r\n this.chunks = numberOfChunks;\r\n this.lastOkChunk = lastSuccessfulChunk;\r\n if (failures)\r\n this.failures = failures.slice();\r\n }\r\n\r\n public static FromFileDownloadInfo(file: DownloadFileInfo): DownloadFileProgress {\r\n return new DownloadFileProgress(\r\n file.externalId,\r\n file.name,\r\n file.url,\r\n file.downloadPath,\r\n file.temporaryDownloadPath,\r\n file.sizeInBytes,\r\n file.downloadedBytes,\r\n file.percent,\r\n file.isCompleted,\r\n file.isFailed,\r\n file.failures,\r\n file.chunks.length,\r\n file.lastSuccessfulChunkNumber,\r\n );\r\n }\r\n}"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"downloadFilePromise.js","sourceRoot":"","sources":["../../../../src/downloader/downloadStatus/downloadFilePromise.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,mBAAmB;IACpC,OAAO,CAAS;IAChB,QAAQ,CAAkB;IAC1B,QAAQ,GAAgE,SAAS,CAAC;IAElF,YAAY,MAAc;QACtB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,QAAQ,GAAG,IAAI,OAAO,CAAS,OAAO,CAAC,EAAE;YAC1C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QAC5B,CAAC,CAAC,CAAC;IACP,CAAC;IAED,QAAQ;QACJ,IAAI,CAAC,QAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;IAED,IAAI,OAAO;QACP,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;CACJ","sourcesContent":["export default class DownloadFilePromise {\n #fileId: string;\n #promise: Promise<string>;\n #resolve: ((value: string | PromiseLike<string>) => void) | undefined = undefined;\n\n constructor(fileId: string) {\n this.#fileId = fileId;\n this.#promise = new Promise<string>(resolve => {\n this.#resolve = resolve;\n });\n }\n\n complete(): void {\n this.#resolve!(this.#fileId);\n }\n\n get awaiter(): Promise<string> {\n return this.#promise;\n }\n}"]}
|
|
1
|
+
{"version":3,"file":"downloadFilePromise.js","sourceRoot":"","sources":["../../../../src/downloader/downloadStatus/downloadFilePromise.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,mBAAmB;IACpC,OAAO,CAAS;IAChB,QAAQ,CAAkB;IAC1B,QAAQ,GAAgE,SAAS,CAAC;IAElF,YAAY,MAAc;QACtB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,QAAQ,GAAG,IAAI,OAAO,CAAS,OAAO,CAAC,EAAE;YAC1C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QAC5B,CAAC,CAAC,CAAC;IACP,CAAC;IAED,QAAQ;QACJ,IAAI,CAAC,QAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;IAED,IAAI,OAAO;QACP,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;CACJ","sourcesContent":["export default class DownloadFilePromise {\r\n #fileId: string;\r\n #promise: Promise<string>;\r\n #resolve: ((value: string | PromiseLike<string>) => void) | undefined = undefined;\r\n\r\n constructor(fileId: string) {\r\n this.#fileId = fileId;\r\n this.#promise = new Promise<string>(resolve => {\r\n this.#resolve = resolve;\r\n });\r\n }\r\n\r\n complete(): void {\r\n this.#resolve!(this.#fileId);\r\n }\r\n\r\n get awaiter(): Promise<string> {\r\n return this.#promise;\r\n }\r\n}"]}
|