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