mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-01-07 15:11:57 +01:00
Use Express router for thumbnails endpoint
This commit is contained in:
parent
414c9bd5fb
commit
2d54a67a1f
@ -3587,8 +3587,8 @@ require('./src/endpoints/presets').registerEndpoints(app, jsonParser);
|
||||
// Secrets managemenet
|
||||
require('./src/endpoints/secrets').registerEndpoints(app, jsonParser);
|
||||
|
||||
// Thumbnail generation
|
||||
require('./src/endpoints/thumbnails').registerEndpoints(app, jsonParser);
|
||||
// Thumbnail generation. These URLs are saved in chat, so this route cannot be renamed!
|
||||
app.use('/thumbnail', require('./src/endpoints/thumbnails').router);
|
||||
|
||||
// NovelAI generation
|
||||
require('./src/endpoints/novelai').registerEndpoints(app, jsonParser);
|
||||
|
@ -1,10 +1,12 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const express = require('express');
|
||||
const sanitize = require('sanitize-filename');
|
||||
const jimp = require('jimp');
|
||||
const writeFileAtomicSync = require('write-file-atomic').sync;
|
||||
const { DIRECTORIES } = require('../constants');
|
||||
const { getConfigValue } = require('../util');
|
||||
const { jsonParser } = require('../express-common');
|
||||
|
||||
/**
|
||||
* Gets a path to thumbnail folder based on the type.
|
||||
@ -150,15 +152,10 @@ async function ensureThumbnailCache() {
|
||||
console.log(`Done! Generated: ${bgFiles.length} preview images`);
|
||||
}
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
/**
|
||||
* Registers the endpoints for the thumbnail management.
|
||||
* @param {import('express').Express} app Express app
|
||||
* @param {any} jsonParser JSON parser middleware
|
||||
*/
|
||||
function registerEndpoints(app, jsonParser) {
|
||||
// Important: Do not change a path to this endpoint. It is used in the client code and saved to chat files.
|
||||
app.get('/thumbnail', jsonParser, async function (request, response) {
|
||||
// Important: This route must be mounted as '/thumbnail'. It is used in the client code and saved to chat files.
|
||||
router.get('/', jsonParser, async function (request, response) {
|
||||
if (typeof request.query.file !== 'string' || typeof request.query.type !== 'string') return response.sendStatus(400);
|
||||
|
||||
const type = request.query.type;
|
||||
@ -191,12 +188,10 @@ function registerEndpoints(app, jsonParser) {
|
||||
}
|
||||
|
||||
return response.sendFile(pathToCachedFile, { root: process.cwd() });
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
invalidateThumbnail,
|
||||
registerEndpoints,
|
||||
ensureThumbnailCache,
|
||||
router,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user