feat: accept uploads into staging with jobs, outbox and job processor

This commit is contained in:
2026-11-15 15:21:46 +03:00
parent 19dda6e286
commit f4793b50cd
18 changed files with 1657 additions and 95 deletions
+30 -8
View File
@@ -1,4 +1,15 @@
import { Attachment } from '@prisma/client';
import { Attachment, AttachmentVariant } from '@prisma/client';
const VARIANT_ORDER = ['thumbnail', 'crop', 'optimized'];
export interface VariantResponse {
name: string;
content_type: string;
size_bytes: number;
width: number;
height: number;
sha256: string;
}
export interface AttachmentResponse {
id: string;
@@ -8,14 +19,18 @@ export interface AttachmentResponse {
content_type: string;
size_bytes: number;
sha256: string;
status: 'ready';
variants: never[];
error_code: null;
status: string;
variants: VariantResponse[];
error_code: string | null;
created_at: string;
updated_at: string;
}
export function toAttachmentResponse(row: Attachment): AttachmentResponse {
export function toAttachmentResponse(
row: Attachment & { variants: AttachmentVariant[] },
): AttachmentResponse {
const variants = row.status === 'ready' ? [...row.variants] : [];
variants.sort((a, b) => VARIANT_ORDER.indexOf(a.name) - VARIANT_ORDER.indexOf(b.name));
return {
id: row.id,
chat_id: row.chatId,
@@ -24,9 +39,16 @@ export function toAttachmentResponse(row: Attachment): AttachmentResponse {
content_type: row.contentType,
size_bytes: row.sizeBytes,
sha256: row.sha256,
status: 'ready',
variants: [],
error_code: null,
status: row.status,
variants: variants.map((variant) => ({
name: variant.name,
content_type: variant.contentType,
size_bytes: variant.sizeBytes,
width: variant.width,
height: variant.height,
sha256: variant.sha256,
})),
error_code: row.errorCode,
created_at: row.createdAt.toISOString(),
updated_at: row.updatedAt.toISOString(),
};