From be45cc3fa7f49cd4f526734f503036bbbe47bc1b Mon Sep 17 00:00:00 2001 From: user Date: Mon, 2 Mar 2026 19:23:59 +0200 Subject: [PATCH] resolved type errors and other proc. app build error --- apps/processor/package.json | 2 +- dockerfiles/processor.Dockerfile | 1 + packages/objectstorage/src/client.ts | 6 ++++-- packages/objectstorage/src/data.ts | 12 +++++++++--- .../src/processors/document-processor.ts | 16 ++++++++++------ .../src/processors/image-processor.ts | 8 +++++--- .../src/processors/video-processor.ts | 4 ++-- 7 files changed, 32 insertions(+), 17 deletions(-) diff --git a/apps/processor/package.json b/apps/processor/package.json index b98581c..35de6ad 100644 --- a/apps/processor/package.json +++ b/apps/processor/package.json @@ -4,7 +4,7 @@ "scripts": { "dev": "tsx watch src/index.ts", "build": "tsc", - "prod": "tsc && node dist/index.js" + "prod": "node dist/index.js" }, "dependencies": { "@opentelemetry/api": "^1.9.0", diff --git a/dockerfiles/processor.Dockerfile b/dockerfiles/processor.Dockerfile index b6047be..43c403d 100644 --- a/dockerfiles/processor.Dockerfile +++ b/dockerfiles/processor.Dockerfile @@ -17,6 +17,7 @@ RUN pnpm install COPY apps/processor ./apps/processor RUN pnpm install +RUN pnpm run build COPY scripts ./scripts diff --git a/packages/objectstorage/src/client.ts b/packages/objectstorage/src/client.ts index bf2c5fc..ef9da4b 100644 --- a/packages/objectstorage/src/client.ts +++ b/packages/objectstorage/src/client.ts @@ -4,6 +4,7 @@ import { GetObjectCommand, HeadObjectCommand, ListObjectsV2Command, + type ListObjectsV2CommandOutput, PutObjectCommand, S3Client, } from "@aws-sdk/client-s3"; @@ -493,13 +494,14 @@ export class R2StorageClient { let continuationToken: string | undefined = undefined; do { - const command = new ListObjectsV2Command({ + const command: ListObjectsV2Command = new ListObjectsV2Command({ Bucket: this.config.bucketName, Prefix: prefix, ContinuationToken: continuationToken, }); - const response = await this.s3Client.send(command); + const response: ListObjectsV2CommandOutput = + await this.s3Client.send(command); const pageKeys = response.Contents?.map((item) => item.Key).filter( (key): key is string => Boolean(key), diff --git a/packages/objectstorage/src/data.ts b/packages/objectstorage/src/data.ts index 77cc6a3..d9f1760 100644 --- a/packages/objectstorage/src/data.ts +++ b/packages/objectstorage/src/data.ts @@ -108,9 +108,15 @@ export const fileProcessingResultSchema = v.object({ metadata: v.optional(v.record(v.string(), v.any())), error: v.optional(v.string()), }); -export type FileProcessingResult = v.InferOutput< - typeof fileProcessingResultSchema ->; +export type BinaryFileData = Uint8Array; +export type FileProcessingResult = { + processed: boolean; + originalFile?: BinaryFileData; + processedFile?: BinaryFileData; + thumbnail?: BinaryFileData; + metadata?: Record; + error?: string; +}; // File Security Result Schema (from utils.ts) export const fileSecurityResultSchema = v.object({ diff --git a/packages/objectstorage/src/processors/document-processor.ts b/packages/objectstorage/src/processors/document-processor.ts index 578999d..f40c27a 100644 --- a/packages/objectstorage/src/processors/document-processor.ts +++ b/packages/objectstorage/src/processors/document-processor.ts @@ -1,6 +1,10 @@ import { createHash } from "crypto"; import type { DocumentProcessingOptions, FileProcessingResult } from "../data"; +function asByteArray(input: Buffer | Uint8Array): Uint8Array { + return Uint8Array.from(input); +} + /** * Process documents (PDF, text files, etc.) */ @@ -78,8 +82,8 @@ async function processPDF( return { processed: true, - originalFile: buffer, - processedFile: buffer, // PDFs typically don't need processing + originalFile: asByteArray(buffer), + processedFile: asByteArray(buffer), // PDFs typically don't need processing metadata, }; } @@ -108,8 +112,8 @@ async function processTextFile( return { processed: true, - originalFile: buffer, - processedFile: buffer, + originalFile: asByteArray(buffer), + processedFile: asByteArray(buffer), metadata, }; } @@ -125,8 +129,8 @@ async function processGenericDocument( return { processed: true, - originalFile: buffer, - processedFile: buffer, + originalFile: asByteArray(buffer), + processedFile: asByteArray(buffer), metadata, }; } diff --git a/packages/objectstorage/src/processors/image-processor.ts b/packages/objectstorage/src/processors/image-processor.ts index d4f6c84..ca125b8 100644 --- a/packages/objectstorage/src/processors/image-processor.ts +++ b/packages/objectstorage/src/processors/image-processor.ts @@ -145,9 +145,11 @@ export async function processImage( return { processed: true, - originalFile: inputBuffer, - processedFile: processedBuffer, - thumbnail: thumbnailBuffer, + originalFile: Uint8Array.from(inputBuffer), + processedFile: Uint8Array.from(processedBuffer), + thumbnail: thumbnailBuffer + ? Uint8Array.from(thumbnailBuffer) + : undefined, metadata, }; } catch (error) { diff --git a/packages/objectstorage/src/processors/video-processor.ts b/packages/objectstorage/src/processors/video-processor.ts index 2b31321..c814a1d 100644 --- a/packages/objectstorage/src/processors/video-processor.ts +++ b/packages/objectstorage/src/processors/video-processor.ts @@ -49,8 +49,8 @@ export async function processVideo( return { processed: true, - originalFile: inputBuffer, - processedFile: inputBuffer, // Videos are typically not re-encoded during upload + originalFile: Uint8Array.from(inputBuffer), + processedFile: Uint8Array.from(inputBuffer), // Videos are typically not re-encoded during upload metadata, }; } catch (error) {