mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-09 00:28:52 +01:00
Fix gallery files caching, filter by mime type. Use fetch instead of Jquery Ajax
This commit is contained in:
parent
194278d171
commit
218cfb43d8
@ -26,16 +26,19 @@ let firstTime = true;
|
||||
* @returns {Promise<Array>} - Resolves with an array of gallery item objects, rejects on error.
|
||||
*/
|
||||
async function getGalleryItems(url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
$.get(`/listimgfiles/${url}`, function (files) {
|
||||
const items = files.map((file) => ({
|
||||
const response = await fetch(`/listimgfiles/${url}`, {
|
||||
method: 'POST',
|
||||
headers: getRequestHeaders(),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
const items = data.map((file) => ({
|
||||
src: `user/images/${url}/${file}`,
|
||||
srct: `user/images/${url}/${file}`,
|
||||
title: "", // Optional title for each item
|
||||
}));
|
||||
resolve(items);
|
||||
}).fail(reject);
|
||||
});
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
|
13
server.js
13
server.js
@ -2705,19 +2705,20 @@ app.post('/uploadimage', jsonParser, async (request, response) => {
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/listimgfiles/:folder', (req, res) => {
|
||||
const directoryPath = path.join(process.cwd(), 'public/user/images/', req.params.folder);
|
||||
app.post('/listimgfiles/:folder', (req, res) => {
|
||||
const directoryPath = path.join(process.cwd(), 'public/user/images/', sanitize(req.params.folder));
|
||||
|
||||
if (!fs.existsSync(directoryPath)) {
|
||||
fs.mkdirSync(directoryPath, { recursive: true });
|
||||
}
|
||||
|
||||
fs.readdir(directoryPath, (err, files) => {
|
||||
if (err) {
|
||||
try {
|
||||
const images = getImages(directoryPath);
|
||||
return res.send(images);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return res.status(500).send({ error: "Unable to retrieve files" });
|
||||
}
|
||||
res.send(files);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user