fix and update

This commit is contained in:
lendry
2026-07-01 23:27:48 +03:00
parent 2b88e028c6
commit bcdfbc3861
36 changed files with 1504 additions and 320 deletions

View File

@@ -290,9 +290,34 @@ export function parseDocumentPhotos(metadata: Record<string, unknown>): string[]
return [];
}
export function withDocumentPhotos(metadata: Record<string, unknown>, photoStorageKeys: string[]) {
export type DocumentAttachmentMeta = {
fileName?: string;
contentType?: string;
};
export function parseAttachmentMeta(metadata: Record<string, unknown>): Record<string, DocumentAttachmentMeta> {
const raw = metadata.attachmentMeta;
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
return {};
}
const result: Record<string, DocumentAttachmentMeta> = {};
for (const [key, value] of Object.entries(raw as Record<string, unknown>)) {
if (!value || typeof value !== 'object' || Array.isArray(value)) continue;
const entry = value as Record<string, unknown>;
result[key] = {
fileName: typeof entry.fileName === 'string' ? entry.fileName : undefined,
contentType: typeof entry.contentType === 'string' ? entry.contentType : undefined
};
}
return result;
}
export function withDocumentPhotos(metadata: Record<string, unknown>, photoStorageKeys: string[], attachmentMeta?: Record<string, DocumentAttachmentMeta>) {
const next: Record<string, unknown> = { ...metadata, photoStorageKeys };
delete next.photoStorageKey;
if (attachmentMeta && Object.keys(attachmentMeta).length > 0) {
next.attachmentMeta = attachmentMeta;
}
return next;
}