resolve #13168 , #8501 This PR fixes an issue where the onChange trigger was deleting all attachments by removing the JWT token from their paths (if it existed) and comparing the new body with the old body to identify deleted attachments. It ensures that only attachments actually removed from the body get deleted, preventing unintended deletion of attachments not added directly through the body. It also handles updating attachment names in the body so changes are reflected in Files, with related tests updated accordingly. https://github.com/user-attachments/assets/8d824a24-b257-4794-942e-3b2dceb9907d --------- Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
29 lines
804 B
TypeScript
29 lines
804 B
TypeScript
export const getAttachmentPath = (attachmentFullPath: string) => {
|
|
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}`;
|
|
};
|