5c2c588885
As attachment files have migrated from fullPath to file files field, need to migrate richText logic to fit to new attachment file handling + data migration
33 lines
909 B
TypeScript
33 lines
909 B
TypeScript
export const getAttachmentPath = (attachmentFullPath: string) => {
|
|
if (attachmentFullPath.includes('/files-field/')) {
|
|
return attachmentFullPath?.split('?')[0];
|
|
}
|
|
|
|
if (!attachmentFullPath.includes('/files/')) {
|
|
return attachmentFullPath?.split('?')[0];
|
|
}
|
|
|
|
const base = attachmentFullPath?.split('/files/')[0];
|
|
const rawPath = attachmentFullPath?.split('/files/')[1]?.split('?')[0];
|
|
|
|
if (!rawPath) {
|
|
throw new Error(`Invalid attachment path: ${attachmentFullPath}`);
|
|
}
|
|
|
|
if (!rawPath.startsWith('attachment/')) {
|
|
return attachmentFullPath?.split('?')[0];
|
|
}
|
|
|
|
const pathParts = rawPath.split('/');
|
|
if (pathParts.length < 2) {
|
|
throw new Error(
|
|
`Invalid attachment path structure: ${rawPath}. Path must have at least two segments.`,
|
|
);
|
|
}
|
|
const filename = pathParts.pop();
|
|
|
|
pathParts.pop();
|
|
|
|
return `${base}/files/${pathParts.join('/')}/${filename}`;
|
|
};
|