/* TODO: */ //const DEBUG_TONY_SAMA_FORK_MODE = true import { DOMPurify } from '../../../lib.js'; import { getRequestHeaders, processDroppedFiles, eventSource, event_types } from '../../../script.js'; import { deleteExtension, extensionNames, getContext, installExtension, renderExtensionTemplateAsync } from '../../extensions.js'; import { POPUP_TYPE, Popup, callGenericPopup } from '../../popup.js'; import { executeSlashCommandsWithOptions } from '../../slash-commands.js'; import { accountStorage } from '../../util/AccountStorage.js'; import { flashHighlight, getStringHash, isValidUrl } from '../../utils.js'; import { t, translate } from '../../i18n.js'; export { MODULE_NAME }; const MODULE_NAME = 'assets'; const DEBUG_PREFIX = ' '; let previewAudio = null; let ASSETS_JSON_URL = 'https://raw.githubusercontent.com/SillyTavern/SillyTavern-Content/main/index.json'; // DBG //if (DEBUG_TONY_SAMA_FORK_MODE) // ASSETS_JSON_URL = "https://raw.githubusercontent.com/Tony-sama/SillyTavern-Content/main/index.json" let availableAssets = {}; let currentAssets = {}; //#############################// // Extension UI and Settings // //#############################// function filterAssets() { const searchValue = String($('#assets_search').val()).toLowerCase().trim(); const typeValue = String($('#assets_type_select').val()); if (typeValue === '') { $('#assets_menu .assets-list-div').show(); $('#assets_menu .assets-list-div h3').show(); } else { $('#assets_menu .assets-list-div h3').hide(); $('#assets_menu .assets-list-div').hide(); $(`#assets_menu .assets-list-div[data-type="${typeValue}"]`).show(); } if (searchValue === '') { $('#assets_menu .asset-block').show(); } else { $('#assets_menu .asset-block').hide(); $('#assets_menu .asset-block').filter(function () { return $(this).text().toLowerCase().includes(searchValue); }).show(); } } const KNOWN_TYPES = { 'extension': t`Extensions`, 'character': t`Characters`, 'ambient': t`Ambient sounds`, 'bgm': t`Background music`, 'blip': t`Blip sounds`, }; const EMPTY_AUTHOR = { name: '', url: '', }; /** * Extracts the repository author from a given URL. * @param {string} url - The URL of the repository. * @returns {{name: string, url: string}} Object containing the author's name and URL, or empty strings if not found. */ function getAuthorFromUrl(url) { const result = structuredClone(EMPTY_AUTHOR); try { const parsedUrl = new URL(url); const pathSegments = parsedUrl.pathname.split('/').filter(s => s.length > 0); // TODO: Handle non-GitHub URLs if needed if (parsedUrl.host === 'github.com' && pathSegments.length >= 2) { result.name = pathSegments[0]; result.url = `${parsedUrl.protocol}//${parsedUrl.hostname}/${result.name}`; } } catch (error) { console.debug(DEBUG_PREFIX, 'Error parsing URL:', error); } return result; } async function downloadAssetsList(url) { updateCurrentAssets().then(async function () { fetch(url, { cache: 'no-cache' }) .then(response => response.json()) .then(async function(json) { availableAssets = {}; $('#assets_menu').empty(); console.debug(DEBUG_PREFIX, 'Received assets dictionary', json); for (const i of json) { //console.log(DEBUG_PREFIX,i) if (availableAssets[i['type']] === undefined) availableAssets[i['type']] = []; availableAssets[i['type']].push(i); } console.debug(DEBUG_PREFIX, 'Updated available assets to', availableAssets); // First extensions, then everything else const assetTypes = Object.keys(availableAssets).sort((a, b) => (a === 'extension') ? -1 : (b === 'extension') ? 1 : 0); $('#assets_type_select').empty(); $('#assets_search').val(''); $('#assets_type_select').append($('