mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-04-27 08:58:44 +02:00
Remove img filter, move file loader to utils
This commit is contained in:
parent
7177fec50c
commit
c7d9eb39f5
@ -5,42 +5,13 @@ import {
|
|||||||
callPopup,
|
callPopup,
|
||||||
} from "../../../script.js";
|
} from "../../../script.js";
|
||||||
import { selected_group } from "../../group-chats.js";
|
import { selected_group } from "../../group-chats.js";
|
||||||
|
import { loadFileToDocument } from "../../utils.js";
|
||||||
|
|
||||||
const extensionName = "gallery";
|
const extensionName = "gallery";
|
||||||
const extensionFolderPath = `scripts/extensions/${extensionName}/`;
|
const extensionFolderPath = `scripts/extensions/${extensionName}/`;
|
||||||
let firstTime = true;
|
let firstTime = true;
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads either a CSS or JS file and appends it to the appropriate document section.
|
|
||||||
*
|
|
||||||
* @param {string} url - The URL of the file to be loaded.
|
|
||||||
* @param {string} type - The type of file to load: "css" or "js".
|
|
||||||
* @returns {Promise} - Resolves when the file has loaded, rejects if there's an error or invalid type.
|
|
||||||
*/
|
|
||||||
function loadFile(url, type) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
let element;
|
|
||||||
|
|
||||||
if (type === "css") {
|
|
||||||
element = document.createElement("link");
|
|
||||||
element.rel = "stylesheet";
|
|
||||||
element.href = url;
|
|
||||||
} else if (type === "js") {
|
|
||||||
element = document.createElement("script");
|
|
||||||
element.src = url;
|
|
||||||
} else {
|
|
||||||
reject("Invalid type specified");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
element.onload = resolve;
|
|
||||||
element.onerror = reject;
|
|
||||||
|
|
||||||
type === "css"
|
|
||||||
? document.head.appendChild(element)
|
|
||||||
: document.body.appendChild(element);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a list of gallery items based on a given URL. This function calls an API endpoint
|
* Retrieves a list of gallery items based on a given URL. This function calls an API endpoint
|
||||||
@ -70,11 +41,11 @@ async function getGalleryItems(url) {
|
|||||||
async function showCharGallery() {
|
async function showCharGallery() {
|
||||||
// Load necessary files if it's the first time calling the function
|
// Load necessary files if it's the first time calling the function
|
||||||
if (firstTime) {
|
if (firstTime) {
|
||||||
await loadFile(
|
await loadFileToDocument(
|
||||||
`${extensionFolderPath}nanogallery2.woff.min.css`,
|
`${extensionFolderPath}nanogallery2.woff.min.css`,
|
||||||
"css"
|
"css"
|
||||||
);
|
);
|
||||||
await loadFile(
|
await loadFileToDocument(
|
||||||
`${extensionFolderPath}jquery.nanogallery2.min.js`,
|
`${extensionFolderPath}jquery.nanogallery2.min.js`,
|
||||||
"js"
|
"js"
|
||||||
);
|
);
|
||||||
|
@ -597,6 +597,38 @@ export async function saveBase64AsFile(base64Data, characterName, filename = "",
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads either a CSS or JS file and appends it to the appropriate document section.
|
||||||
|
*
|
||||||
|
* @param {string} url - The URL of the file to be loaded.
|
||||||
|
* @param {string} type - The type of file to load: "css" or "js".
|
||||||
|
* @returns {Promise} - Resolves when the file has loaded, rejects if there's an error or invalid type.
|
||||||
|
*/
|
||||||
|
export function loadFileToDocument(url, type) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let element;
|
||||||
|
|
||||||
|
if (type === "css") {
|
||||||
|
element = document.createElement("link");
|
||||||
|
element.rel = "stylesheet";
|
||||||
|
element.href = url;
|
||||||
|
} else if (type === "js") {
|
||||||
|
element = document.createElement("script");
|
||||||
|
element.src = url;
|
||||||
|
} else {
|
||||||
|
reject("Invalid type specified");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
element.onload = resolve;
|
||||||
|
element.onerror = reject;
|
||||||
|
|
||||||
|
type === "css"
|
||||||
|
? document.head.appendChild(element)
|
||||||
|
: document.body.appendChild(element);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function createThumbnail(dataUrl, maxWidth, maxHeight) {
|
export function createThumbnail(dataUrl, maxWidth, maxHeight) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const img = new Image();
|
const img = new Image();
|
||||||
|
@ -2686,8 +2686,7 @@ app.get('/listimgfiles/:folder', (req, res) => {
|
|||||||
if (err) {
|
if (err) {
|
||||||
return res.status(500).send({ error: "Unable to retrieve files" });
|
return res.status(500).send({ error: "Unable to retrieve files" });
|
||||||
}
|
}
|
||||||
const imgFiles = files.filter(file => ['.jpg', '.jpeg', '.png', '.gif'].includes(path.extname(file)));
|
res.send(files);
|
||||||
res.send(imgFiles);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user