WIP: hacks to ignore dom access from web worker
This commit is contained in:
parent
15d41d5ef8
commit
15707f8344
|
@ -10,15 +10,15 @@ class DownloadManager {
|
||||||
private fileObjectUrlPromise = new Map<string, Promise<string>>();
|
private fileObjectUrlPromise = new Map<string, Promise<string>>();
|
||||||
private thumbnailObjectUrlPromise = new Map<number, Promise<string>>();
|
private thumbnailObjectUrlPromise = new Map<number, Promise<string>>();
|
||||||
|
|
||||||
public async getPreview(file: File) {
|
public async getPreview(file: File, tokenOverride?: string) {
|
||||||
try {
|
try {
|
||||||
const token = getToken();
|
const token = tokenOverride || getToken();
|
||||||
if (!token) {
|
if (!token) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const thumbnailCache = await caches.open('thumbs');
|
const thumbnailCache = await caches.open('thumbs');
|
||||||
const cacheResp: Response = await thumbnailCache.match(
|
const cacheResp: Response = await thumbnailCache.match(
|
||||||
file.id.toString()
|
'/' + file.id.toString()
|
||||||
);
|
);
|
||||||
if (cacheResp) {
|
if (cacheResp) {
|
||||||
return URL.createObjectURL(await cacheResp.blob());
|
return URL.createObjectURL(await cacheResp.blob());
|
||||||
|
@ -47,7 +47,7 @@ class DownloadManager {
|
||||||
const thumb = await this.getThumbnail(token, file);
|
const thumb = await this.getThumbnail(token, file);
|
||||||
try {
|
try {
|
||||||
await thumbnailCache.put(
|
await thumbnailCache.put(
|
||||||
file.id.toString(),
|
'/' + file.id.toString(),
|
||||||
new Response(new Blob([thumb]))
|
new Response(new Blob([thumb]))
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -75,7 +75,7 @@ class MlService {
|
||||||
throw Error('Token needed by ml service to sync file');
|
throw Error('Token needed by ml service to sync file');
|
||||||
}
|
}
|
||||||
|
|
||||||
const fileUrl = await DownloadManager.getPreview(file);
|
const fileUrl = await DownloadManager.getPreview(file, token);
|
||||||
console.log('[MLService] Got thumbnail: ', file.id.toString(), fileUrl);
|
console.log('[MLService] Got thumbnail: ', file.id.toString(), fileUrl);
|
||||||
|
|
||||||
const thumbFile = await fetch(fileUrl);
|
const thumbFile = await fetch(fileUrl);
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { FILE_TYPE } from 'services/fileService';
|
||||||
import { CustomError, errorWithContext } from 'utils/common/errorUtil';
|
import { CustomError, errorWithContext } from 'utils/common/errorUtil';
|
||||||
import { logError } from 'utils/sentry';
|
import { logError } from 'utils/sentry';
|
||||||
import { BLACK_THUMBNAIL_BASE64 } from '../../../public/images/black-thumbnail-b64';
|
import { BLACK_THUMBNAIL_BASE64 } from '../../../public/images/black-thumbnail-b64';
|
||||||
import FFmpegService from 'services/ffmpegService';
|
// import FFmpegService from 'services/ffmpegService';
|
||||||
import { convertToHumanReadable } from 'utils/billingUtil';
|
import { convertToHumanReadable } from 'utils/billingUtil';
|
||||||
import { fileIsHEIC } from 'utils/file';
|
import { fileIsHEIC } from 'utils/file';
|
||||||
import { FileTypeInfo } from './readFileService';
|
import { FileTypeInfo } from './readFileService';
|
||||||
|
@ -34,20 +34,20 @@ export async function generateThumbnail(
|
||||||
const isHEIC = fileIsHEIC(fileTypeInfo.exactType);
|
const isHEIC = fileIsHEIC(fileTypeInfo.exactType);
|
||||||
canvas = await generateImageThumbnail(worker, file, isHEIC);
|
canvas = await generateImageThumbnail(worker, file, isHEIC);
|
||||||
} else {
|
} else {
|
||||||
try {
|
// try {
|
||||||
const thumb = await FFmpegService.generateThumbnail(file);
|
// const thumb = await FFmpegService.generateThumbnail(file);
|
||||||
const dummyImageFile = new File([thumb], file.name);
|
// const dummyImageFile = new File([thumb], file.name);
|
||||||
canvas = await generateImageThumbnail(
|
// canvas = await generateImageThumbnail(
|
||||||
worker,
|
// worker,
|
||||||
dummyImageFile,
|
// dummyImageFile,
|
||||||
false
|
// false
|
||||||
);
|
// );
|
||||||
} catch (e) {
|
// } catch (e) {
|
||||||
logError(e, 'failed to generate thumbnail using ffmpeg', {
|
// logError(e, 'failed to generate thumbnail using ffmpeg', {
|
||||||
type: fileTypeInfo.exactType,
|
// type: fileTypeInfo.exactType,
|
||||||
});
|
// });
|
||||||
canvas = await generateVideoThumbnail(file);
|
canvas = await generateVideoThumbnail(file);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
const thumbnailBlob = await thumbnailCanvasToBlob(canvas);
|
const thumbnailBlob = await thumbnailCanvasToBlob(canvas);
|
||||||
thumbnail = await worker.getUint8ArrayView(thumbnailBlob);
|
thumbnail = await worker.getUint8ArrayView(thumbnailBlob);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { runningInBrowser } from 'utils/common';
|
// import { runningInBrowser } from 'utils/common';
|
||||||
import englishConstants from './englishConstants';
|
import englishConstants from './englishConstants';
|
||||||
|
|
||||||
/** Enums of supported locale */
|
/** Enums of supported locale */
|
||||||
|
@ -64,7 +64,7 @@ const globalConstants: VernacularConstants<typeof englishConstants> = {
|
||||||
* @param localConstants
|
* @param localConstants
|
||||||
*/
|
*/
|
||||||
export function getConstantValue<T>(localConstants?: VernacularConstants<T>) {
|
export function getConstantValue<T>(localConstants?: VernacularConstants<T>) {
|
||||||
const searchParam = runningInBrowser() ? window.location.search : '';
|
const searchParam = '';
|
||||||
const query = new URLSearchParams(searchParam);
|
const query = new URLSearchParams(searchParam);
|
||||||
const currLocale = getLocale(query.get('lang'));
|
const currLocale = getLocale(query.get('lang'));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue