fix and update
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user