WIP: hacks to ignore dom access from web worker

This commit is contained in:
Shailesh Pandit 2021-11-04 17:25:49 +05:30
parent 15d41d5ef8
commit 15707f8344
4 changed files with 22 additions and 22 deletions

View file

@ -10,15 +10,15 @@ class DownloadManager {
private fileObjectUrlPromise = new Map<string, Promise<string>>();
private thumbnailObjectUrlPromise = new Map<number, Promise<string>>();
public async getPreview(file: File) {
public async getPreview(file: File, tokenOverride?: string) {
try {
const token = getToken();
const token = tokenOverride || getToken();
if (!token) {
return null;
}
const thumbnailCache = await caches.open('thumbs');
const cacheResp: Response = await thumbnailCache.match(
file.id.toString()
'/' + file.id.toString()
);
if (cacheResp) {
return URL.createObjectURL(await cacheResp.blob());
@ -47,7 +47,7 @@ class DownloadManager {
const thumb = await this.getThumbnail(token, file);
try {
await thumbnailCache.put(
file.id.toString(),
'/' + file.id.toString(),
new Response(new Blob([thumb]))
);
} catch (e) {

View file

@ -75,7 +75,7 @@ class MlService {
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);
const thumbFile = await fetch(fileUrl);

View file

@ -2,7 +2,7 @@ import { FILE_TYPE } from 'services/fileService';
import { CustomError, errorWithContext } from 'utils/common/errorUtil';
import { logError } from 'utils/sentry';
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 { fileIsHEIC } from 'utils/file';
import { FileTypeInfo } from './readFileService';
@ -34,20 +34,20 @@ export async function generateThumbnail(
const isHEIC = fileIsHEIC(fileTypeInfo.exactType);
canvas = await generateImageThumbnail(worker, file, isHEIC);
} else {
try {
const thumb = await FFmpegService.generateThumbnail(file);
const dummyImageFile = new File([thumb], file.name);
canvas = await generateImageThumbnail(
worker,
dummyImageFile,
false
);
} catch (e) {
logError(e, 'failed to generate thumbnail using ffmpeg', {
type: fileTypeInfo.exactType,
});
canvas = await generateVideoThumbnail(file);
}
// try {
// const thumb = await FFmpegService.generateThumbnail(file);
// const dummyImageFile = new File([thumb], file.name);
// canvas = await generateImageThumbnail(
// worker,
// dummyImageFile,
// false
// );
// } catch (e) {
// logError(e, 'failed to generate thumbnail using ffmpeg', {
// type: fileTypeInfo.exactType,
// });
canvas = await generateVideoThumbnail(file);
// }
}
const thumbnailBlob = await thumbnailCanvasToBlob(canvas);
thumbnail = await worker.getUint8ArrayView(thumbnailBlob);

View file

@ -1,4 +1,4 @@
import { runningInBrowser } from 'utils/common';
// import { runningInBrowser } from 'utils/common';
import englishConstants from './englishConstants';
/** Enums of supported locale */
@ -64,7 +64,7 @@ const globalConstants: VernacularConstants<typeof englishConstants> = {
* @param localConstants
*/
export function getConstantValue<T>(localConstants?: VernacularConstants<T>) {
const searchParam = runningInBrowser() ? window.location.search : '';
const searchParam = '';
const query = new URLSearchParams(searchParam);
const currLocale = getLocale(query.get('lang'));