mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Remove hard coded list in extensions
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
import { callPopup, saveSettings, saveSettingsDebounced } from "../script.js";
|
import { callPopup, saveSettings, saveSettingsDebounced, token } from "../script.js";
|
||||||
import { isSubsetOf } from "./utils.js";
|
import { isSubsetOf } from "./utils.js";
|
||||||
export {
|
export {
|
||||||
getContext,
|
getContext,
|
||||||
@ -9,8 +9,8 @@ export {
|
|||||||
extension_settings,
|
extension_settings,
|
||||||
};
|
};
|
||||||
|
|
||||||
const extensionNames = ['caption', 'dice', 'expressions', 'floating-prompt', 'memory', 'backgrounds'];
|
let extensionNames = [];
|
||||||
const manifests = await getManifests(extensionNames);
|
let manifests = [];
|
||||||
const defaultUrl = "http://localhost:5100";
|
const defaultUrl = "http://localhost:5100";
|
||||||
|
|
||||||
const extension_settings = {
|
const extension_settings = {
|
||||||
@ -34,6 +34,24 @@ const getApiUrl = () => extension_settings.apiUrl;
|
|||||||
const defaultRequestArgs = { method: 'GET', headers: { 'Bypass-Tunnel-Reminder': 'bypass' } };
|
const defaultRequestArgs = { method: 'GET', headers: { 'Bypass-Tunnel-Reminder': 'bypass' } };
|
||||||
let connectedToApi = false;
|
let connectedToApi = false;
|
||||||
|
|
||||||
|
async function discoverExtensions() {
|
||||||
|
try {
|
||||||
|
const response = await fetch('/discover_extensions', { headers: { 'X-CSRF-Token': token } });
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
const extensions = await response.json();
|
||||||
|
return extensions;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function onDisableExtensionClick() {
|
function onDisableExtensionClick() {
|
||||||
const name = $(this).data('name');
|
const name = $(this).data('name');
|
||||||
disableExtension(name);
|
disableExtension(name);
|
||||||
@ -247,7 +265,7 @@ function showExtensionsDetails() {
|
|||||||
callPopup(`<div class="extensions_info">${html}</div>`, 'text');
|
callPopup(`<div class="extensions_info">${html}</div>`, 'text');
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadExtensionSettings(settings) {
|
async function loadExtensionSettings(settings) {
|
||||||
if (settings.extension_settings) {
|
if (settings.extension_settings) {
|
||||||
Object.assign(extension_settings, settings.extension_settings);
|
Object.assign(extension_settings, settings.extension_settings);
|
||||||
}
|
}
|
||||||
@ -256,6 +274,8 @@ function loadExtensionSettings(settings) {
|
|||||||
$("#extensions_autoconnect").prop('checked', extension_settings.autoConnect).trigger('input');
|
$("#extensions_autoconnect").prop('checked', extension_settings.autoConnect).trigger('input');
|
||||||
|
|
||||||
// Activate offline extensions
|
// Activate offline extensions
|
||||||
|
extensionNames = await discoverExtensions();
|
||||||
|
manifests = await getManifests(extensionNames)
|
||||||
activateExtensions();
|
activateExtensions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,6 +118,7 @@ const directories = {
|
|||||||
thumbnailsBg: 'thumbnails/bg/',
|
thumbnailsBg: 'thumbnails/bg/',
|
||||||
thumbnailsAvatar: 'thumbnails/avatar/',
|
thumbnailsAvatar: 'thumbnails/avatar/',
|
||||||
themes: 'public/themes',
|
themes: 'public/themes',
|
||||||
|
extensions: 'public/scripts/extensions'
|
||||||
};
|
};
|
||||||
|
|
||||||
// CSRF Protection //
|
// CSRF Protection //
|
||||||
@ -1920,6 +1921,14 @@ app.post('/generate_poe', jsonParser, async (request, response) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get('/discover_extensions', jsonParser, function (_, response) {
|
||||||
|
const extensions = fs
|
||||||
|
.readdirSync(directories.extensions)
|
||||||
|
.filter(f => fs.statSync(path.join(directories.extensions, f)).isDirectory());
|
||||||
|
|
||||||
|
return response.send(extensions);
|
||||||
|
});
|
||||||
|
|
||||||
function getThumbnailFolder(type) {
|
function getThumbnailFolder(type) {
|
||||||
let thumbnailFolder;
|
let thumbnailFolder;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user