π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Remove old code
Manav Rathi52130a0f4267
diff --git a/web/packages/new/photos/services/ffmpeg/worker.ts b/web/packages/new/photos/services/ffmpeg/worker.tsdeleted file mode 100644index afcec3f472..0000000000--- a/web/packages/new/photos/services/ffmpeg/worker.ts+++ /dev/null@@ -1,133 +0,0 @@-import log from "@/base/log";-import QueueProcessor from "@ente/shared/utils/queueProcessor";-import { FFmpeg } from "@ffmpeg/ffmpeg";-import { expose } from "comlink";-import {- ffmpegPathPlaceholder,- inputPathPlaceholder,- outputPathPlaceholder,-} from "./constants";--// When we run tsc on CI, the line below errors out-//-// > Error: src/worker/ffmpeg.worker.ts(10,38): error TS2307: Cannot find module-// 'ffmpeg-wasm' or its corresponding type declarations.-//-// Building and running works fine. And this error does not occur when running-// tsc locally either.-//-// Of course, there is some misconfiguration, but we plan to move off our old-// fork and onto upstream ffmpeg-wasm, and the reason can be figured out then.-// For now, disable the error to allow the CI lint to complete.-//-// Note that we can't use @ts-expect-error since it doesn't error out when-// actually building!-//-// eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error-// @ts-ignore--export class DedicatedFFmpegWorker {- private ffmpeg: FFmpeg;- private ffmpegTaskQueue = new QueueProcessor<Uint8Array>();-- constructor() {- this.ffmpeg = new FFmpeg();- }-- /**- * Execute a FFmpeg {@link command} on {@link blob}.- *- * This is a sibling of {@link ffmpegExec} exposed by the desktop app in- * `ipc.ts`. See [Note: FFmpeg in Electron].- */- async exec(- command: string[],- blob: Blob,- outputFileExtension: string,- ): Promise<Uint8Array> {- if (!this.ffmpeg.loaded) {- // This loads @ffmpeg/core from its CDN:- // https://unpkg.com/@ffmpeg/[email protected]/dist/umd/ffmpeg-core.js- // https://unpkg.com/@ffmpeg/[email protected]/dist/umd/ffmpeg-core.wasm- await this.ffmpeg.load();- }-- const request = this.ffmpegTaskQueue.queueUpRequest(() =>- ffmpegExec(this.ffmpeg, command, outputFileExtension, blob),- );-- return await request.promise;- }-}--expose(DedicatedFFmpegWorker, self);--const ffmpegExec = async (- ffmpeg: FFmpeg,- command: string[],- outputFileExtension: string,- blob: Blob,-) => {- const inputPath = randomPrefix();- const outputSuffix = outputFileExtension ? "." + outputFileExtension : "";- const outputPath = randomPrefix() + outputSuffix;-- const cmd = substitutePlaceholders(command, inputPath, outputPath);-- const inputData = new Uint8Array(await blob.arrayBuffer());-- try {- const startTime = Date.now();-- await ffmpeg.writeFile(inputPath, inputData);- await ffmpeg.exec(cmd);-- const result = await ffmpeg.readFile(outputPath);- if (typeof result == "string") throw new Error("Expected binary data");-- const ms = Date.now() - startTime;- log.debug(() => `[wasm] ffmpeg ${cmd.join(" ")} (${ms} ms)`);- return result;- } finally {- try {- ffmpeg.deleteFile(inputPath);- } catch (e) {- log.error(`Failed to remove input ${inputPath}`, e);- }- try {- ffmpeg.deleteFile(outputPath);- } catch (e) {- log.error(`Failed to remove output ${outputPath}`, e);- }- }-};--/** Generate a random string suitable for being used as a file name prefix */-const randomPrefix = () => {- const alphabet =- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";-- let result = "";- for (let i = 0; i < 10; i++)- result += alphabet[Math.floor(Math.random() * alphabet.length)]!;- return result;-};--const substitutePlaceholders = (- command: string[],- inputFilePath: string,- outputFilePath: string,-) =>- command- .map((segment) => {- if (segment == ffmpegPathPlaceholder) {- return undefined;- } else if (segment == inputPathPlaceholder) {- return inputFilePath;- } else if (segment == outputPathPlaceholder) {- return outputFilePath;- } else {- return segment;- }- })- .filter((s) => s !== undefined);diff --git a/web/packages/shared/utils/queueProcessor.ts b/web/packages/shared/utils/queueProcessor.tsdeleted file mode 100644index 0661e34533..0000000000--- a/web/packages/shared/utils/queueProcessor.ts+++ /dev/null@@ -1,68 +0,0 @@-interface RequestQueueItem {- request: (canceller?: RequestCanceller) => Promise<any>;- successCallback: (response: any) => void;- failureCallback: (error: unknown) => void;- isCanceled: { status: boolean };- canceller: { exec: () => void };-}--export interface RequestCanceller {- exec: () => void;-}--export interface CancellationStatus {- status: boolean;-}--export default class QueueProcessor<T> {- private requestQueue: RequestQueueItem[] = [];- private isProcessingRequest = false;-- public queueUpRequest(- request: (canceller?: RequestCanceller) => Promise<T>,- ) {- const isCanceled: CancellationStatus = { status: false };- const canceller: RequestCanceller = {- exec: () => {- isCanceled.status = true;- },- };-- const promise = new Promise<T>((resolve, reject) => {- this.requestQueue.push({- request,- successCallback: resolve,- failureCallback: reject,- isCanceled,- canceller,- });-- this.processQueueIfNeeded();- });-- return { promise, canceller };- }-- private async processQueueIfNeeded() {- if (this.isProcessingRequest) return;- this.isProcessingRequest = true;-- while (this.requestQueue.length > 0) {- const queueItem = this.requestQueue.shift()!;- let response = null;-- if (queueItem.isCanceled.status) {- queueItem.failureCallback(new Error("Request canceled"));- } else {- try {- response = await queueItem.request(queueItem.canceller);- queueItem.successCallback(response);- } catch (e) {- queueItem.failureCallback(e);- }- }- }-- this.isProcessingRequest = false;- }-}