refactor(worker): Move blurhash processing to worker

This commit is contained in:
Jesse Wierzbinski 2025-01-06 19:45:32 +01:00
parent 8188a6ffc7
commit b086e65404
No known key found for this signature in database
8 changed files with 34 additions and 37 deletions

View file

@ -86,7 +86,6 @@ describe("MediaManager", () => {
uploadedFile: new File(["hey"], "test.webp"),
path: "test/test.webp",
hash: "testhash",
blurhash: null,
});
});

View file

@ -7,7 +7,6 @@ import type { Config } from "~/packages/config-manager/config.type";
import { DiskMediaDriver } from "./drivers/disk.ts";
import type { MediaDriver } from "./drivers/media-driver.ts";
import { S3MediaDriver } from "./drivers/s3.ts";
import { BlurhashPreprocessor } from "./preprocessors/blurhash.ts";
import type { MediaPreprocessor } from "./preprocessors/media-preprocessor.ts";
/**
@ -33,7 +32,6 @@ export class MediaManager {
*/
public constructor(private config: Config) {
this.driver = this.initializeDriver();
this.initializePreprocessors();
}
/**
@ -53,14 +51,6 @@ export class MediaManager {
}
}
/**
* Initializes the preprocessors based on the configuration.
*/
private initializePreprocessors(): void {
this.preprocessors.push(new BlurhashPreprocessor());
// Add other preprocessors here as needed
}
/**
* Adds a file to the media storage.
* @param file - The file to add.
@ -68,21 +58,16 @@ export class MediaManager {
*/
public async addFile(file: File): Promise<UploadedFileMetadata> {
let processedFile = file;
let blurhash: string | null = null;
for (const preprocessor of this.preprocessors) {
const result = await preprocessor.process(processedFile);
if ("blurhash" in result) {
blurhash = result.blurhash as string;
}
processedFile = result.file;
}
const uploadResult = await this.driver.addFile(processedFile);
return { ...uploadResult, blurhash };
return uploadResult;
}
/**
* Retrieves a file from the media storage by its hash.
@ -123,5 +108,4 @@ export interface UploadedFileMetadata {
uploadedFile: File;
path: string;
hash: string;
blurhash: string | null;
}