mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-14 03:00:44 +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,
|
humanFileSize,
|
||||||
saveBase64AsFile,
|
saveBase64AsFile,
|
||||||
} from './utils.js';
|
} 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 { POPUP_RESULT, POPUP_TYPE, callGenericPopup } from './popup.js';
|
||||||
import { ScraperManager } from './scrapers.js';
|
import { ScraperManager } from './scrapers.js';
|
||||||
|
|
||||||
@ -607,8 +607,7 @@ async function deleteAttachment(attachment, source, callback) {
|
|||||||
saveMetadataDebounced();
|
saveMetadataDebounced();
|
||||||
break;
|
break;
|
||||||
case 'character':
|
case 'character':
|
||||||
characters[this_chid].data.extensions.attachments = characters[this_chid].data.extensions.attachments.filter((a) => a.url !== attachment.url);
|
extension_settings.character_attachments[characters[this_chid]?.avatar] = extension_settings.character_attachments[characters[this_chid]?.avatar].filter((a) => a.url !== attachment.url);
|
||||||
await writeExtensionField(this_chid, 'attachments', characters[this_chid].data.extensions.attachments);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -678,7 +677,7 @@ async function openAttachmentManager() {
|
|||||||
/**
|
/**
|
||||||
* Renders buttons for the attachment manager.
|
* Renders buttons for the attachment manager.
|
||||||
*/
|
*/
|
||||||
function renderButtons() {
|
async function renderButtons() {
|
||||||
const sources = {
|
const sources = {
|
||||||
[ATTACHMENT_SOURCE.GLOBAL]: '.globalAttachmentsTitle',
|
[ATTACHMENT_SOURCE.GLOBAL]: '.globalAttachmentsTitle',
|
||||||
[ATTACHMENT_SOURCE.CHARACTER]: '.characterAttachmentsTitle',
|
[ATTACHMENT_SOURCE.CHARACTER]: '.characterAttachmentsTitle',
|
||||||
@ -689,6 +688,11 @@ async function openAttachmentManager() {
|
|||||||
const scrapers = ScraperManager.getDataBankScrapers();
|
const scrapers = ScraperManager.getDataBankScrapers();
|
||||||
|
|
||||||
for (const scraper of scrapers) {
|
for (const scraper of scrapers) {
|
||||||
|
const isAvailable = await ScraperManager.isScraperAvailable(scraper.id);
|
||||||
|
if (!isAvailable) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const buttonTemplate = template.find('.actionButtonTemplate .actionButton').clone();
|
const buttonTemplate = template.find('.actionButtonTemplate .actionButton').clone();
|
||||||
buttonTemplate.find('.actionButtonIcon').addClass(scraper.iconClass);
|
buttonTemplate.find('.actionButtonIcon').addClass(scraper.iconClass);
|
||||||
buttonTemplate.find('.actionButtonText').text(scraper.name);
|
buttonTemplate.find('.actionButtonText').text(scraper.name);
|
||||||
@ -746,7 +750,7 @@ async function openAttachmentManager() {
|
|||||||
/** @type {FileAttachment[]} */
|
/** @type {FileAttachment[]} */
|
||||||
const chatAttachments = chat_metadata.attachments ?? [];
|
const chatAttachments = chat_metadata.attachments ?? [];
|
||||||
/** @type {FileAttachment[]} */
|
/** @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(globalAttachments, ATTACHMENT_SOURCE.GLOBAL);
|
||||||
await renderList(chatAttachments, ATTACHMENT_SOURCE.CHAT);
|
await renderList(chatAttachments, ATTACHMENT_SOURCE.CHAT);
|
||||||
@ -786,7 +790,7 @@ async function openAttachmentManager() {
|
|||||||
renderAttachments();
|
renderAttachments();
|
||||||
});
|
});
|
||||||
|
|
||||||
const cleanupFn = renderButtons();
|
const cleanupFn = await renderButtons();
|
||||||
await renderAttachments();
|
await renderAttachments();
|
||||||
await callGenericPopup(template, POPUP_TYPE.TEXT, '', { wide: true, large: true, okButton: 'Close' });
|
await callGenericPopup(template, POPUP_TYPE.TEXT, '', { wide: true, large: true, okButton: 'Close' });
|
||||||
|
|
||||||
@ -886,8 +890,8 @@ async function uploadFileAttachmentToServer(file, target) {
|
|||||||
saveMetadataDebounced();
|
saveMetadataDebounced();
|
||||||
break;
|
break;
|
||||||
case ATTACHMENT_SOURCE.CHARACTER:
|
case ATTACHMENT_SOURCE.CHARACTER:
|
||||||
characters[this_chid].data.extensions.attachments.push(attachment);
|
extension_settings.character_attachments[characters[this_chid]?.avatar].push(attachment);
|
||||||
await writeExtensionField(this_chid, 'attachments', characters[this_chid].data.extensions.attachments);
|
saveSettingsDebounced();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -902,16 +906,12 @@ function ensureAttachmentsExist() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this_chid !== undefined && characters[this_chid]) {
|
if (this_chid !== undefined && characters[this_chid]) {
|
||||||
if (!characters[this_chid].data) {
|
if (!extension_settings.character_attachments) {
|
||||||
characters[this_chid].data = {};
|
extension_settings.character_attachments = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!characters[this_chid].data.extensions) {
|
if (!Array.isArray(extension_settings.character_attachments[characters[this_chid].avatar])) {
|
||||||
characters[this_chid].data.extensions = {};
|
extension_settings.character_attachments[characters[this_chid].avatar] = [];
|
||||||
}
|
|
||||||
|
|
||||||
if (!Array.isArray(characters[this_chid]?.data?.extensions?.attachments)) {
|
|
||||||
characters[this_chid].data.extensions.attachments = [];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -924,7 +924,7 @@ export function getDataBankAttachments() {
|
|||||||
ensureAttachmentsExist();
|
ensureAttachmentsExist();
|
||||||
const globalAttachments = extension_settings.attachments ?? [];
|
const globalAttachments = extension_settings.attachments ?? [];
|
||||||
const chatAttachments = chat_metadata.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];
|
return [...globalAttachments, ...chatAttachments, ...characterAttachments];
|
||||||
}
|
}
|
||||||
|
@ -146,6 +146,7 @@ const extension_settings = {
|
|||||||
global: {},
|
global: {},
|
||||||
},
|
},
|
||||||
attachments: [],
|
attachments: [],
|
||||||
|
character_attachments: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
let modules = [];
|
let modules = [];
|
||||||
|
@ -62,8 +62,15 @@
|
|||||||
</h3>
|
</h3>
|
||||||
<div class="flex-container flexFlowColumn">
|
<div class="flex-container flexFlowColumn">
|
||||||
<strong><small class="characterAttachmentsName"></small></strong>
|
<strong><small class="characterAttachmentsName"></small></strong>
|
||||||
<small data-i18n="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.
|
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>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
<div class="characterAttachmentsList attachmentsList"></div>
|
<div class="characterAttachmentsList attachmentsList"></div>
|
||||||
|
@ -61,6 +61,20 @@ export class ScraperManager {
|
|||||||
}
|
}
|
||||||
return scraper.scrape();
|
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