|
@@ -1,5 +1,5 @@
|
|
|
import { getToken } from 'utils/common/key';
|
|
|
-import { getFileUrl, getThumbnailUrl } from 'utils/common/apiUtil';
|
|
|
+import { getFileURL, getThumbnailURL } from 'utils/common/apiUtil';
|
|
|
import CryptoWorker from 'utils/crypto';
|
|
|
import {
|
|
|
generateStreamFromArrayBuffer,
|
|
@@ -13,8 +13,8 @@ import { logError } from 'utils/sentry';
|
|
|
import { FILE_TYPE } from 'constants/file';
|
|
|
|
|
|
class DownloadManager {
|
|
|
- private fileObjectUrlPromise = new Map<string, Promise<string>>();
|
|
|
- private thumbnailObjectUrlPromise = new Map<number, Promise<string>>();
|
|
|
+ private fileObjectURLPromise = new Map<string, Promise<string>>();
|
|
|
+ private thumbnailObjectURLPromise = new Map<number, Promise<string>>();
|
|
|
|
|
|
public async getThumbnail(file: EnteFile) {
|
|
|
try {
|
|
@@ -22,7 +22,7 @@ class DownloadManager {
|
|
|
if (!token) {
|
|
|
return null;
|
|
|
}
|
|
|
- if (!this.thumbnailObjectUrlPromise.get(file.id)) {
|
|
|
+ if (!this.thumbnailObjectURLPromise.get(file.id)) {
|
|
|
const downloadPromise = async () => {
|
|
|
const thumbnailCache = await caches.open('thumbs');
|
|
|
const cacheResp: Response = await thumbnailCache.match(
|
|
@@ -43,12 +43,12 @@ class DownloadManager {
|
|
|
}
|
|
|
return URL.createObjectURL(thumbBlob);
|
|
|
};
|
|
|
- this.thumbnailObjectUrlPromise.set(file.id, downloadPromise());
|
|
|
+ this.thumbnailObjectURLPromise.set(file.id, downloadPromise());
|
|
|
}
|
|
|
|
|
|
- return await this.thumbnailObjectUrlPromise.get(file.id);
|
|
|
+ return await this.thumbnailObjectURLPromise.get(file.id);
|
|
|
} catch (e) {
|
|
|
- this.thumbnailObjectUrlPromise.delete(file.id);
|
|
|
+ this.thumbnailObjectURLPromise.delete(file.id);
|
|
|
logError(e, 'get preview Failed');
|
|
|
throw e;
|
|
|
}
|
|
@@ -56,7 +56,7 @@ class DownloadManager {
|
|
|
|
|
|
downloadThumb = async (token: string, file: EnteFile) => {
|
|
|
const resp = await HTTPService.get(
|
|
|
- getThumbnailUrl(file.id),
|
|
|
+ getThumbnailURL(file.id),
|
|
|
null,
|
|
|
{ 'X-Auth-Token': token },
|
|
|
{ responseType: 'arraybuffer' }
|
|
@@ -84,23 +84,23 @@ class DownloadManager {
|
|
|
}
|
|
|
return URL.createObjectURL(fileBlob);
|
|
|
};
|
|
|
- if (!this.fileObjectUrlPromise.get(fileKey)) {
|
|
|
- this.fileObjectUrlPromise.set(
|
|
|
+ if (!this.fileObjectURLPromise.get(fileKey)) {
|
|
|
+ this.fileObjectURLPromise.set(
|
|
|
fileKey,
|
|
|
getFilePromise(shouldBeConverted)
|
|
|
);
|
|
|
}
|
|
|
- const fileURL = await this.fileObjectUrlPromise.get(fileKey);
|
|
|
+ const fileURL = await this.fileObjectURLPromise.get(fileKey);
|
|
|
return fileURL;
|
|
|
} catch (e) {
|
|
|
- this.fileObjectUrlPromise.delete(fileKey);
|
|
|
+ this.fileObjectURLPromise.delete(fileKey);
|
|
|
logError(e, 'Failed to get File');
|
|
|
throw e;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
public async getCachedOriginalFile(file: EnteFile) {
|
|
|
- return await this.fileObjectUrlPromise.get(file.id.toString());
|
|
|
+ return await this.fileObjectURLPromise.get(file.id.toString());
|
|
|
}
|
|
|
|
|
|
async downloadFile(file: EnteFile) {
|
|
@@ -114,7 +114,7 @@ class DownloadManager {
|
|
|
file.metadata.fileType === FILE_TYPE.LIVE_PHOTO
|
|
|
) {
|
|
|
const resp = await HTTPService.get(
|
|
|
- getFileUrl(file.id),
|
|
|
+ getFileURL(file.id),
|
|
|
null,
|
|
|
{ 'X-Auth-Token': token },
|
|
|
{ responseType: 'arraybuffer' }
|
|
@@ -126,7 +126,7 @@ class DownloadManager {
|
|
|
);
|
|
|
return generateStreamFromArrayBuffer(decrypted);
|
|
|
}
|
|
|
- const resp = await fetch(getFileUrl(file.id), {
|
|
|
+ const resp = await fetch(getFileURL(file.id), {
|
|
|
headers: {
|
|
|
'X-Auth-Token': token,
|
|
|
},
|