|
|
@ -8,7 +8,7 @@ import { logger, LogLevels } from "../logger"; |
|
|
|
import { InputFileLocation, FileLocation, UploadFile } from "../../types"; |
|
|
|
import { InputFileLocation, FileLocation, UploadFile } from "../../types"; |
|
|
|
import { isSafari } from "../../helpers/userAgent"; |
|
|
|
import { isSafari } from "../../helpers/userAgent"; |
|
|
|
import cryptoWorker from "../crypto/cryptoworker"; |
|
|
|
import cryptoWorker from "../crypto/cryptoworker"; |
|
|
|
import { notifySomeone } from "../../helpers/context"; |
|
|
|
import { notifySomeone, notifyAll } from "../../helpers/context"; |
|
|
|
|
|
|
|
|
|
|
|
type Delayed = { |
|
|
|
type Delayed = { |
|
|
|
offset: number, |
|
|
|
offset: number, |
|
|
@ -26,6 +26,8 @@ export type DownloadOptions = { |
|
|
|
processPart?: (bytes: Uint8Array, offset?: number, queue?: Delayed[]) => Promise<any> |
|
|
|
processPart?: (bytes: Uint8Array, offset?: number, queue?: Delayed[]) => Promise<any> |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const MAX_FILE_SAVE_SIZE = 20e6; |
|
|
|
|
|
|
|
|
|
|
|
export class ApiFileManager { |
|
|
|
export class ApiFileManager { |
|
|
|
public cachedDownloadPromises: { |
|
|
|
public cachedDownloadPromises: { |
|
|
|
[fileName: string]: CancellablePromise<Blob> |
|
|
|
[fileName: string]: CancellablePromise<Blob> |
|
|
@ -334,14 +336,14 @@ export class ApiFileManager { |
|
|
|
//done += limit;
|
|
|
|
//done += limit;
|
|
|
|
done += result.bytes.byteLength; |
|
|
|
done += result.bytes.byteLength; |
|
|
|
|
|
|
|
|
|
|
|
const processedResult = await processDownloaded(result.bytes, offset); |
|
|
|
|
|
|
|
checkCancel(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//if(!isFinal) {
|
|
|
|
//if(!isFinal) {
|
|
|
|
////this.log('deferred notify 2:', {done: offset + limit, total: size}, deferred);
|
|
|
|
////this.log('deferred notify 2:', {done: offset + limit, total: size}, deferred);
|
|
|
|
deferred.notify({done, offset, total: size}); |
|
|
|
deferred.notify({done, offset, total: size}); |
|
|
|
//}
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const processedResult = await processDownloaded(result.bytes, offset); |
|
|
|
|
|
|
|
checkCancel(); |
|
|
|
|
|
|
|
|
|
|
|
await writeFilePromise; |
|
|
|
await writeFilePromise; |
|
|
|
checkCancel(); |
|
|
|
checkCancel(); |
|
|
|
|
|
|
|
|
|
|
@ -356,7 +358,7 @@ export class ApiFileManager { |
|
|
|
if(options.processPart) { |
|
|
|
if(options.processPart) { |
|
|
|
deferred.resolve(); |
|
|
|
deferred.resolve(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
deferred.resolve(fileWriter.finalize()); |
|
|
|
deferred.resolve(fileWriter.finalize(size < MAX_FILE_SAVE_SIZE)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} catch(err) { |
|
|
|
} catch(err) { |
|
|
@ -384,6 +386,10 @@ export class ApiFileManager { |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
deferred.notify = (progress: {done: number, total: number, offset: number}) => { |
|
|
|
|
|
|
|
notifyAll({progress: {fileName, ...progress}}); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
this.cachedDownloadPromises[fileName] = deferred; |
|
|
|
this.cachedDownloadPromises[fileName] = deferred; |
|
|
|
|
|
|
|
|
|
|
|
return deferred; |
|
|
|
return deferred; |
|
|
|