From 78ce23750e49b4f736343fd9b83a1dd9e818df35 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sun, 21 Apr 2024 01:40:11 +0300 Subject: [PATCH] Add function to get data bank contents by source --- public/scripts/chats.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/public/scripts/chats.js b/public/scripts/chats.js index 0ae0b304b..71949e829 100644 --- a/public/scripts/chats.js +++ b/public/scripts/chats.js @@ -932,6 +932,24 @@ export function getDataBankAttachments() { return [...globalAttachments, ...chatAttachments, ...characterAttachments]; } +/** + * Gets all attachments for a specific source. + * @param {string} source Attachment source + * @returns {FileAttachment[]} List of attachments + */ +export function getDataBankAttachmentsForSource(source) { + ensureAttachmentsExist(); + + switch (source) { + case ATTACHMENT_SOURCE.GLOBAL: + return extension_settings.attachments ?? []; + case ATTACHMENT_SOURCE.CHAT: + return chat_metadata.attachments ?? []; + case ATTACHMENT_SOURCE.CHARACTER: + return extension_settings.character_attachments?.[characters[this_chid]?.avatar] ?? []; + } +} + jQuery(function () { $(document).on('click', '.mes_hide', async function () { const messageBlock = $(this).closest('.mes');