Files
twenty/packages/twenty-front/src/modules/activities/utils/getActivityAttachmentIdsToDelete.ts
T
Etienne 26f0a416a1 File storage cleaning (#18381)
- Remove feature flag
- Remove legacy methods in file-upload and file-service
- Migrate AI Chat to new file management

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
2026-03-04 23:46:03 +01:00

37 lines
1.3 KiB
TypeScript

import { type Attachment } from '@/activities/files/types/Attachment';
import { filterAttachmentsWithFile } from '@/activities/files/utils/filterAttachmentsWithFile';
import { compareUrls } from '@/activities/utils/compareUrls';
import { getActivityAttachmentPathsAndName } from '@/activities/utils/getActivityAttachmentPathsAndName';
import { getAttachmentUrl } from '@/activities/utils/getAttachmentUrl';
export const getActivityAttachmentIdsToDelete = (
newActivityBody: string,
oldActivityAttachments: Attachment[] = [],
oldActivityBody: string,
) => {
if (oldActivityAttachments.length === 0) return [];
const newActivityAttachmentPaths =
getActivityAttachmentPathsAndName(newActivityBody);
const oldActivityAttachmentPaths =
getActivityAttachmentPathsAndName(oldActivityBody);
const pathsToDelete = oldActivityAttachmentPaths
.filter(
(oldActivity) =>
!newActivityAttachmentPaths.some(
(newActivity) => newActivity.path === oldActivity.path,
),
)
.map((activity) => activity.path);
return filterAttachmentsWithFile(oldActivityAttachments)
.filter((attachment) =>
pathsToDelete.some((pathToDelete) =>
compareUrls(getAttachmentUrl({ attachment }), pathToDelete),
),
)
.map((attachment) => attachment.id);
};