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 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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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'));
|
||||
|
||||
|
|
Loading…
Reference in a new issue