26f0a416a1
- 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>
37 lines
1.3 KiB
TypeScript
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);
|
|
};
|