mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-10 00:50:43 +01:00
Save character data bank attachments as non-exportable
This commit is contained in:
parent
59bb04f1b3
commit
f4f0a59e90
@ -32,7 +32,7 @@ import {
|
||||
humanFileSize,
|
||||
saveBase64AsFile,
|
||||
} from './utils.js';
|
||||
import { extension_settings, renderExtensionTemplateAsync, saveMetadataDebounced, writeExtensionField } from './extensions.js';
|
||||
import { extension_settings, renderExtensionTemplateAsync, saveMetadataDebounced } from './extensions.js';
|
||||
import { POPUP_RESULT, POPUP_TYPE, callGenericPopup } from './popup.js';
|
||||
import { ScraperManager } from './scrapers.js';
|
||||
|
||||
@ -607,8 +607,7 @@ async function deleteAttachment(attachment, source, callback) {
|
||||
saveMetadataDebounced();
|
||||
break;
|
||||
case 'character':
|
||||
characters[this_chid].data.extensions.attachments = characters[this_chid].data.extensions.attachments.filter((a) => a.url !== attachment.url);
|
||||
await writeExtensionField(this_chid, 'attachments', characters[this_chid].data.extensions.attachments);
|
||||
extension_settings.character_attachments[characters[this_chid]?.avatar] = extension_settings.character_attachments[characters[this_chid]?.avatar].filter((a) => a.url !== attachment.url);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -678,7 +677,7 @@ async function openAttachmentManager() {
|
||||
/**
|
||||
* Renders buttons for the attachment manager.
|
||||
*/
|
||||
function renderButtons() {
|
||||
async function renderButtons() {
|
||||
const sources = {
|
||||
[ATTACHMENT_SOURCE.GLOBAL]: '.globalAttachmentsTitle',
|
||||
[ATTACHMENT_SOURCE.CHARACTER]: '.characterAttachmentsTitle',
|
||||
@ -689,6 +688,11 @@ async function openAttachmentManager() {
|
||||
const scrapers = ScraperManager.getDataBankScrapers();
|
||||
|
||||
for (const scraper of scrapers) {
|
||||
const isAvailable = await ScraperManager.isScraperAvailable(scraper.id);
|
||||
if (!isAvailable) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const buttonTemplate = template.find('.actionButtonTemplate .actionButton').clone();
|
||||
buttonTemplate.find('.actionButtonIcon').addClass(scraper.iconClass);
|
||||
buttonTemplate.find('.actionButtonText').text(scraper.name);
|
||||
@ -746,7 +750,7 @@ async function openAttachmentManager() {
|
||||
/** @type {FileAttachment[]} */
|
||||
const chatAttachments = chat_metadata.attachments ?? [];
|
||||
/** @type {FileAttachment[]} */
|
||||
const characterAttachments = characters[this_chid]?.data?.extensions?.attachments ?? [];
|
||||
const characterAttachments = extension_settings.character_attachments?.[characters[this_chid]?.avatar] ?? [];
|
||||
|
||||
await renderList(globalAttachments, ATTACHMENT_SOURCE.GLOBAL);
|
||||
await renderList(chatAttachments, ATTACHMENT_SOURCE.CHAT);
|
||||
@ -786,7 +790,7 @@ async function openAttachmentManager() {
|
||||
renderAttachments();
|
||||
});
|
||||
|
||||
const cleanupFn = renderButtons();
|
||||
const cleanupFn = await renderButtons();
|
||||
await renderAttachments();
|
||||
await callGenericPopup(template, POPUP_TYPE.TEXT, '', { wide: true, large: true, okButton: 'Close' });
|
||||
|
||||
@ -886,8 +890,8 @@ async function uploadFileAttachmentToServer(file, target) {
|
||||
saveMetadataDebounced();
|
||||
break;
|
||||
case ATTACHMENT_SOURCE.CHARACTER:
|
||||
characters[this_chid].data.extensions.attachments.push(attachment);
|
||||
await writeExtensionField(this_chid, 'attachments', characters[this_chid].data.extensions.attachments);
|
||||
extension_settings.character_attachments[characters[this_chid]?.avatar].push(attachment);
|
||||
saveSettingsDebounced();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -902,16 +906,12 @@ function ensureAttachmentsExist() {
|
||||
}
|
||||
|
||||
if (this_chid !== undefined && characters[this_chid]) {
|
||||
if (!characters[this_chid].data) {
|
||||
characters[this_chid].data = {};
|
||||
if (!extension_settings.character_attachments) {
|
||||
extension_settings.character_attachments = {};
|
||||
}
|
||||
|
||||
if (!characters[this_chid].data.extensions) {
|
||||
characters[this_chid].data.extensions = {};
|
||||
}
|
||||
|
||||
if (!Array.isArray(characters[this_chid]?.data?.extensions?.attachments)) {
|
||||
characters[this_chid].data.extensions.attachments = [];
|
||||
if (!Array.isArray(extension_settings.character_attachments[characters[this_chid].avatar])) {
|
||||
extension_settings.character_attachments[characters[this_chid].avatar] = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -924,7 +924,7 @@ export function getDataBankAttachments() {
|
||||
ensureAttachmentsExist();
|
||||
const globalAttachments = extension_settings.attachments ?? [];
|
||||
const chatAttachments = chat_metadata.attachments ?? [];
|
||||
const characterAttachments = characters[this_chid]?.data?.extensions?.attachments ?? [];
|
||||
const characterAttachments = extension_settings.character_attachments?.[characters[this_chid]?.avatar] ?? [];
|
||||
|
||||
return [...globalAttachments, ...chatAttachments, ...characterAttachments];
|
||||
}
|
||||
|
@ -146,6 +146,7 @@ const extension_settings = {
|
||||
global: {},
|
||||
},
|
||||
attachments: [],
|
||||
character_attachments: {},
|
||||
};
|
||||
|
||||
let modules = [];
|
||||
|
@ -62,8 +62,15 @@
|
||||
</h3>
|
||||
<div class="flex-container flexFlowColumn">
|
||||
<strong><small class="characterAttachmentsName"></small></strong>
|
||||
<small data-i18n="These files are available the current character in all chats they are in.">
|
||||
These files are available the current character in all chats they are in.
|
||||
<small>
|
||||
<span data-i18n="These files are available the current character in all chats they are in.">
|
||||
These files are available the current character in all chats they are in.
|
||||
</span>
|
||||
<span>
|
||||
<span data-i18n="Saved locally. Not exported.">
|
||||
Saved locally. Not exported.
|
||||
</span>
|
||||
</span>
|
||||
</small>
|
||||
</div>
|
||||
<div class="characterAttachmentsList attachmentsList"></div>
|
||||
|
@ -61,6 +61,20 @@ export class ScraperManager {
|
||||
}
|
||||
return scraper.scrape();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a scraper is available.
|
||||
* @param {string} scraperId ID of the scraper to check
|
||||
* @returns {Promise<boolean>} Whether the scraper is available
|
||||
*/
|
||||
static isScraperAvailable(scraperId) {
|
||||
const scraper = ScraperManager.#scrapers.find(s => s.id === scraperId);
|
||||
if (!scraper) {
|
||||
console.warn(`Scraper with ID ${scraperId} not found`);
|
||||
return;
|
||||
}
|
||||
return scraper.isAvailable();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user