Merge pull request #3652 from SillyTavern/default-middleware Use default middleware for parsing request body
Signed| @@ -113,6 +113,9 @@ app.use(helmet({ | ||
| 113 | 113 | app.use(compression()); |
| 114 | 114 | app.use(responseTime()); |
| 115 | 115 | |
| 116 | +app.use(bodyParser.json({ limit: '200mb' })); | |
| 117 | +app.use(bodyParser.urlencoded({ extended: true, limit: '200mb' })); | |
| 118 | + | |
| 116 | 119 | // CORS Settings // |
| 117 | 120 | const CORS = cors({ |
| 118 | 121 | origin: 'null', |
| @@ -135,9 +138,6 @@ if (cliArgs.listen) { | ||
| 135 | 138 | } |
| 136 | 139 | |
| 137 | 140 | if (cliArgs.enableCorsProxy) { |
| 138 | - app.use(bodyParser.json({ | |
| 139 | - limit: '200mb', | |
| 140 | - })); | |
| 141 | 141 | app.use('/proxy/:url(*)', corsProxyMiddleware); |
| 142 | 142 | } else { |
| 143 | 143 | app.use('/proxy/:url(*)', async (_, res) => { |
| @@ -2,11 +2,10 @@ import fetch from 'node-fetch'; | ||
| 2 | 2 | import express from 'express'; |
| 3 | 3 | |
| 4 | 4 | import { readSecret, SECRET_KEYS } from './secrets.js'; |
| 5 | -import { jsonParser } from '../express-common.js'; | |
| 6 | 5 | |
| 7 | 6 | export const router = express.Router(); |
| 8 | 7 | |
| 9 | 8 | router.post('/caption-image', jsonParser, async (request, response) => { |
| 10 | 9 | try { |
| 11 | 10 | const mimeType = request.body.image.split(';')[0].split(':')[1]; |
| 12 | 11 | const base64Data = request.body.image.split(',')[1]; |
| @@ -8,7 +8,6 @@ import sanitize from 'sanitize-filename'; | ||
| 8 | 8 | import fetch from 'node-fetch'; |
| 9 | 9 | |
| 10 | 10 | import { UNSAFE_EXTENSIONS } from '../constants.js'; |
| 11 | -import { jsonParser } from '../express-common.js'; | |
| 12 | 11 | import { clientRelativePath } from '../util.js'; |
| 13 | 12 | |
| 14 | 13 | const VALID_CATEGORIES = ['bgm', 'ambient', 'blip', 'live2d', 'vrm', 'character', 'temp']; |
| @@ -105,7 +104,7 @@ export const router = express.Router(); | ||
| 105 | 104 | * |
| 106 | 105 | * @returns {void} |
| 107 | 106 | */ |
| 108 | 107 | router.post('/get', jsonParser, async (request, response) => { |
| 109 | 108 | const folderPath = path.join(request.user.directories.assets); |
| 110 | 109 | let output = {}; |
| 111 | 110 | |
| @@ -189,7 +188,7 @@ router.post('/get', jsonParser, async (request, response) => { | ||
| 189 | 188 | * |
| 190 | 189 | * @returns {void} |
| 191 | 190 | */ |
| 192 | 191 | router.post('/download', jsonParser, async (request, response) => { |
| 193 | 192 | const url = request.body.url; |
| 194 | 193 | const inputCategory = request.body.category; |
| 195 | 194 | |
| @@ -260,7 +259,7 @@ router.post('/download', jsonParser, async (request, response) => { | ||
| 260 | 259 | * |
| 261 | 260 | * @returns {void} |
| 262 | 261 | */ |
| 263 | 262 | router.post('/delete', jsonParser, async (request, response) => { |
| 264 | 263 | const inputCategory = request.body.category; |
| 265 | 264 | |
| 266 | 265 | // Check category |
| @@ -312,7 +311,7 @@ router.post('/delete', jsonParser, async (request, response) => { | ||
| 312 | 311 | * |
| 313 | 312 | * @returns {void} |
| 314 | 313 | */ |
| 315 | 314 | router.post('/character', jsonParser, async (request, response) => { |
| 316 | 315 | if (request.query.name === undefined) return response.sendStatus(400); |
| 317 | 316 | |
| 318 | 317 | // For backwards compatibility, don't reject invalid character names, just sanitize them |
| @@ -6,19 +6,18 @@ import sanitize from 'sanitize-filename'; | ||
| 6 | 6 | import jimp from 'jimp'; |
| 7 | 7 | import { sync as writeFileAtomicSync } from 'write-file-atomic'; |
| 8 | 8 | |
| 9 | -import { jsonParser, urlencodedParser } from '../express-common.js'; | |
| 10 | 9 | import { AVATAR_WIDTH, AVATAR_HEIGHT } from '../constants.js'; |
| 11 | 10 | import { getImages, tryParse } from '../util.js'; |
| 12 | 11 | import { getFileNameValidationFunction } from '../middleware/validateFileName.js'; |
| 13 | 12 | |
| 14 | 13 | export const router = express.Router(); |
| 15 | 14 | |
| 16 | 15 | router.post('/get', jsonParser, function (request, response) { |
| 17 | 16 | var images = getImages(request.user.directories.avatars); |
| 18 | 17 | response.send(JSON.stringify(images)); |
| 19 | 18 | }); |
| 20 | 19 | |
| 21 | 20 | router.post('/delete', jsonParser, getFileNameValidationFunction('avatar'), function (request, response) { |
| 22 | 21 | if (!request.body) return response.sendStatus(400); |
| 23 | 22 | |
| 24 | 23 | if (request.body.avatar !== sanitize(request.body.avatar)) { |
| @@ -36,7 +35,7 @@ router.post('/delete', jsonParser, getFileNameValidationFunction('avatar'), func | ||
| 36 | 35 | return response.sendStatus(404); |
| 37 | 36 | }); |
| 38 | 37 | |
| 39 | 38 | router.post('/upload', urlencodedParser, async (request, response) => { |
| 40 | 39 | if (!request.file) return response.sendStatus(400); |
| 41 | 40 | |
| 42 | 41 | try { |
| @@ -2,11 +2,10 @@ import fetch from 'node-fetch'; | ||
| 2 | 2 | import { Router } from 'express'; |
| 3 | 3 | |
| 4 | 4 | import { readSecret, SECRET_KEYS } from './secrets.js'; |
| 5 | -import { jsonParser } from '../express-common.js'; | |
| 6 | 5 | |
| 7 | 6 | export const router = Router(); |
| 8 | 7 | |
| 9 | 8 | router.post('/list', jsonParser, async (req, res) => { |
| 10 | 9 | try { |
| 11 | 10 | const key = readSecret(req.user.directories, SECRET_KEYS.AZURE_TTS); |
| 12 | 11 | |
| @@ -44,7 +43,7 @@ router.post('/list', jsonParser, async (req, res) => { | ||
| 44 | 43 | } |
| 45 | 44 | }); |
| 46 | 45 | |
| 47 | 46 | router.post('/generate', jsonParser, async (req, res) => { |
| 48 | 47 | try { |
| 49 | 48 | const key = readSecret(req.user.directories, SECRET_KEYS.AZURE_TTS); |
| 50 | 49 | |
| @@ -2,7 +2,6 @@ import process from 'node:process'; | ||
| 2 | 2 | import express from 'express'; |
| 3 | 3 | import fetch from 'node-fetch'; |
| 4 | 4 | |
| 5 | -import { jsonParser } from '../../express-common.js'; | |
| 6 | 5 | import { |
| 7 | 6 | CHAT_COMPLETION_SOURCES, |
| 8 | 7 | GEMINI_SAFETY, |
| @@ -821,7 +820,7 @@ async function sendDeepSeekRequest(request, response) { | ||
| 821 | 820 | |
| 822 | 821 | export const router = express.Router(); |
| 823 | 822 | |
| 824 | 823 | router.post('/status', jsonParser, async function (request, response_getstatus_openai) { |
| 825 | 824 | if (!request.body) return response_getstatus_openai.sendStatus(400); |
| 826 | 825 | |
| 827 | 826 | let api_url; |
| @@ -937,7 +936,7 @@ router.post('/status', jsonParser, async function (request, response_getstatus_o | ||
| 937 | 936 | } |
| 938 | 937 | }); |
| 939 | 938 | |
| 940 | 939 | router.post('/bias', jsonParser, async function (request, response) { |
| 941 | 940 | if (!request.body || !Array.isArray(request.body)) |
| 942 | 941 | return response.sendStatus(400); |
| 943 | 942 | |
| @@ -1022,7 +1021,7 @@ router.post('/bias', jsonParser, async function (request, response) { | ||
| 1022 | 1021 | }); |
| 1023 | 1022 | |
| 1024 | 1023 | |
| 1025 | 1024 | router.post('/generate', jsonParser, function (request, response) { |
| 1026 | 1025 | if (!request.body) return response.status(400).send({ error: true }); |
| 1027 | 1026 | |
| 1028 | 1027 | switch (request.body.chat_completion_source) { |
| @@ -2,14 +2,13 @@ import fs from 'node:fs'; | ||
| 2 | 2 | import express from 'express'; |
| 3 | 3 | import fetch from 'node-fetch'; |
| 4 | 4 | |
| 5 | -import { jsonParser, urlencodedParser } from '../../express-common.js'; | |
| 6 | 5 | import { forwardFetchResponse, delay } from '../../util.js'; |
| 7 | 6 | import { getOverrideHeaders, setAdditionalHeaders, setAdditionalHeadersByType } from '../../additional-headers.js'; |
| 8 | 7 | import { TEXTGEN_TYPES } from '../../constants.js'; |
| 9 | 8 | |
| 10 | 9 | export const router = express.Router(); |
| 11 | 10 | |
| 12 | 11 | router.post('/generate', jsonParser, async function (request, response_generate) { |
| 13 | 12 | if (!request.body) return response_generate.sendStatus(400); |
| 14 | 13 | |
| 15 | 14 | if (request.body.api_server.indexOf('localhost') != -1) { |
| @@ -141,7 +140,7 @@ router.post('/generate', jsonParser, async function (request, response_generate) | ||
| 141 | 140 | return response_generate.send({ error: true }); |
| 142 | 141 | }); |
| 143 | 142 | |
| 144 | 143 | router.post('/status', jsonParser, async function (request, response) { |
| 145 | 144 | if (!request.body) return response.sendStatus(400); |
| 146 | 145 | let api_server = request.body.api_server; |
| 147 | 146 | if (api_server.indexOf('localhost') != -1) { |
| @@ -188,7 +187,7 @@ router.post('/status', jsonParser, async function (request, response) { | ||
| 188 | 187 | response.send(result); |
| 189 | 188 | }); |
| 190 | 189 | |
| 191 | 190 | router.post('/transcribe-audio', urlencodedParser, async function (request, response) { |
| 192 | 191 | try { |
| 193 | 192 | const server = request.body.server; |
| 194 | 193 | |
| @@ -1,12 +1,11 @@ | ||
| 1 | 1 | import express from 'express'; |
| 2 | 2 | import fetch from 'node-fetch'; |
| 3 | 3 | |
| 4 | -import { jsonParser } from '../../express-common.js'; | |
| 5 | 4 | import { readSecret, SECRET_KEYS } from '../secrets.js'; |
| 6 | 5 | |
| 7 | 6 | export const router = express.Router(); |
| 8 | 7 | |
| 9 | 8 | router.post('/generate', jsonParser, async function (request, response) { |
| 10 | 9 | if (!request.body) return response.sendStatus(400); |
| 11 | 10 | |
| 12 | 11 | try { |
| @@ -3,7 +3,6 @@ import fetch from 'node-fetch'; | ||
| 3 | 3 | import express from 'express'; |
| 4 | 4 | import _ from 'lodash'; |
| 5 | 5 | |
| 6 | -import { jsonParser } from '../../express-common.js'; | |
| 7 | 6 | import { |
| 8 | 7 | TEXTGEN_TYPES, |
| 9 | 8 | TOGETHERAI_KEYS, |
| @@ -93,7 +92,7 @@ async function abortKoboldCppRequest(url) { | ||
| 93 | 92 | } |
| 94 | 93 | |
| 95 | 94 | //************** Ooba/OpenAI text completions API |
| 96 | 95 | router.post('/status', jsonParser, async function (request, response) { |
| 97 | 96 | if (!request.body) return response.sendStatus(400); |
| 98 | 97 | |
| 99 | 98 | try { |
| @@ -227,7 +226,7 @@ router.post('/status', jsonParser, async function (request, response) { | ||
| 227 | 226 | } |
| 228 | 227 | }); |
| 229 | 228 | |
| 230 | 229 | router.post('/props', jsonParser, async function (request, response) { |
| 231 | 230 | if (!request.body.api_server) return response.sendStatus(400); |
| 232 | 231 | |
| 233 | 232 | try { |
| @@ -261,7 +260,7 @@ router.post('/props', jsonParser, async function (request, response) { | ||
| 261 | 260 | } |
| 262 | 261 | }); |
| 263 | 262 | |
| 264 | 263 | router.post('/generate', jsonParser, async function (request, response) { |
| 265 | 264 | if (!request.body) return response.sendStatus(400); |
| 266 | 265 | |
| 267 | 266 | try { |
| @@ -432,7 +431,7 @@ router.post('/generate', jsonParser, async function (request, response) { | ||
| 432 | 431 | |
| 433 | 432 | const ollama = express.Router(); |
| 434 | 433 | |
| 435 | 434 | ollama.post('/download', jsonParser, async function (request, response) { |
| 436 | 435 | try { |
| 437 | 436 | if (!request.body.name || !request.body.api_server) return response.sendStatus(400); |
| 438 | 437 | |
| @@ -462,7 +461,7 @@ ollama.post('/download', jsonParser, async function (request, response) { | ||
| 462 | 461 | } |
| 463 | 462 | }); |
| 464 | 463 | |
| 465 | 464 | ollama.post('/caption-image', jsonParser, async function (request, response) { |
| 466 | 465 | try { |
| 467 | 466 | if (!request.body.server_url || !request.body.model) { |
| 468 | 467 | return response.sendStatus(400); |
| @@ -507,7 +506,7 @@ ollama.post('/caption-image', jsonParser, async function (request, response) { | ||
| 507 | 506 | |
| 508 | 507 | const llamacpp = express.Router(); |
| 509 | 508 | |
| 510 | 509 | llamacpp.post('/caption-image', jsonParser, async function (request, response) { |
| 511 | 510 | try { |
| 512 | 511 | if (!request.body.server_url) { |
| 513 | 512 | return response.sendStatus(400); |
| @@ -552,7 +551,7 @@ llamacpp.post('/caption-image', jsonParser, async function (request, response) { | ||
| 552 | 551 | } |
| 553 | 552 | }); |
| 554 | 553 | |
| 555 | 554 | llamacpp.post('/props', jsonParser, async function (request, response) { |
| 556 | 555 | try { |
| 557 | 556 | if (!request.body.server_url) { |
| 558 | 557 | return response.sendStatus(400); |
| @@ -581,7 +580,7 @@ llamacpp.post('/props', jsonParser, async function (request, response) { | ||
| 581 | 580 | } |
| 582 | 581 | }); |
| 583 | 582 | |
| 584 | 583 | llamacpp.post('/slots', jsonParser, async function (request, response) { |
| 585 | 584 | try { |
| 586 | 585 | if (!request.body.server_url) { |
| 587 | 586 | return response.sendStatus(400); |
| @@ -633,7 +632,7 @@ llamacpp.post('/slots', jsonParser, async function (request, response) { | ||
| 633 | 632 | |
| 634 | 633 | const tabby = express.Router(); |
| 635 | 634 | |
| 636 | 635 | tabby.post('/download', jsonParser, async function (request, response) { |
| 637 | 636 | try { |
| 638 | 637 | const baseUrl = String(request.body.api_server).replace(/\/$/, ''); |
| 639 | 638 | |
| @@ -4,19 +4,18 @@ import path from 'node:path'; | ||
| 4 | 4 | import express from 'express'; |
| 5 | 5 | import sanitize from 'sanitize-filename'; |
| 6 | 6 | |
| 7 | -import { jsonParser, urlencodedParser } from '../express-common.js'; | |
| 8 | 7 | import { invalidateThumbnail } from './thumbnails.js'; |
| 9 | 8 | import { getImages } from '../util.js'; |
| 10 | 9 | import { getFileNameValidationFunction } from '../middleware/validateFileName.js'; |
| 11 | 10 | |
| 12 | 11 | export const router = express.Router(); |
| 13 | 12 | |
| 14 | 13 | router.post('/all', jsonParser, function (request, response) { |
| 15 | 14 | var images = getImages(request.user.directories.backgrounds); |
| 16 | 15 | response.send(JSON.stringify(images)); |
| 17 | 16 | }); |
| 18 | 17 | |
| 19 | 18 | router.post('/delete', jsonParser, getFileNameValidationFunction('bg'), function (request, response) { |
| 20 | 19 | if (!request.body) return response.sendStatus(400); |
| 21 | 20 | |
| 22 | 21 | if (request.body.bg !== sanitize(request.body.bg)) { |
| @@ -36,7 +35,7 @@ router.post('/delete', jsonParser, getFileNameValidationFunction('bg'), function | ||
| 36 | 35 | return response.send('ok'); |
| 37 | 36 | }); |
| 38 | 37 | |
| 39 | 38 | router.post('/rename', jsonParser, function (request, response) { |
| 40 | 39 | if (!request.body) return response.sendStatus(400); |
| 41 | 40 | |
| 42 | 41 | const oldFileName = path.join(request.user.directories.backgrounds, sanitize(request.body.old_bg)); |
| @@ -58,7 +57,7 @@ router.post('/rename', jsonParser, function (request, response) { | ||
| 58 | 57 | return response.send('ok'); |
| 59 | 58 | }); |
| 60 | 59 | |
| 61 | 60 | router.post('/upload', urlencodedParser, function (request, response) { |
| 62 | 61 | if (!request.body || !request.file) return response.sendStatus(400); |
| 63 | 62 | |
| 64 | 63 | const img_path = path.join(request.file.destination, request.file.filename); |
| @@ -1,12 +1,11 @@ | ||
| 1 | 1 | import express from 'express'; |
| 2 | -import { jsonParser } from '../express-common.js'; | |
| 3 | 2 | import { getPipeline, getRawImage } from '../transformers.js'; |
| 4 | 3 | |
| 5 | 4 | export const router = express.Router(); |
| 6 | 5 | |
| 7 | 6 | const TASK = 'image-to-text'; |
| 8 | 7 | |
| 9 | 8 | router.post('/', jsonParser, async (req, res) => { |
| 10 | 9 | try { |
| 11 | 10 | const { image } = req.body; |
| 12 | 11 | |
| @@ -13,7 +13,6 @@ import mime from 'mime-types'; | ||
| 13 | 13 | import jimp from 'jimp'; |
| 14 | 14 | |
| 15 | 15 | import { AVATAR_WIDTH, AVATAR_HEIGHT } from '../constants.js'; |
| 16 | -import { jsonParser, urlencodedParser } from '../express-common.js'; | |
| 17 | 16 | import { default as validateAvatarUrlMiddleware, getFileNameValidationFunction } from '../middleware/validateFileName.js'; |
| 18 | 17 | import { deepMerge, humanizedISO8601DateTime, tryParse, extractFileFromZipBuffer, MemoryLimitedMap, getConfigValue } from '../util.js'; |
| 19 | 18 | import { TavernCardValidator } from '../validator/TavernCardValidator.js'; |
| @@ -768,7 +767,7 @@ async function importFromPng(uploadPath, { request }, preservedFileName) { | ||
| 768 | 767 | |
| 769 | 768 | export const router = express.Router(); |
| 770 | 769 | |
| 771 | 770 | router.post('/create', urlencodedParser, async function (request, response) { |
| 772 | 771 | try { |
| 773 | 772 | if (!request.body) return response.sendStatus(400); |
| 774 | 773 | |
| @@ -797,7 +796,7 @@ router.post('/create', urlencodedParser, async function (request, response) { | ||
| 797 | 796 | } |
| 798 | 797 | }); |
| 799 | 798 | |
| 800 | 799 | router.post('/rename', jsonParser, validateAvatarUrlMiddleware, async function (request, response) { |
| 801 | 800 | if (!request.body.avatar_url || !request.body.new_name) { |
| 802 | 801 | return response.sendStatus(400); |
| 803 | 802 | } |
| @@ -844,7 +843,7 @@ router.post('/rename', jsonParser, validateAvatarUrlMiddleware, async function ( | ||
| 844 | 843 | } |
| 845 | 844 | }); |
| 846 | 845 | |
| 847 | 846 | router.post('/edit', urlencodedParser, validateAvatarUrlMiddleware, async function (request, response) { |
| 848 | 847 | if (!request.body) { |
| 849 | 848 | console.warn('Error: no response body detected'); |
| 850 | 849 | response.status(400).send('Error: no response body detected'); |
| @@ -896,7 +895,7 @@ router.post('/edit', urlencodedParser, validateAvatarUrlMiddleware, async functi | ||
| 896 | 895 | * @param {Object} response - The HTTP response object. |
| 897 | 896 | * @returns {void} |
| 898 | 897 | */ |
| 899 | 898 | router.post('/edit-attribute', jsonParser, validateAvatarUrlMiddleware, async function (request, response) { |
| 900 | 899 | console.debug(request.body); |
| 901 | 900 | if (!request.body) { |
| 902 | 901 | console.warn('Error: no response body detected'); |
| @@ -942,7 +941,7 @@ router.post('/edit-attribute', jsonParser, validateAvatarUrlMiddleware, async fu | ||
| 942 | 941 | * |
| 943 | 942 | * @returns {void} |
| 944 | 943 | * */ |
| 945 | 944 | router.post('/merge-attributes', jsonParser, getFileNameValidationFunction('avatar'), async function (request, response) { |
| 946 | 945 | try { |
| 947 | 946 | const update = request.body; |
| 948 | 947 | const avatarPath = path.join(request.user.directories.characters, update.avatar); |
| @@ -973,7 +972,7 @@ router.post('/merge-attributes', jsonParser, getFileNameValidationFunction('avat | ||
| 973 | 972 | } |
| 974 | 973 | }); |
| 975 | 974 | |
| 976 | 975 | router.post('/delete', jsonParser, validateAvatarUrlMiddleware, async function (request, response) { |
| 977 | 976 | if (!request.body || !request.body.avatar_url) { |
| 978 | 977 | return response.sendStatus(400); |
| 979 | 978 | } |
| @@ -1023,7 +1022,7 @@ router.post('/delete', jsonParser, validateAvatarUrlMiddleware, async function ( | ||
| 1023 | 1022 | * @param {import("express").Response} response The HTTP response object. |
| 1024 | 1023 | * @return {void} |
| 1025 | 1024 | */ |
| 1026 | 1025 | router.post('/all', jsonParser, async function (request, response) { |
| 1027 | 1026 | try { |
| 1028 | 1027 | const files = fs.readdirSync(request.user.directories.characters); |
| 1029 | 1028 | const pngFiles = files.filter(file => file.endsWith('.png')); |
| @@ -1036,7 +1035,7 @@ router.post('/all', jsonParser, async function (request, response) { | ||
| 1036 | 1035 | } |
| 1037 | 1036 | }); |
| 1038 | 1037 | |
| 1039 | 1038 | router.post('/get', jsonParser, validateAvatarUrlMiddleware, async function (request, response) { |
| 1040 | 1039 | try { |
| 1041 | 1040 | if (!request.body) return response.sendStatus(400); |
| 1042 | 1041 | const item = request.body.avatar_url; |
| @@ -1055,7 +1054,7 @@ router.post('/get', jsonParser, validateAvatarUrlMiddleware, async function (req | ||
| 1055 | 1054 | } |
| 1056 | 1055 | }); |
| 1057 | 1056 | |
| 1058 | 1057 | router.post('/chats', jsonParser, validateAvatarUrlMiddleware, async function (request, response) { |
| 1059 | 1058 | try { |
| 1060 | 1059 | if (!request.body) return response.sendStatus(400); |
| 1061 | 1060 | |
| @@ -1164,7 +1163,7 @@ function getPreservedName(request) { | ||
| 1164 | 1163 | : undefined; |
| 1165 | 1164 | } |
| 1166 | 1165 | |
| 1167 | 1166 | router.post('/import', urlencodedParser, async function (request, response) { |
| 1168 | 1167 | if (!request.body || !request.file) return response.sendStatus(400); |
| 1169 | 1168 | |
| 1170 | 1169 | const uploadPath = path.join(request.file.destination, request.file.filename); |
| @@ -1204,7 +1203,7 @@ router.post('/import', urlencodedParser, async function (request, response) { | ||
| 1204 | 1203 | } |
| 1205 | 1204 | }); |
| 1206 | 1205 | |
| 1207 | 1206 | router.post('/duplicate', jsonParser, validateAvatarUrlMiddleware, async function (request, response) { |
| 1208 | 1207 | try { |
| 1209 | 1208 | if (!request.body.avatar_url) { |
| 1210 | 1209 | console.warn('avatar URL not found in request body'); |
| @@ -1250,7 +1249,7 @@ router.post('/duplicate', jsonParser, validateAvatarUrlMiddleware, async functio | ||
| 1250 | 1249 | } |
| 1251 | 1250 | }); |
| 1252 | 1251 | |
| 1253 | 1252 | router.post('/export', jsonParser, validateAvatarUrlMiddleware, async function (request, response) { |
| 1254 | 1253 | try { |
| 1255 | 1254 | if (!request.body.format || !request.body.avatar_url) { |
| 1256 | 1255 | return response.sendStatus(400); |
| @@ -8,7 +8,6 @@ import sanitize from 'sanitize-filename'; | ||
| 8 | 8 | import { sync as writeFileAtomicSync } from 'write-file-atomic'; |
| 9 | 9 | import _ from 'lodash'; |
| 10 | 10 | |
| 11 | -import { jsonParser, urlencodedParser } from '../express-common.js'; | |
| 12 | 11 | import validateAvatarUrlMiddleware from '../middleware/validateFileName.js'; |
| 13 | 12 | import { |
| 14 | 13 | getConfigValue, |
| @@ -295,7 +294,7 @@ function importRisuChat(userName, characterName, jsonData) { | ||
| 295 | 294 | |
| 296 | 295 | export const router = express.Router(); |
| 297 | 296 | |
| 298 | 297 | router.post('/save', jsonParser, validateAvatarUrlMiddleware, function (request, response) { |
| 299 | 298 | try { |
| 300 | 299 | const directoryName = String(request.body.avatar_url).replace('.png', ''); |
| 301 | 300 | const chatData = request.body.chat; |
| @@ -311,7 +310,7 @@ router.post('/save', jsonParser, validateAvatarUrlMiddleware, function (request, | ||
| 311 | 310 | } |
| 312 | 311 | }); |
| 313 | 312 | |
| 314 | 313 | router.post('/get', jsonParser, validateAvatarUrlMiddleware, function (request, response) { |
| 315 | 314 | try { |
| 316 | 315 | const dirName = String(request.body.avatar_url).replace('.png', ''); |
| 317 | 316 | const directoryPath = path.join(request.user.directories.chats, dirName); |
| @@ -347,8 +346,7 @@ router.post('/get', jsonParser, validateAvatarUrlMiddleware, function (request, | ||
| 347 | 346 | } |
| 348 | 347 | }); |
| 349 | 348 | |
| 350 | - | |
| 349 | +router.post('/rename', validateAvatarUrlMiddleware, async function (request, response) { | |
| 351 | -router.post('/rename', jsonParser, validateAvatarUrlMiddleware, async function (request, response) { | |
| 352 | 350 | if (!request.body || !request.body.original_file || !request.body.renamed_file) { |
| 353 | 351 | return response.sendStatus(400); |
| 354 | 352 | } |
| @@ -373,7 +371,7 @@ router.post('/rename', jsonParser, validateAvatarUrlMiddleware, async function ( | ||
| 373 | 371 | return response.send({ ok: true, sanitizedFileName }); |
| 374 | 372 | }); |
| 375 | 373 | |
| 376 | 374 | router.post('/delete', jsonParser, validateAvatarUrlMiddleware, function (request, response) { |
| 377 | 375 | const dirName = String(request.body.avatar_url).replace('.png', ''); |
| 378 | 376 | const fileName = String(request.body.chatfile); |
| 379 | 377 | const filePath = path.join(request.user.directories.chats, dirName, sanitize(fileName)); |
| @@ -389,7 +387,7 @@ router.post('/delete', jsonParser, validateAvatarUrlMiddleware, function (reques | ||
| 389 | 387 | return response.send('ok'); |
| 390 | 388 | }); |
| 391 | 389 | |
| 392 | 390 | router.post('/export', jsonParser, validateAvatarUrlMiddleware, async function (request, response) { |
| 393 | 391 | if (!request.body.file || (!request.body.avatar_url && request.body.is_group === false)) { |
| 394 | 392 | return response.sendStatus(400); |
| 395 | 393 | } |
| @@ -458,7 +456,7 @@ router.post('/export', jsonParser, validateAvatarUrlMiddleware, async function ( | ||
| 458 | 456 | } |
| 459 | 457 | }); |
| 460 | 458 | |
| 461 | 459 | router.post('/group/import', urlencodedParser, function (request, response) { |
| 462 | 460 | try { |
| 463 | 461 | const filedata = request.file; |
| 464 | 462 | |
| @@ -478,7 +476,7 @@ router.post('/group/import', urlencodedParser, function (request, response) { | ||
| 478 | 476 | } |
| 479 | 477 | }); |
| 480 | 478 | |
| 481 | 479 | router.post('/import', urlencodedParser, validateAvatarUrlMiddleware, function (request, response) { |
| 482 | 480 | if (!request.body) return response.sendStatus(400); |
| 483 | 481 | |
| 484 | 482 | const format = request.body.file_type; |
| @@ -571,7 +569,7 @@ router.post('/import', urlencodedParser, validateAvatarUrlMiddleware, function ( | ||
| 571 | 569 | } |
| 572 | 570 | }); |
| 573 | 571 | |
| 574 | 572 | router.post('/group/get', jsonParser, (request, response) => { |
| 575 | 573 | if (!request.body || !request.body.id) { |
| 576 | 574 | return response.sendStatus(400); |
| 577 | 575 | } |
| @@ -591,7 +589,7 @@ router.post('/group/get', jsonParser, (request, response) => { | ||
| 591 | 589 | } |
| 592 | 590 | }); |
| 593 | 591 | |
| 594 | 592 | router.post('/group/delete', jsonParser, (request, response) => { |
| 595 | 593 | if (!request.body || !request.body.id) { |
| 596 | 594 | return response.sendStatus(400); |
| 597 | 595 | } |
| @@ -607,7 +605,7 @@ router.post('/group/delete', jsonParser, (request, response) => { | ||
| 607 | 605 | return response.send({ error: true }); |
| 608 | 606 | }); |
| 609 | 607 | |
| 610 | 608 | router.post('/group/save', jsonParser, (request, response) => { |
| 611 | 609 | if (!request.body || !request.body.id) { |
| 612 | 610 | return response.sendStatus(400); |
| 613 | 611 | } |
| @@ -626,7 +624,7 @@ router.post('/group/save', jsonParser, (request, response) => { | ||
| 626 | 624 | return response.send({ ok: true }); |
| 627 | 625 | }); |
| 628 | 626 | |
| 629 | 627 | router.post('/search', jsonParser, validateAvatarUrlMiddleware, function (request, response) { |
| 630 | 628 | try { |
| 631 | 629 | const { query, avatar_url, group_id } = request.body; |
| 632 | 630 | let chatFiles = []; |
| @@ -1,7 +1,6 @@ | ||
| 1 | 1 | import express from 'express'; |
| 2 | 2 | |
| 3 | 3 | import { getPipeline } from '../transformers.js'; |
| 4 | -import { jsonParser } from '../express-common.js'; | |
| 5 | 4 | |
| 6 | 5 | const TASK = 'text-classification'; |
| 7 | 6 | |
| @@ -12,7 +11,7 @@ export const router = express.Router(); | ||
| 12 | 11 | */ |
| 13 | 12 | const cacheObject = new Map(); |
| 14 | 13 | |
| 15 | 14 | router.post('/labels', jsonParser, async (req, res) => { |
| 16 | 15 | try { |
| 17 | 16 | const pipe = await getPipeline(TASK); |
| 18 | 17 | const result = Object.keys(pipe.model.config.label2id); |
| @@ -23,7 +22,7 @@ router.post('/labels', jsonParser, async (req, res) => { | ||
| 23 | 22 | } |
| 24 | 23 | }); |
| 25 | 24 | |
| 26 | 25 | router.post('/', jsonParser, async (req, res) => { |
| 27 | 26 | try { |
| 28 | 27 | const { text } = req.body; |
| 29 | 28 | |
| @@ -9,7 +9,6 @@ import sanitize from 'sanitize-filename'; | ||
| 9 | 9 | import { sync as writeFileAtomicSync } from 'write-file-atomic'; |
| 10 | 10 | |
| 11 | 11 | import { getConfigValue, color } from '../util.js'; |
| 12 | -import { jsonParser } from '../express-common.js'; | |
| 13 | 12 | import { write } from '../character-card-parser.js'; |
| 14 | 13 | |
| 15 | 14 | const contentDirectory = path.join(process.cwd(), 'default/content'); |
| @@ -627,7 +626,7 @@ function isHostWhitelisted(host) { | ||
| 627 | 626 | |
| 628 | 627 | export const router = express.Router(); |
| 629 | 628 | |
| 630 | 629 | router.post('/importURL', jsonParser, async (request, response) => { |
| 631 | 630 | if (!request.body.url) { |
| 632 | 631 | return response.sendStatus(400); |
| 633 | 632 | } |
| @@ -713,7 +712,7 @@ router.post('/importURL', jsonParser, async (request, response) => { | ||
| 713 | 712 | } |
| 714 | 713 | }); |
| 715 | 714 | |
| 716 | 715 | router.post('/importUUID', jsonParser, async (request, response) => { |
| 717 | 716 | if (!request.body.url) { |
| 718 | 717 | return response.sendStatus(400); |
| 719 | 718 | } |
| @@ -6,7 +6,6 @@ import sanitize from 'sanitize-filename'; | ||
| 6 | 6 | import { default as simpleGit } from 'simple-git'; |
| 7 | 7 | |
| 8 | 8 | import { PUBLIC_DIRECTORIES } from '../constants.js'; |
| 9 | -import { jsonParser } from '../express-common.js'; | |
| 10 | 9 | |
| 11 | 10 | /** |
| 12 | 11 | * This function extracts the extension information from the manifest file. |
| @@ -60,7 +59,7 @@ export const router = express.Router(); | ||
| 60 | 59 | * |
| 61 | 60 | * @returns {void} |
| 62 | 61 | */ |
| 63 | 62 | router.post('/install', jsonParser, async (request, response) => { |
| 64 | 63 | if (!request.body.url) { |
| 65 | 64 | return response.status(400).send('Bad Request: URL is required in the request body.'); |
| 66 | 65 | } |
| @@ -114,7 +113,7 @@ router.post('/install', jsonParser, async (request, response) => { | ||
| 114 | 113 | * |
| 115 | 114 | * @returns {void} |
| 116 | 115 | */ |
| 117 | 116 | router.post('/update', jsonParser, async (request, response) => { |
| 118 | 117 | const git = simpleGit(); |
| 119 | 118 | if (!request.body.extensionName) { |
| 120 | 119 | return response.status(400).send('Bad Request: extensionName is required in the request body.'); |
| @@ -155,7 +154,7 @@ router.post('/update', jsonParser, async (request, response) => { | ||
| 155 | 154 | } |
| 156 | 155 | }); |
| 157 | 156 | |
| 158 | 157 | router.post('/move', jsonParser, async (request, response) => { |
| 159 | 158 | try { |
| 160 | 159 | const { extensionName, source, destination } = request.body; |
| 161 | 160 | |
| @@ -209,7 +208,7 @@ router.post('/move', jsonParser, async (request, response) => { | ||
| 209 | 208 | * |
| 210 | 209 | * @returns {void} |
| 211 | 210 | */ |
| 212 | 211 | router.post('/version', jsonParser, async (request, response) => { |
| 213 | 212 | const git = simpleGit(); |
| 214 | 213 | if (!request.body.extensionName) { |
| 215 | 214 | return response.status(400).send('Bad Request: extensionName is required in the request body.'); |
| @@ -256,7 +255,7 @@ router.post('/version', jsonParser, async (request, response) => { | ||
| 256 | 255 | * |
| 257 | 256 | * @returns {void} |
| 258 | 257 | */ |
| 259 | 258 | router.post('/delete', jsonParser, async (request, response) => { |
| 260 | 259 | if (!request.body.extensionName) { |
| 261 | 260 | return response.status(400).send('Bad Request: extensionName is required in the request body.'); |
| 262 | 261 | } |
| @@ -291,7 +290,7 @@ router.post('/delete', jsonParser, async (request, response) => { | ||
| 291 | 290 | * Discover the extension folders |
| 292 | 291 | * If the folder is called third-party, search for subfolders instead |
| 293 | 292 | */ |
| 294 | 293 | router.get('/discover', jsonParser, function (request, response) { |
| 295 | 294 | if (!fs.existsSync(path.join(request.user.directories.extensions))) { |
| 296 | 295 | fs.mkdirSync(path.join(request.user.directories.extensions)); |
| 297 | 296 | } |
| @@ -6,12 +6,11 @@ import sanitize from 'sanitize-filename'; | ||
| 6 | 6 | import { sync as writeFileSyncAtomic } from 'write-file-atomic'; |
| 7 | 7 | |
| 8 | 8 | import { validateAssetFileName } from './assets.js'; |
| 9 | -import { jsonParser } from '../express-common.js'; | |
| 10 | 9 | import { clientRelativePath } from '../util.js'; |
| 11 | 10 | |
| 12 | 11 | export const router = express.Router(); |
| 13 | 12 | |
| 14 | 13 | router.post('/sanitize-filename', jsonParser, async (request, response) => { |
| 15 | 14 | try { |
| 16 | 15 | const fileName = String(request.body.fileName); |
| 17 | 16 | if (!fileName) { |
| @@ -26,7 +25,7 @@ router.post('/sanitize-filename', jsonParser, async (request, response) => { | ||
| 26 | 25 | } |
| 27 | 26 | }); |
| 28 | 27 | |
| 29 | 28 | router.post('/upload', jsonParser, async (request, response) => { |
| 30 | 29 | try { |
| 31 | 30 | if (!request.body.name) { |
| 32 | 31 | return response.status(400).send('No upload name specified'); |
| @@ -52,7 +51,7 @@ router.post('/upload', jsonParser, async (request, response) => { | ||
| 52 | 51 | } |
| 53 | 52 | }); |
| 54 | 53 | |
| 55 | 54 | router.post('/delete', jsonParser, async (request, response) => { |
| 56 | 55 | try { |
| 57 | 56 | if (!request.body.path) { |
| 58 | 57 | return response.status(400).send('No path specified'); |
| @@ -76,7 +75,7 @@ router.post('/delete', jsonParser, async (request, response) => { | ||
| 76 | 75 | } |
| 77 | 76 | }); |
| 78 | 77 | |
| 79 | 78 | router.post('/verify', jsonParser, async (request, response) => { |
| 80 | 79 | try { |
| 81 | 80 | if (!Array.isArray(request.body.urls)) { |
| 82 | 81 | return response.status(400).send('No URLs specified'); |
| @@ -4,14 +4,13 @@ import express from 'express'; | ||
| 4 | 4 | import { speak, languages } from 'google-translate-api-x'; |
| 5 | 5 | |
| 6 | 6 | import { readSecret, SECRET_KEYS } from './secrets.js'; |
| 7 | -import { jsonParser } from '../express-common.js'; | |
| 8 | 7 | import { GEMINI_SAFETY } from '../constants.js'; |
| 9 | 8 | |
| 10 | 9 | const API_MAKERSUITE = 'https://generativelanguage.googleapis.com'; |
| 11 | 10 | |
| 12 | 11 | export const router = express.Router(); |
| 13 | 12 | |
| 14 | 13 | router.post('/caption-image', jsonParser, async (request, response) => { |
| 15 | 14 | try { |
| 16 | 15 | const mimeType = request.body.image.split(';')[0].split(':')[1]; |
| 17 | 16 | const base64Data = request.body.image.split(',')[1]; |
| @@ -75,7 +74,7 @@ router.post('/list-voices', (_, response) => { | ||
| 75 | 74 | return response.json(languages); |
| 76 | 75 | }); |
| 77 | 76 | |
| 78 | 77 | router.post('/generate-voice', jsonParser, async (request, response) => { |
| 79 | 78 | try { |
| 80 | 79 | const text = request.body.text; |
| 81 | 80 | const voice = request.body.voice ?? 'en'; |
| @@ -5,12 +5,11 @@ import express from 'express'; | ||
| 5 | 5 | import sanitize from 'sanitize-filename'; |
| 6 | 6 | import { sync as writeFileAtomicSync } from 'write-file-atomic'; |
| 7 | 7 | |
| 8 | -import { jsonParser } from '../express-common.js'; | |
| 9 | 8 | import { humanizedISO8601DateTime } from '../util.js'; |
| 10 | 9 | |
| 11 | 10 | export const router = express.Router(); |
| 12 | 11 | |
| 13 | 12 | router.post('/all', jsonParser, (request, response) => { |
| 14 | 13 | const groups = []; |
| 15 | 14 | |
| 16 | 15 | if (!fs.existsSync(request.user.directories.groups)) { |
| @@ -54,7 +53,7 @@ router.post('/all', jsonParser, (request, response) => { | ||
| 54 | 53 | return response.send(groups); |
| 55 | 54 | }); |
| 56 | 55 | |
| 57 | 56 | router.post('/create', jsonParser, (request, response) => { |
| 58 | 57 | if (!request.body) { |
| 59 | 58 | return response.sendStatus(400); |
| 60 | 59 | } |
| @@ -88,7 +87,7 @@ router.post('/create', jsonParser, (request, response) => { | ||
| 88 | 87 | return response.send(groupMetadata); |
| 89 | 88 | }); |
| 90 | 89 | |
| 91 | 90 | router.post('/edit', jsonParser, (request, response) => { |
| 92 | 91 | if (!request.body || !request.body.id) { |
| 93 | 92 | return response.sendStatus(400); |
| 94 | 93 | } |
| @@ -100,7 +99,7 @@ router.post('/edit', jsonParser, (request, response) => { | ||
| 100 | 99 | return response.send({ ok: true }); |
| 101 | 100 | }); |
| 102 | 101 | |
| 103 | 102 | router.post('/delete', jsonParser, async (request, response) => { |
| 104 | 103 | if (!request.body || !request.body.id) { |
| 105 | 104 | return response.sendStatus(400); |
| 106 | 105 | } |
| @@ -3,7 +3,6 @@ import express from 'express'; | ||
| 3 | 3 | import { AIHorde, ModelGenerationInputStableSamplers, ModelInterrogationFormTypes, HordeAsyncRequestStates } from '@zeldafan0225/ai_horde'; |
| 4 | 4 | import { getVersion, delay, Cache } from '../util.js'; |
| 5 | 5 | import { readSecret, SECRET_KEYS } from './secrets.js'; |
| 6 | -import { jsonParser } from '../express-common.js'; | |
| 7 | 6 | |
| 8 | 7 | const ANONYMOUS_KEY = '0000000000'; |
| 9 | 8 | const HORDE_TEXT_MODEL_METADATA_URL = 'https://raw.githubusercontent.com/db0/AI-Horde-text-model-reference/main/db.json'; |
| @@ -56,7 +55,7 @@ function sanitizeHordeImagePrompt(prompt) { | ||
| 56 | 55 | return prompt; |
| 57 | 56 | } |
| 58 | 57 | |
| 59 | 58 | router.post('/text-workers', jsonParser, async (request, response) => { |
| 60 | 59 | try { |
| 61 | 60 | const cachedWorkers = cache.get('workers'); |
| 62 | 61 | |
| @@ -94,7 +93,7 @@ async function mergeModelsAndMetadata(models, metadata) { | ||
| 94 | 93 | }); |
| 95 | 94 | } |
| 96 | 95 | |
| 97 | 96 | router.post('/text-models', jsonParser, async (request, response) => { |
| 98 | 97 | try { |
| 99 | 98 | const cachedModels = cache.get('models'); |
| 100 | 99 | if (cachedModels && !request.body.force) { |
| @@ -127,7 +126,7 @@ router.post('/text-models', jsonParser, async (request, response) => { | ||
| 127 | 126 | } |
| 128 | 127 | }); |
| 129 | 128 | |
| 130 | 129 | router.post('/status', jsonParser, async (_, response) => { |
| 131 | 130 | try { |
| 132 | 131 | const agent = await getClientAgent(); |
| 133 | 132 | const fetchResult = await fetch('https://aihorde.net/api/v2/status/heartbeat', { |
| @@ -143,7 +142,7 @@ router.post('/status', jsonParser, async (_, response) => { | ||
| 143 | 142 | } |
| 144 | 143 | }); |
| 145 | 144 | |
| 146 | 145 | router.post('/cancel-task', jsonParser, async (request, response) => { |
| 147 | 146 | try { |
| 148 | 147 | const taskId = request.body.taskId; |
| 149 | 148 | const agent = await getClientAgent(); |
| @@ -163,7 +162,7 @@ router.post('/cancel-task', jsonParser, async (request, response) => { | ||
| 163 | 162 | } |
| 164 | 163 | }); |
| 165 | 164 | |
| 166 | 165 | router.post('/task-status', jsonParser, async (request, response) => { |
| 167 | 166 | try { |
| 168 | 167 | const taskId = request.body.taskId; |
| 169 | 168 | const agent = await getClientAgent(); |
| @@ -182,7 +181,7 @@ router.post('/task-status', jsonParser, async (request, response) => { | ||
| 182 | 181 | } |
| 183 | 182 | }); |
| 184 | 183 | |
| 185 | 184 | router.post('/generate-text', jsonParser, async (request, response) => { |
| 186 | 185 | const apiKey = readSecret(request.user.directories, SECRET_KEYS.HORDE) || ANONYMOUS_KEY; |
| 187 | 186 | const url = 'https://aihorde.net/api/v2/generate/text/async'; |
| 188 | 187 | const agent = await getClientAgent(); |
| @@ -213,7 +212,7 @@ router.post('/generate-text', jsonParser, async (request, response) => { | ||
| 213 | 212 | } |
| 214 | 213 | }); |
| 215 | 214 | |
| 216 | 215 | router.post('/sd-samplers', jsonParser, async (_, response) => { |
| 217 | 216 | try { |
| 218 | 217 | const samplers = Object.values(ModelGenerationInputStableSamplers); |
| 219 | 218 | response.send(samplers); |
| @@ -223,7 +222,7 @@ router.post('/sd-samplers', jsonParser, async (_, response) => { | ||
| 223 | 222 | } |
| 224 | 223 | }); |
| 225 | 224 | |
| 226 | 225 | router.post('/sd-models', jsonParser, async (_, response) => { |
| 227 | 226 | try { |
| 228 | 227 | const ai_horde = await getHordeClient(); |
| 229 | 228 | const models = await ai_horde.getModels(); |
| @@ -234,7 +233,7 @@ router.post('/sd-models', jsonParser, async (_, response) => { | ||
| 234 | 233 | } |
| 235 | 234 | }); |
| 236 | 235 | |
| 237 | 236 | router.post('/caption-image', jsonParser, async (request, response) => { |
| 238 | 237 | try { |
| 239 | 238 | const api_key_horde = readSecret(request.user.directories, SECRET_KEYS.HORDE) || ANONYMOUS_KEY; |
| 240 | 239 | const ai_horde = await getHordeClient(); |
| @@ -286,7 +285,7 @@ router.post('/caption-image', jsonParser, async (request, response) => { | ||
| 286 | 285 | } |
| 287 | 286 | }); |
| 288 | 287 | |
| 289 | 288 | router.post('/user-info', jsonParser, async (request, response) => { |
| 290 | 289 | const api_key_horde = readSecret(request.user.directories, SECRET_KEYS.HORDE); |
| 291 | 290 | |
| 292 | 291 | if (!api_key_horde) { |
| @@ -303,7 +302,7 @@ router.post('/user-info', jsonParser, async (request, response) => { | ||
| 303 | 302 | } |
| 304 | 303 | }); |
| 305 | 304 | |
| 306 | 305 | router.post('/generate-image', jsonParser, async (request, response) => { |
| 307 | 306 | if (!request.body.prompt) { |
| 308 | 307 | return response.sendStatus(400); |
| 309 | 308 | } |
| @@ -5,7 +5,6 @@ import { Buffer } from 'node:buffer'; | ||
| 5 | 5 | import express from 'express'; |
| 6 | 6 | import sanitize from 'sanitize-filename'; |
| 7 | 7 | |
| 8 | -import { jsonParser } from '../express-common.js'; | |
| 9 | 8 | import { clientRelativePath, removeFileExtension, getImages } from '../util.js'; |
| 10 | 9 | |
| 11 | 10 | /** |
| @@ -36,7 +35,7 @@ export const router = express.Router(); | ||
| 36 | 35 | * @param {string} [request.body.ch_name] - Optional character name to determine the sub-directory. |
| 37 | 36 | * @returns {Object} response - The response object containing the path where the image was saved. |
| 38 | 37 | */ |
| 39 | 38 | router.post('/upload', jsonParser, async (request, response) => { |
| 40 | 39 | // Check for image data |
| 41 | 40 | if (!request.body || !request.body.image) { |
| 42 | 41 | return response.status(400).send({ error: 'No image data provided' }); |
| @@ -76,7 +75,7 @@ router.post('/upload', jsonParser, async (request, response) => { | ||
| 76 | 75 | } |
| 77 | 76 | }); |
| 78 | 77 | |
| 79 | 78 | router.post('/list/:folder?', jsonParser, (request, response) => { |
| 80 | 79 | try { |
| 81 | 80 | if (request.params.folder) { |
| 82 | 81 | if (request.body.folder) { |
| @@ -3,11 +3,9 @@ import express from 'express'; | ||
| 3 | 3 | import sanitize from 'sanitize-filename'; |
| 4 | 4 | import { sync as writeFileAtomicSync } from 'write-file-atomic'; |
| 5 | 5 | |
| 6 | -import { jsonParser } from '../express-common.js'; | |
| 7 | - | |
| 8 | 6 | export const router = express.Router(); |
| 9 | 7 | |
| 10 | 8 | router.post('/save', jsonParser, (request, response) => { |
| 11 | 9 | if (!request.body || !request.body.name) { |
| 12 | 10 | return response.sendStatus(400); |
| 13 | 11 | } |
| @@ -6,7 +6,6 @@ import express from 'express'; | ||
| 6 | 6 | |
| 7 | 7 | import { readSecret, SECRET_KEYS } from './secrets.js'; |
| 8 | 8 | import { readAllChunks, extractFileFromZipBuffer, forwardFetchResponse } from '../util.js'; |
| 9 | -import { jsonParser } from '../express-common.js'; | |
| 10 | 9 | |
| 11 | 10 | const API_NOVELAI = 'https://api.novelai.net'; |
| 12 | 11 | const TEXT_NOVELAI = 'https://text.novelai.net'; |
| @@ -115,7 +114,7 @@ function getRepPenaltyWhitelist(model) { | ||
| 115 | 114 | |
| 116 | 115 | export const router = express.Router(); |
| 117 | 116 | |
| 118 | 117 | router.post('/status', jsonParser, async function (req, res) { |
| 119 | 118 | if (!req.body) return res.sendStatus(400); |
| 120 | 119 | const api_key_novel = readSecret(req.user.directories, SECRET_KEYS.NOVEL); |
| 121 | 120 | |
| @@ -150,7 +149,7 @@ router.post('/status', jsonParser, async function (req, res) { | ||
| 150 | 149 | } |
| 151 | 150 | }); |
| 152 | 151 | |
| 153 | 152 | router.post('/generate', jsonParser, async function (req, res) { |
| 154 | 153 | if (!req.body) return res.sendStatus(400); |
| 155 | 154 | |
| 156 | 155 | const api_key_novel = readSecret(req.user.directories, SECRET_KEYS.NOVEL); |
| @@ -284,7 +283,7 @@ router.post('/generate', jsonParser, async function (req, res) { | ||
| 284 | 283 | } |
| 285 | 284 | }); |
| 286 | 285 | |
| 287 | 286 | router.post('/generate-image', jsonParser, async (request, response) => { |
| 288 | 287 | if (!request.body) { |
| 289 | 288 | return response.sendStatus(400); |
| 290 | 289 | } |
| @@ -418,7 +417,7 @@ router.post('/generate-image', jsonParser, async (request, response) => { | ||
| 418 | 417 | } |
| 419 | 418 | }); |
| 420 | 419 | |
| 421 | 420 | router.post('/generate-voice', jsonParser, async (request, response) => { |
| 422 | 421 | const token = readSecret(request.user.directories, SECRET_KEYS.NOVEL); |
| 423 | 422 | |
| 424 | 423 | if (!token) { |
| @@ -5,7 +5,6 @@ import fetch from 'node-fetch'; | ||
| 5 | 5 | import FormData from 'form-data'; |
| 6 | 6 | import express from 'express'; |
| 7 | 7 | |
| 8 | -import { jsonParser, urlencodedParser } from '../express-common.js'; | |
| 9 | 8 | import { getConfigValue, mergeObjectWithYaml, excludeKeysByYaml, trimV1 } from '../util.js'; |
| 10 | 9 | import { setAdditionalHeaders } from '../additional-headers.js'; |
| 11 | 10 | import { readSecret, SECRET_KEYS } from './secrets.js'; |
| @@ -13,7 +12,7 @@ import { OPENROUTER_HEADERS } from '../constants.js'; | ||
| 13 | 12 | |
| 14 | 13 | export const router = express.Router(); |
| 15 | 14 | |
| 16 | 15 | router.post('/caption-image', jsonParser, async (request, response) => { |
| 17 | 16 | try { |
| 18 | 17 | let key = ''; |
| 19 | 18 | let headers = {}; |
| @@ -189,7 +188,7 @@ router.post('/caption-image', jsonParser, async (request, response) => { | ||
| 189 | 188 | } |
| 190 | 189 | }); |
| 191 | 190 | |
| 192 | 191 | router.post('/transcribe-audio', urlencodedParser, async (request, response) => { |
| 193 | 192 | try { |
| 194 | 193 | const key = readSecret(request.user.directories, SECRET_KEYS.OPENAI); |
| 195 | 194 | |
| @@ -237,7 +236,7 @@ router.post('/transcribe-audio', urlencodedParser, async (request, response) => | ||
| 237 | 236 | } |
| 238 | 237 | }); |
| 239 | 238 | |
| 240 | 239 | router.post('/generate-voice', jsonParser, async (request, response) => { |
| 241 | 240 | try { |
| 242 | 241 | const key = readSecret(request.user.directories, SECRET_KEYS.OPENAI); |
| 243 | 242 | |
| @@ -276,7 +275,7 @@ router.post('/generate-voice', jsonParser, async (request, response) => { | ||
| 276 | 275 | } |
| 277 | 276 | }); |
| 278 | 277 | |
| 279 | 278 | router.post('/generate-image', jsonParser, async (request, response) => { |
| 280 | 279 | try { |
| 281 | 280 | const key = readSecret(request.user.directories, SECRET_KEYS.OPENAI); |
| 282 | 281 | |
| @@ -312,7 +311,7 @@ router.post('/generate-image', jsonParser, async (request, response) => { | ||
| 312 | 311 | |
| 313 | 312 | const custom = express.Router(); |
| 314 | 313 | |
| 315 | 314 | custom.post('/generate-voice', jsonParser, async (request, response) => { |
| 316 | 315 | try { |
| 317 | 316 | const key = readSecret(request.user.directories, SECRET_KEYS.CUSTOM_OPENAI_TTS); |
| 318 | 317 | const { input, provider_endpoint, response_format, voice, speed, model } = request.body; |
| @@ -1,10 +1,9 @@ | ||
| 1 | 1 | import express from 'express'; |
| 2 | -import { jsonParser } from '../express-common.js'; | |
| 3 | 2 | |
| 4 | 3 | export const router = express.Router(); |
| 5 | 4 | const API_OPENROUTER = 'https://openrouter.ai/api/v1'; |
| 6 | 5 | |
| 7 | 6 | router.post('/models/providers', jsonParser, async (req, res) => { |
| 8 | 7 | try { |
| 9 | 8 | const { model } = req.body; |
| 10 | 9 | const response = await fetch(`${API_OPENROUTER}/models/${model}/endpoints`, { |
| @@ -29,7 +28,7 @@ router.post('/models/providers', jsonParser, async (req, res) => { | ||
| 29 | 28 | } |
| 30 | 29 | }); |
| 31 | 30 | |
| 32 | 31 | router.post('/models/multimodal', jsonParser, async (_req, res) => { |
| 33 | 32 | try { |
| 34 | 33 | // The endpoint is available without authentication |
| 35 | 34 | const response = await fetch(`${API_OPENROUTER}/models`, { |
| @@ -6,7 +6,6 @@ import sanitize from 'sanitize-filename'; | ||
| 6 | 6 | import { sync as writeFileAtomicSync } from 'write-file-atomic'; |
| 7 | 7 | |
| 8 | 8 | import { getDefaultPresetFile, getDefaultPresets } from './content-manager.js'; |
| 9 | -import { jsonParser } from '../express-common.js'; | |
| 10 | 9 | |
| 11 | 10 | /** |
| 12 | 11 | * Gets the folder and extension for the preset settings based on the API source ID. |
| @@ -38,7 +37,7 @@ function getPresetSettingsByAPI(apiId, directories) { | ||
| 38 | 37 | |
| 39 | 38 | export const router = express.Router(); |
| 40 | 39 | |
| 41 | 40 | router.post('/save', jsonParser, function (request, response) { |
| 42 | 41 | const name = sanitize(request.body.name); |
| 43 | 42 | if (!request.body.preset || !name) { |
| 44 | 43 | return response.sendStatus(400); |
| @@ -56,7 +55,7 @@ router.post('/save', jsonParser, function (request, response) { | ||
| 56 | 55 | return response.send({ name }); |
| 57 | 56 | }); |
| 58 | 57 | |
| 59 | 58 | router.post('/delete', jsonParser, function (request, response) { |
| 60 | 59 | const name = sanitize(request.body.name); |
| 61 | 60 | if (!name) { |
| 62 | 61 | return response.sendStatus(400); |
| @@ -79,7 +78,7 @@ router.post('/delete', jsonParser, function (request, response) { | ||
| 79 | 78 | } |
| 80 | 79 | }); |
| 81 | 80 | |
| 82 | 81 | router.post('/restore', jsonParser, function (request, response) { |
| 83 | 82 | try { |
| 84 | 83 | const settings = getPresetSettingsByAPI(request.body.apiId, request.user.directories); |
| 85 | 84 | const name = sanitize(request.body.name); |
| @@ -102,7 +101,7 @@ router.post('/restore', jsonParser, function (request, response) { | ||
| 102 | 101 | }); |
| 103 | 102 | |
| 104 | 103 | // TODO: Merge with /api/presets/save |
| 105 | 104 | router.post('/save-openai', jsonParser, function (request, response) { |
| 106 | 105 | if (!request.body || typeof request.query.name !== 'string') return response.sendStatus(400); |
| 107 | 106 | const name = sanitize(request.query.name); |
| 108 | 107 | if (!name) return response.sendStatus(400); |
| @@ -114,7 +113,7 @@ router.post('/save-openai', jsonParser, function (request, response) { | ||
| 114 | 113 | }); |
| 115 | 114 | |
| 116 | 115 | // TODO: Merge with /api/presets/delete |
| 117 | 116 | router.post('/delete-openai', jsonParser, function (request, response) { |
| 118 | 117 | if (!request.body || !request.body.name) { |
| 119 | 118 | return response.sendStatus(400); |
| 120 | 119 | } |
| @@ -5,11 +5,9 @@ import express from 'express'; | ||
| 5 | 5 | import sanitize from 'sanitize-filename'; |
| 6 | 6 | import { sync as writeFileAtomicSync } from 'write-file-atomic'; |
| 7 | 7 | |
| 8 | -import { jsonParser } from '../express-common.js'; | |
| 9 | - | |
| 10 | 8 | export const router = express.Router(); |
| 11 | 9 | |
| 12 | 10 | router.post('/save', jsonParser, (request, response) => { |
| 13 | 11 | if (!request.body || !request.body.name) { |
| 14 | 12 | return response.sendStatus(400); |
| 15 | 13 | } |
| @@ -20,7 +18,7 @@ router.post('/save', jsonParser, (request, response) => { | ||
| 20 | 18 | return response.sendStatus(200); |
| 21 | 19 | }); |
| 22 | 20 | |
| 23 | 21 | router.post('/delete', jsonParser, (request, response) => { |
| 24 | 22 | if (!request.body || !request.body.name) { |
| 25 | 23 | return response.sendStatus(400); |
| 26 | 24 | } |
| @@ -3,7 +3,6 @@ import express from 'express'; | ||
| 3 | 3 | |
| 4 | 4 | import { decode } from 'html-entities'; |
| 5 | 5 | import { readSecret, SECRET_KEYS } from './secrets.js'; |
| 6 | -import { jsonParser } from '../express-common.js'; | |
| 7 | 6 | import { trimV1 } from '../util.js'; |
| 8 | 7 | import { setAdditionalHeaders } from '../additional-headers.js'; |
| 9 | 8 | |
| @@ -91,7 +90,7 @@ async function extractTranscript(videoPageBody, lang) { | ||
| 91 | 90 | return transcriptText; |
| 92 | 91 | } |
| 93 | 92 | |
| 94 | 93 | router.post('/serpapi', jsonParser, async (request, response) => { |
| 95 | 94 | try { |
| 96 | 95 | const key = readSecret(request.user.directories, SECRET_KEYS.SERPAPI); |
| 97 | 96 | |
| @@ -124,7 +123,7 @@ router.post('/serpapi', jsonParser, async (request, response) => { | ||
| 124 | 123 | * Get the transcript of a YouTube video |
| 125 | 124 | * @copyright https://github.com/Kakulukian/youtube-transcript (MIT License) |
| 126 | 125 | */ |
| 127 | 126 | router.post('/transcript', jsonParser, async (request, response) => { |
| 128 | 127 | try { |
| 129 | 128 | const id = request.body.id; |
| 130 | 129 | const lang = request.body.lang; |
| @@ -161,7 +160,7 @@ router.post('/transcript', jsonParser, async (request, response) => { | ||
| 161 | 160 | } |
| 162 | 161 | }); |
| 163 | 162 | |
| 164 | 163 | router.post('/searxng', jsonParser, async (request, response) => { |
| 165 | 164 | try { |
| 166 | 165 | const { baseUrl, query, preferences, categories } = request.body; |
| 167 | 166 | |
| @@ -215,7 +214,7 @@ router.post('/searxng', jsonParser, async (request, response) => { | ||
| 215 | 214 | } |
| 216 | 215 | }); |
| 217 | 216 | |
| 218 | 217 | router.post('/tavily', jsonParser, async (request, response) => { |
| 219 | 218 | try { |
| 220 | 219 | const apiKey = readSecret(request.user.directories, SECRET_KEYS.TAVILY); |
| 221 | 220 | |
| @@ -264,7 +263,7 @@ router.post('/tavily', jsonParser, async (request, response) => { | ||
| 264 | 263 | } |
| 265 | 264 | }); |
| 266 | 265 | |
| 267 | 266 | router.post('/koboldcpp', jsonParser, async (request, response) => { |
| 268 | 267 | try { |
| 269 | 268 | const { query, url } = request.body; |
| 270 | 269 | |
| @@ -300,7 +299,7 @@ router.post('/koboldcpp', jsonParser, async (request, response) => { | ||
| 300 | 299 | } |
| 301 | 300 | }); |
| 302 | 301 | |
| 303 | 302 | router.post('/serper', jsonParser, async (request, response) => { |
| 304 | 303 | try { |
| 305 | 304 | const key = readSecret(request.user.directories, SECRET_KEYS.SERPER); |
| 306 | 305 | |
| @@ -342,7 +341,7 @@ router.post('/serper', jsonParser, async (request, response) => { | ||
| 342 | 341 | } |
| 343 | 342 | }); |
| 344 | 343 | |
| 345 | 344 | router.post('/visit', jsonParser, async (request, response) => { |
| 346 | 345 | try { |
| 347 | 346 | const url = request.body.url; |
| 348 | 347 | const html = Boolean(request.body.html ?? true); |
| @@ -4,7 +4,6 @@ import path from 'node:path'; | ||
| 4 | 4 | import express from 'express'; |
| 5 | 5 | import { sync as writeFileAtomicSync } from 'write-file-atomic'; |
| 6 | 6 | import { getConfigValue } from '../util.js'; |
| 7 | -import { jsonParser } from '../express-common.js'; | |
| 8 | 7 | |
| 9 | 8 | export const SECRETS_FILE = 'secrets.json'; |
| 10 | 9 | export const SECRET_KEYS = { |
| @@ -164,7 +163,7 @@ export function getAllSecrets(directories) { | ||
| 164 | 163 | |
| 165 | 164 | export const router = express.Router(); |
| 166 | 165 | |
| 167 | 166 | router.post('/write', jsonParser, (request, response) => { |
| 168 | 167 | const key = request.body.key; |
| 169 | 168 | const value = request.body.value; |
| 170 | 169 | |
| @@ -172,7 +171,7 @@ router.post('/write', jsonParser, (request, response) => { | ||
| 172 | 171 | return response.send('ok'); |
| 173 | 172 | }); |
| 174 | 173 | |
| 175 | 174 | router.post('/read', jsonParser, (request, response) => { |
| 176 | 175 | try { |
| 177 | 176 | const state = readSecretState(request.user.directories); |
| 178 | 177 | return response.send(state); |
| @@ -182,7 +181,7 @@ router.post('/read', jsonParser, (request, response) => { | ||
| 182 | 181 | } |
| 183 | 182 | }); |
| 184 | 183 | |
| 185 | 184 | router.post('/view', jsonParser, async (request, response) => { |
| 186 | 185 | const allowKeysExposure = getConfigValue('allowKeysExposure', false, 'boolean'); |
| 187 | 186 | |
| 188 | 187 | if (!allowKeysExposure) { |
| @@ -204,7 +203,7 @@ router.post('/view', jsonParser, async (request, response) => { | ||
| 204 | 203 | } |
| 205 | 204 | }); |
| 206 | 205 | |
| 207 | 206 | router.post('/find', jsonParser, (request, response) => { |
| 208 | 207 | const allowKeysExposure = getConfigValue('allowKeysExposure', false, 'boolean'); |
| 209 | 208 | const key = request.body.key; |
| 210 | 209 | |
| @@ -7,7 +7,6 @@ import { sync as writeFileAtomicSync } from 'write-file-atomic'; | ||
| 7 | 7 | |
| 8 | 8 | import { SETTINGS_FILE } from '../constants.js'; |
| 9 | 9 | import { getConfigValue, generateTimestamp, removeOldBackups } from '../util.js'; |
| 10 | -import { jsonParser } from '../express-common.js'; | |
| 11 | 10 | import { getAllUserHandles, getUserDirectories } from '../users.js'; |
| 12 | 11 | import { getFileNameValidationFunction } from '../middleware/validateFileName.js'; |
| 13 | 12 | |
| @@ -195,7 +194,7 @@ function getLatestBackup(handle) { | ||
| 195 | 194 | |
| 196 | 195 | export const router = express.Router(); |
| 197 | 196 | |
| 198 | 197 | router.post('/save', jsonParser, function (request, response) { |
| 199 | 198 | try { |
| 200 | 199 | const pathToSettings = path.join(request.user.directories.root, SETTINGS_FILE); |
| 201 | 200 | writeFileAtomicSync(pathToSettings, JSON.stringify(request.body, null, 4), 'utf8'); |
| @@ -208,7 +207,7 @@ router.post('/save', jsonParser, function (request, response) { | ||
| 208 | 207 | }); |
| 209 | 208 | |
| 210 | 209 | // Wintermute's code |
| 211 | 210 | router.post('/get', jsonParser, (request, response) => { |
| 212 | 211 | let settings; |
| 213 | 212 | try { |
| 214 | 213 | const pathToSettings = path.join(request.user.directories.root, SETTINGS_FILE); |
| @@ -279,7 +278,7 @@ router.post('/get', jsonParser, (request, response) => { | ||
| 279 | 278 | }); |
| 280 | 279 | }); |
| 281 | 280 | |
| 282 | 281 | router.post('/get-snapshots', jsonParser, async (request, response) => { |
| 283 | 282 | try { |
| 284 | 283 | const snapshots = fs.readdirSync(request.user.directories.backups); |
| 285 | 284 | const userFilesPattern = getFilePrefix(request.user.profile.handle); |
| @@ -297,7 +296,7 @@ router.post('/get-snapshots', jsonParser, async (request, response) => { | ||
| 297 | 296 | } |
| 298 | 297 | }); |
| 299 | 298 | |
| 300 | 299 | router.post('/load-snapshot', jsonParser, getFileNameValidationFunction('name'), async (request, response) => { |
| 301 | 300 | try { |
| 302 | 301 | const userFilesPattern = getFilePrefix(request.user.profile.handle); |
| 303 | 302 | |
| @@ -321,7 +320,7 @@ router.post('/load-snapshot', jsonParser, getFileNameValidationFunction('name'), | ||
| 321 | 320 | } |
| 322 | 321 | }); |
| 323 | 322 | |
| 324 | 323 | router.post('/make-snapshot', jsonParser, async (request, response) => { |
| 325 | 324 | try { |
| 326 | 325 | backupUserSettings(request.user.profile.handle, false); |
| 327 | 326 | response.sendStatus(204); |
| @@ -331,7 +330,7 @@ router.post('/make-snapshot', jsonParser, async (request, response) => { | ||
| 331 | 330 | } |
| 332 | 331 | }); |
| 333 | 332 | |
| 334 | 333 | router.post('/restore-snapshot', jsonParser, getFileNameValidationFunction('name'), async (request, response) => { |
| 335 | 334 | try { |
| 336 | 335 | const userFilesPattern = getFilePrefix(request.user.profile.handle); |
| 337 | 336 | |
| @@ -1,7 +1,6 @@ | ||
| 1 | 1 | import { Buffer } from 'node:buffer'; |
| 2 | 2 | import express from 'express'; |
| 3 | 3 | import wavefile from 'wavefile'; |
| 4 | -import { jsonParser } from '../express-common.js'; | |
| 5 | 4 | import { getPipeline } from '../transformers.js'; |
| 6 | 5 | |
| 7 | 6 | export const router = express.Router(); |
| @@ -34,7 +33,7 @@ function getWaveFile(audio) { | ||
| 34 | 33 | return audioData; |
| 35 | 34 | } |
| 36 | 35 | |
| 37 | 36 | router.post('/recognize', jsonParser, async (req, res) => { |
| 38 | 37 | try { |
| 39 | 38 | const TASK = 'automatic-speech-recognition'; |
| 40 | 39 | const { model, audio, lang } = req.body; |
| @@ -53,7 +52,7 @@ router.post('/recognize', jsonParser, async (req, res) => { | ||
| 53 | 52 | } |
| 54 | 53 | }); |
| 55 | 54 | |
| 56 | 55 | router.post('/synthesize', jsonParser, async (req, res) => { |
| 57 | 56 | try { |
| 58 | 57 | const TASK = 'text-to-speech'; |
| 59 | 58 | const { text, model, speaker } = req.body; |
| @@ -7,7 +7,6 @@ import sanitize from 'sanitize-filename'; | ||
| 7 | 7 | import { sync as writeFileAtomicSync } from 'write-file-atomic'; |
| 8 | 8 | |
| 9 | 9 | import { getImageBuffers } from '../util.js'; |
| 10 | -import { jsonParser, urlencodedParser } from '../express-common.js'; | |
| 11 | 10 | |
| 12 | 11 | /** |
| 13 | 12 | * Gets the path to the sprites folder for the provided character name |
| @@ -109,7 +108,7 @@ export function importRisuSprites(directories, data) { | ||
| 109 | 108 | |
| 110 | 109 | export const router = express.Router(); |
| 111 | 110 | |
| 112 | 111 | router.get('/get', jsonParser, function (request, response) { |
| 113 | 112 | const name = String(request.query.name); |
| 114 | 113 | const isSubfolder = name.includes('/'); |
| 115 | 114 | const spritesPath = getSpritesPath(request.user.directories, name, isSubfolder); |
| @@ -144,7 +143,7 @@ router.get('/get', jsonParser, function (request, response) { | ||
| 144 | 143 | return response.send(sprites); |
| 145 | 144 | }); |
| 146 | 145 | |
| 147 | 146 | router.post('/delete', jsonParser, async (request, response) => { |
| 148 | 147 | const label = request.body.label; |
| 149 | 148 | const name = request.body.name; |
| 150 | 149 | const spriteName = request.body.spriteName || label; |
| @@ -177,7 +176,7 @@ router.post('/delete', jsonParser, async (request, response) => { | ||
| 177 | 176 | } |
| 178 | 177 | }); |
| 179 | 178 | |
| 180 | 179 | router.post('/upload-zip', urlencodedParser, async (request, response) => { |
| 181 | 180 | const file = request.file; |
| 182 | 181 | const name = request.body.name; |
| 183 | 182 | |
| @@ -224,7 +223,7 @@ router.post('/upload-zip', urlencodedParser, async (request, response) => { | ||
| 224 | 223 | } |
| 225 | 224 | }); |
| 226 | 225 | |
| 227 | 226 | router.post('/upload', urlencodedParser, async (request, response) => { |
| 228 | 227 | const file = request.file; |
| 229 | 228 | const label = request.body.label; |
| 230 | 229 | const name = request.body.name; |
| @@ -10,7 +10,6 @@ import urlJoin from 'url-join'; | ||
| 10 | 10 | import _ from 'lodash'; |
| 11 | 11 | |
| 12 | 12 | import { delay, getBasicAuthHeader, tryParse } from '../util.js'; |
| 13 | -import { jsonParser } from '../express-common.js'; | |
| 14 | 13 | import { readSecret, SECRET_KEYS } from './secrets.js'; |
| 15 | 14 | |
| 16 | 15 | /** |
| @@ -27,7 +26,7 @@ function getComfyWorkflows(directories) { | ||
| 27 | 26 | |
| 28 | 27 | export const router = express.Router(); |
| 29 | 28 | |
| 30 | 29 | router.post('/ping', jsonParser, async (request, response) => { |
| 31 | 30 | try { |
| 32 | 31 | const url = new URL(request.body.url); |
| 33 | 32 | url.pathname = '/sdapi/v1/options'; |
| @@ -50,7 +49,7 @@ router.post('/ping', jsonParser, async (request, response) => { | ||
| 50 | 49 | } |
| 51 | 50 | }); |
| 52 | 51 | |
| 53 | 52 | router.post('/upscalers', jsonParser, async (request, response) => { |
| 54 | 53 | try { |
| 55 | 54 | async function getUpscalerModels() { |
| 56 | 55 | const url = new URL(request.body.url); |
| @@ -104,7 +103,7 @@ router.post('/upscalers', jsonParser, async (request, response) => { | ||
| 104 | 103 | } |
| 105 | 104 | }); |
| 106 | 105 | |
| 107 | 106 | router.post('/vaes', jsonParser, async (request, response) => { |
| 108 | 107 | try { |
| 109 | 108 | const autoUrl = new URL(request.body.url); |
| 110 | 109 | autoUrl.pathname = '/sdapi/v1/sd-vae'; |
| @@ -136,7 +135,7 @@ router.post('/vaes', jsonParser, async (request, response) => { | ||
| 136 | 135 | } |
| 137 | 136 | }); |
| 138 | 137 | |
| 139 | 138 | router.post('/samplers', jsonParser, async (request, response) => { |
| 140 | 139 | try { |
| 141 | 140 | const url = new URL(request.body.url); |
| 142 | 141 | url.pathname = '/sdapi/v1/samplers'; |
| @@ -163,7 +162,7 @@ router.post('/samplers', jsonParser, async (request, response) => { | ||
| 163 | 162 | } |
| 164 | 163 | }); |
| 165 | 164 | |
| 166 | 165 | router.post('/schedulers', jsonParser, async (request, response) => { |
| 167 | 166 | try { |
| 168 | 167 | const url = new URL(request.body.url); |
| 169 | 168 | url.pathname = '/sdapi/v1/schedulers'; |
| @@ -189,7 +188,7 @@ router.post('/schedulers', jsonParser, async (request, response) => { | ||
| 189 | 188 | } |
| 190 | 189 | }); |
| 191 | 190 | |
| 192 | 191 | router.post('/models', jsonParser, async (request, response) => { |
| 193 | 192 | try { |
| 194 | 193 | const url = new URL(request.body.url); |
| 195 | 194 | url.pathname = '/sdapi/v1/sd-models'; |
| @@ -215,7 +214,7 @@ router.post('/models', jsonParser, async (request, response) => { | ||
| 215 | 214 | } |
| 216 | 215 | }); |
| 217 | 216 | |
| 218 | 217 | router.post('/get-model', jsonParser, async (request, response) => { |
| 219 | 218 | try { |
| 220 | 219 | const url = new URL(request.body.url); |
| 221 | 220 | url.pathname = '/sdapi/v1/options'; |
| @@ -235,7 +234,7 @@ router.post('/get-model', jsonParser, async (request, response) => { | ||
| 235 | 234 | } |
| 236 | 235 | }); |
| 237 | 236 | |
| 238 | 237 | router.post('/set-model', jsonParser, async (request, response) => { |
| 239 | 238 | try { |
| 240 | 239 | async function getProgress() { |
| 241 | 240 | const url = new URL(request.body.url); |
| @@ -294,7 +293,7 @@ router.post('/set-model', jsonParser, async (request, response) => { | ||
| 294 | 293 | } |
| 295 | 294 | }); |
| 296 | 295 | |
| 297 | 296 | router.post('/generate', jsonParser, async (request, response) => { |
| 298 | 297 | try { |
| 299 | 298 | try { |
| 300 | 299 | const optionsUrl = new URL(request.body.url); |
| @@ -349,7 +348,7 @@ router.post('/generate', jsonParser, async (request, response) => { | ||
| 349 | 348 | } |
| 350 | 349 | }); |
| 351 | 350 | |
| 352 | 351 | router.post('/sd-next/upscalers', jsonParser, async (request, response) => { |
| 353 | 352 | try { |
| 354 | 353 | const url = new URL(request.body.url); |
| 355 | 354 | url.pathname = '/sdapi/v1/upscalers'; |
| @@ -384,7 +383,7 @@ router.post('/sd-next/upscalers', jsonParser, async (request, response) => { | ||
| 384 | 383 | |
| 385 | 384 | const comfy = express.Router(); |
| 386 | 385 | |
| 387 | 386 | comfy.post('/ping', jsonParser, async (request, response) => { |
| 388 | 387 | try { |
| 389 | 388 | const url = new URL(urlJoin(request.body.url, '/system_stats')); |
| 390 | 389 | |
| @@ -400,7 +399,7 @@ comfy.post('/ping', jsonParser, async (request, response) => { | ||
| 400 | 399 | } |
| 401 | 400 | }); |
| 402 | 401 | |
| 403 | 402 | comfy.post('/samplers', jsonParser, async (request, response) => { |
| 404 | 403 | try { |
| 405 | 404 | const url = new URL(urlJoin(request.body.url, '/object_info')); |
| 406 | 405 | |
| @@ -418,7 +417,7 @@ comfy.post('/samplers', jsonParser, async (request, response) => { | ||
| 418 | 417 | } |
| 419 | 418 | }); |
| 420 | 419 | |
| 421 | 420 | comfy.post('/models', jsonParser, async (request, response) => { |
| 422 | 421 | try { |
| 423 | 422 | const url = new URL(urlJoin(request.body.url, '/object_info')); |
| 424 | 423 | |
| @@ -446,7 +445,7 @@ comfy.post('/models', jsonParser, async (request, response) => { | ||
| 446 | 445 | } |
| 447 | 446 | }); |
| 448 | 447 | |
| 449 | 448 | comfy.post('/schedulers', jsonParser, async (request, response) => { |
| 450 | 449 | try { |
| 451 | 450 | const url = new URL(urlJoin(request.body.url, '/object_info')); |
| 452 | 451 | |
| @@ -464,7 +463,7 @@ comfy.post('/schedulers', jsonParser, async (request, response) => { | ||
| 464 | 463 | } |
| 465 | 464 | }); |
| 466 | 465 | |
| 467 | 466 | comfy.post('/vaes', jsonParser, async (request, response) => { |
| 468 | 467 | try { |
| 469 | 468 | const url = new URL(urlJoin(request.body.url, '/object_info')); |
| 470 | 469 | |
| @@ -482,7 +481,7 @@ comfy.post('/vaes', jsonParser, async (request, response) => { | ||
| 482 | 481 | } |
| 483 | 482 | }); |
| 484 | 483 | |
| 485 | 484 | comfy.post('/workflows', jsonParser, async (request, response) => { |
| 486 | 485 | try { |
| 487 | 486 | const data = getComfyWorkflows(request.user.directories); |
| 488 | 487 | return response.send(data); |
| @@ -492,7 +491,7 @@ comfy.post('/workflows', jsonParser, async (request, response) => { | ||
| 492 | 491 | } |
| 493 | 492 | }); |
| 494 | 493 | |
| 495 | 494 | comfy.post('/workflow', jsonParser, async (request, response) => { |
| 496 | 495 | try { |
| 497 | 496 | let filePath = path.join(request.user.directories.comfyWorkflows, sanitize(String(request.body.file_name))); |
| 498 | 497 | if (!fs.existsSync(filePath)) { |
| @@ -506,7 +505,7 @@ comfy.post('/workflow', jsonParser, async (request, response) => { | ||
| 506 | 505 | } |
| 507 | 506 | }); |
| 508 | 507 | |
| 509 | 508 | comfy.post('/save-workflow', jsonParser, async (request, response) => { |
| 510 | 509 | try { |
| 511 | 510 | const filePath = path.join(request.user.directories.comfyWorkflows, sanitize(String(request.body.file_name))); |
| 512 | 511 | writeFileAtomicSync(filePath, request.body.workflow, 'utf8'); |
| @@ -518,7 +517,7 @@ comfy.post('/save-workflow', jsonParser, async (request, response) => { | ||
| 518 | 517 | } |
| 519 | 518 | }); |
| 520 | 519 | |
| 521 | 520 | comfy.post('/delete-workflow', jsonParser, async (request, response) => { |
| 522 | 521 | try { |
| 523 | 522 | const filePath = path.join(request.user.directories.comfyWorkflows, sanitize(String(request.body.file_name))); |
| 524 | 523 | if (fs.existsSync(filePath)) { |
| @@ -531,7 +530,7 @@ comfy.post('/delete-workflow', jsonParser, async (request, response) => { | ||
| 531 | 530 | } |
| 532 | 531 | }); |
| 533 | 532 | |
| 534 | 533 | comfy.post('/generate', jsonParser, async (request, response) => { |
| 535 | 534 | try { |
| 536 | 535 | let item; |
| 537 | 536 | const url = new URL(urlJoin(request.body.url, '/prompt')); |
| @@ -599,7 +598,7 @@ comfy.post('/generate', jsonParser, async (request, response) => { | ||
| 599 | 598 | |
| 600 | 599 | const together = express.Router(); |
| 601 | 600 | |
| 602 | 601 | together.post('/models', jsonParser, async (request, response) => { |
| 603 | 602 | try { |
| 604 | 603 | const key = readSecret(request.user.directories, SECRET_KEYS.TOGETHERAI); |
| 605 | 604 | |
| @@ -638,7 +637,7 @@ together.post('/models', jsonParser, async (request, response) => { | ||
| 638 | 637 | } |
| 639 | 638 | }); |
| 640 | 639 | |
| 641 | 640 | together.post('/generate', jsonParser, async (request, response) => { |
| 642 | 641 | try { |
| 643 | 642 | const key = readSecret(request.user.directories, SECRET_KEYS.TOGETHERAI); |
| 644 | 643 | |
| @@ -694,7 +693,7 @@ together.post('/generate', jsonParser, async (request, response) => { | ||
| 694 | 693 | |
| 695 | 694 | const drawthings = express.Router(); |
| 696 | 695 | |
| 697 | 696 | drawthings.post('/ping', jsonParser, async (request, response) => { |
| 698 | 697 | try { |
| 699 | 698 | const url = new URL(request.body.url); |
| 700 | 699 | url.pathname = '/'; |
| @@ -714,7 +713,7 @@ drawthings.post('/ping', jsonParser, async (request, response) => { | ||
| 714 | 713 | } |
| 715 | 714 | }); |
| 716 | 715 | |
| 717 | 716 | drawthings.post('/get-model', jsonParser, async (request, response) => { |
| 718 | 717 | try { |
| 719 | 718 | const url = new URL(request.body.url); |
| 720 | 719 | url.pathname = '/'; |
| @@ -733,7 +732,7 @@ drawthings.post('/get-model', jsonParser, async (request, response) => { | ||
| 733 | 732 | } |
| 734 | 733 | }); |
| 735 | 734 | |
| 736 | 735 | drawthings.post('/get-upscaler', jsonParser, async (request, response) => { |
| 737 | 736 | try { |
| 738 | 737 | const url = new URL(request.body.url); |
| 739 | 738 | url.pathname = '/'; |
| @@ -752,7 +751,7 @@ drawthings.post('/get-upscaler', jsonParser, async (request, response) => { | ||
| 752 | 751 | } |
| 753 | 752 | }); |
| 754 | 753 | |
| 755 | 754 | drawthings.post('/generate', jsonParser, async (request, response) => { |
| 756 | 755 | try { |
| 757 | 756 | console.debug('SD DrawThings API request:', request.body); |
| 758 | 757 | |
| @@ -788,7 +787,7 @@ drawthings.post('/generate', jsonParser, async (request, response) => { | ||
| 788 | 787 | |
| 789 | 788 | const pollinations = express.Router(); |
| 790 | 789 | |
| 791 | 790 | pollinations.post('/models', jsonParser, async (_request, response) => { |
| 792 | 791 | try { |
| 793 | 792 | const modelsUrl = new URL('https://image.pollinations.ai/models'); |
| 794 | 793 | const result = await fetch(modelsUrl); |
| @@ -813,7 +812,7 @@ pollinations.post('/models', jsonParser, async (_request, response) => { | ||
| 813 | 812 | } |
| 814 | 813 | }); |
| 815 | 814 | |
| 816 | 815 | pollinations.post('/generate', jsonParser, async (request, response) => { |
| 817 | 816 | try { |
| 818 | 817 | const promptUrl = new URL(`https://image.pollinations.ai/prompt/${encodeURIComponent(request.body.prompt)}`); |
| 819 | 818 | const params = new URLSearchParams({ |
| @@ -850,7 +849,7 @@ pollinations.post('/generate', jsonParser, async (request, response) => { | ||
| 850 | 849 | |
| 851 | 850 | const stability = express.Router(); |
| 852 | 851 | |
| 853 | 852 | stability.post('/generate', jsonParser, async (request, response) => { |
| 854 | 853 | try { |
| 855 | 854 | const key = readSecret(request.user.directories, SECRET_KEYS.STABILITY); |
| 856 | 855 | |
| @@ -910,7 +909,7 @@ stability.post('/generate', jsonParser, async (request, response) => { | ||
| 910 | 909 | |
| 911 | 910 | const blockentropy = express.Router(); |
| 912 | 911 | |
| 913 | 912 | blockentropy.post('/models', jsonParser, async (request, response) => { |
| 914 | 913 | try { |
| 915 | 914 | const key = readSecret(request.user.directories, SECRET_KEYS.BLOCKENTROPY); |
| 916 | 915 | |
| @@ -946,7 +945,7 @@ blockentropy.post('/models', jsonParser, async (request, response) => { | ||
| 946 | 945 | } |
| 947 | 946 | }); |
| 948 | 947 | |
| 949 | 948 | blockentropy.post('/generate', jsonParser, async (request, response) => { |
| 950 | 949 | try { |
| 951 | 950 | const key = readSecret(request.user.directories, SECRET_KEYS.BLOCKENTROPY); |
| 952 | 951 | |
| @@ -993,7 +992,7 @@ blockentropy.post('/generate', jsonParser, async (request, response) => { | ||
| 993 | 992 | |
| 994 | 993 | const huggingface = express.Router(); |
| 995 | 994 | |
| 996 | 995 | huggingface.post('/generate', jsonParser, async (request, response) => { |
| 997 | 996 | try { |
| 998 | 997 | const key = readSecret(request.user.directories, SECRET_KEYS.HUGGINGFACE); |
| 999 | 998 | |
| @@ -1032,7 +1031,7 @@ huggingface.post('/generate', jsonParser, async (request, response) => { | ||
| 1032 | 1031 | |
| 1033 | 1032 | const nanogpt = express.Router(); |
| 1034 | 1033 | |
| 1035 | 1034 | nanogpt.post('/models', jsonParser, async (request, response) => { |
| 1036 | 1035 | try { |
| 1037 | 1036 | const key = readSecret(request.user.directories, SECRET_KEYS.NANOGPT); |
| 1038 | 1037 | |
| @@ -1072,7 +1071,7 @@ nanogpt.post('/models', jsonParser, async (request, response) => { | ||
| 1072 | 1071 | } |
| 1073 | 1072 | }); |
| 1074 | 1073 | |
| 1075 | 1074 | nanogpt.post('/generate', jsonParser, async (request, response) => { |
| 1076 | 1075 | try { |
| 1077 | 1076 | const key = readSecret(request.user.directories, SECRET_KEYS.NANOGPT); |
| 1078 | 1077 | |
| @@ -1116,7 +1115,7 @@ nanogpt.post('/generate', jsonParser, async (request, response) => { | ||
| 1116 | 1115 | |
| 1117 | 1116 | const bfl = express.Router(); |
| 1118 | 1117 | |
| 1119 | 1118 | bfl.post('/generate', jsonParser, async (request, response) => { |
| 1120 | 1119 | try { |
| 1121 | 1120 | const key = readSecret(request.user.directories, SECRET_KEYS.BFL); |
| 1122 | 1121 | |
| @@ -1230,7 +1229,7 @@ bfl.post('/generate', jsonParser, async (request, response) => { | ||
| 1230 | 1229 | |
| 1231 | 1230 | const falai = express.Router(); |
| 1232 | 1231 | |
| 1233 | 1232 | falai.post('/models', jsonParser, async (_request, response) => { |
| 1234 | 1233 | try { |
| 1235 | 1234 | const modelsUrl = new URL('https://fal.ai/api/models?categories=text-to-image'); |
| 1236 | 1235 | const result = await fetch(modelsUrl); |
| @@ -1260,7 +1259,7 @@ falai.post('/models', jsonParser, async (_request, response) => { | ||
| 1260 | 1259 | } |
| 1261 | 1260 | }); |
| 1262 | 1261 | |
| 1263 | 1262 | falai.post('/generate', jsonParser, async (request, response) => { |
| 1264 | 1263 | try { |
| 1265 | 1264 | const key = readSecret(request.user.directories, SECRET_KEYS.FALAI); |
| 1266 | 1265 | |
| @@ -1276,7 +1275,7 @@ falai.post('/generate', jsonParser, async (request, response) => { | ||
| 1276 | 1275 | seed: request.body.seed ?? null, |
| 1277 | 1276 | guidance_scale: request.body.guidance, |
| 1278 | 1277 | enable_safety_checker: false, // Disable general safety checks |
| 1279 | 1278 | safety_tolerance: 6, // Make Flux the least strict |
| 1280 | 1279 | }; |
| 1281 | 1280 | |
| 1282 | 1281 | console.debug('FAL.AI request:', requestBody); |
| @@ -8,7 +8,6 @@ import writeFileAtomic from 'write-file-atomic'; | ||
| 8 | 8 | const readFile = fs.promises.readFile; |
| 9 | 9 | const readdir = fs.promises.readdir; |
| 10 | 10 | |
| 11 | -import { jsonParser } from '../express-common.js'; | |
| 12 | 11 | import { getAllUserHandles, getUserDirectories } from '../users.js'; |
| 13 | 12 | |
| 14 | 13 | const STATS_FILE = 'stats.json'; |
| @@ -440,7 +439,7 @@ export const router = express.Router(); | ||
| 440 | 439 | /** |
| 441 | 440 | * Handle a POST request to get the stats object |
| 442 | 441 | */ |
| 443 | 442 | router.post('/get', jsonParser, function (request, response) { |
| 444 | 443 | const stats = STATS.get(request.user.profile.handle) || {}; |
| 445 | 444 | response.send(stats); |
| 446 | 445 | }); |
| @@ -448,7 +447,7 @@ router.post('/get', jsonParser, function (request, response) { | ||
| 448 | 447 | /** |
| 449 | 448 | * Triggers the recreation of statistics from chat files. |
| 450 | 449 | */ |
| 451 | 450 | router.post('/recreate', jsonParser, async function (request, response) { |
| 452 | 451 | try { |
| 453 | 452 | await recreateStats(request.user.profile.handle, request.user.directories.chats, request.user.directories.characters); |
| 454 | 453 | return response.sendStatus(200); |
| @@ -461,7 +460,7 @@ router.post('/recreate', jsonParser, async function (request, response) { | ||
| 461 | 460 | /** |
| 462 | 461 | * Handle a POST request to update the stats object |
| 463 | 462 | */ |
| 464 | 463 | router.post('/update', jsonParser, function (request, response) { |
| 465 | 464 | if (!request.body) return response.sendStatus(400); |
| 466 | 465 | setCharStats(request.user.profile.handle, request.body); |
| 467 | 466 | return response.sendStatus(200); |
| @@ -5,11 +5,9 @@ import express from 'express'; | ||
| 5 | 5 | import sanitize from 'sanitize-filename'; |
| 6 | 6 | import { sync as writeFileAtomicSync } from 'write-file-atomic'; |
| 7 | 7 | |
| 8 | -import { jsonParser } from '../express-common.js'; | |
| 9 | - | |
| 10 | 8 | export const router = express.Router(); |
| 11 | 9 | |
| 12 | 10 | router.post('/save', jsonParser, (request, response) => { |
| 13 | 11 | if (!request.body || !request.body.name) { |
| 14 | 12 | return response.sendStatus(400); |
| 15 | 13 | } |
| @@ -20,7 +18,7 @@ router.post('/save', jsonParser, (request, response) => { | ||
| 20 | 18 | return response.sendStatus(200); |
| 21 | 19 | }); |
| 22 | 20 | |
| 23 | 21 | router.post('/delete', jsonParser, function (request, response) { |
| 24 | 22 | if (!request.body || !request.body.name) { |
| 25 | 23 | return response.sendStatus(400); |
| 26 | 24 | } |
| @@ -10,7 +10,6 @@ import { sync as writeFileAtomicSync } from 'write-file-atomic'; | ||
| 10 | 10 | |
| 11 | 11 | import { getAllUserHandles, getUserDirectories } from '../users.js'; |
| 12 | 12 | import { getConfigValue } from '../util.js'; |
| 13 | -import { jsonParser } from '../express-common.js'; | |
| 14 | 13 | |
| 15 | 14 | const thumbnailsEnabled = !!getConfigValue('thumbnails.enabled', true, 'boolean'); |
| 16 | 15 | const quality = Math.min(100, Math.max(1, parseInt(getConfigValue('thumbnails.quality', 95, 'number')))); |
| @@ -176,7 +175,7 @@ export async function ensureThumbnailCache() { | ||
| 176 | 175 | export const router = express.Router(); |
| 177 | 176 | |
| 178 | 177 | // Important: This route must be mounted as '/thumbnail'. It is used in the client code and saved to chat files. |
| 179 | 178 | router.get('/', jsonParser, async function (request, response) { |
| 180 | 179 | try{ |
| 181 | 180 | if (typeof request.query.file !== 'string' || typeof request.query.type !== 'string') { |
| 182 | 181 | return response.sendStatus(400); |
| @@ -11,7 +11,6 @@ import tiktoken from 'tiktoken'; | ||
| 11 | 11 | |
| 12 | 12 | import { convertClaudePrompt } from '../prompt-converters.js'; |
| 13 | 13 | import { TEXTGEN_TYPES } from '../constants.js'; |
| 14 | -import { jsonParser } from '../express-common.js'; | |
| 15 | 14 | import { setAdditionalHeaders } from '../additional-headers.js'; |
| 16 | 15 | import { getConfigValue, isValidUrl } from '../util.js'; |
| 17 | 16 | |
| @@ -689,36 +688,36 @@ function createWebTokenizerDecodingHandler(tokenizer) { | ||
| 689 | 688 | |
| 690 | 689 | export const router = express.Router(); |
| 691 | 690 | |
| 692 | 691 | router.post('/llama/encode', jsonParser, createSentencepieceEncodingHandler(spp_llama)); |
| 693 | 692 | router.post('/nerdstash/encode', jsonParser, createSentencepieceEncodingHandler(spp_nerd)); |
| 694 | 693 | router.post('/nerdstash_v2/encode', jsonParser, createSentencepieceEncodingHandler(spp_nerd_v2)); |
| 695 | 694 | router.post('/mistral/encode', jsonParser, createSentencepieceEncodingHandler(spp_mistral)); |
| 696 | 695 | router.post('/yi/encode', jsonParser, createSentencepieceEncodingHandler(spp_yi)); |
| 697 | 696 | router.post('/gemma/encode', jsonParser, createSentencepieceEncodingHandler(spp_gemma)); |
| 698 | 697 | router.post('/jamba/encode', jsonParser, createSentencepieceEncodingHandler(spp_jamba)); |
| 699 | 698 | router.post('/gpt2/encode', jsonParser, createTiktokenEncodingHandler('gpt2')); |
| 700 | 699 | router.post('/claude/encode', jsonParser, createWebTokenizerEncodingHandler(claude_tokenizer)); |
| 701 | 700 | router.post('/llama3/encode', jsonParser, createWebTokenizerEncodingHandler(llama3_tokenizer)); |
| 702 | 701 | router.post('/qwen2/encode', jsonParser, createWebTokenizerEncodingHandler(qwen2Tokenizer)); |
| 703 | 702 | router.post('/command-r/encode', jsonParser, createWebTokenizerEncodingHandler(commandTokenizer)); |
| 704 | 703 | router.post('/nemo/encode', jsonParser, createWebTokenizerEncodingHandler(nemoTokenizer)); |
| 705 | 704 | router.post('/deepseek/encode', jsonParser, createWebTokenizerEncodingHandler(deepseekTokenizer)); |
| 706 | 705 | router.post('/llama/decode', jsonParser, createSentencepieceDecodingHandler(spp_llama)); |
| 707 | 706 | router.post('/nerdstash/decode', jsonParser, createSentencepieceDecodingHandler(spp_nerd)); |
| 708 | 707 | router.post('/nerdstash_v2/decode', jsonParser, createSentencepieceDecodingHandler(spp_nerd_v2)); |
| 709 | 708 | router.post('/mistral/decode', jsonParser, createSentencepieceDecodingHandler(spp_mistral)); |
| 710 | 709 | router.post('/yi/decode', jsonParser, createSentencepieceDecodingHandler(spp_yi)); |
| 711 | 710 | router.post('/gemma/decode', jsonParser, createSentencepieceDecodingHandler(spp_gemma)); |
| 712 | 711 | router.post('/jamba/decode', jsonParser, createSentencepieceDecodingHandler(spp_jamba)); |
| 713 | 712 | router.post('/gpt2/decode', jsonParser, createTiktokenDecodingHandler('gpt2')); |
| 714 | 713 | router.post('/claude/decode', jsonParser, createWebTokenizerDecodingHandler(claude_tokenizer)); |
| 715 | 714 | router.post('/llama3/decode', jsonParser, createWebTokenizerDecodingHandler(llama3_tokenizer)); |
| 716 | 715 | router.post('/qwen2/decode', jsonParser, createWebTokenizerDecodingHandler(qwen2Tokenizer)); |
| 717 | 716 | router.post('/command-r/decode', jsonParser, createWebTokenizerDecodingHandler(commandTokenizer)); |
| 718 | 717 | router.post('/nemo/decode', jsonParser, createWebTokenizerDecodingHandler(nemoTokenizer)); |
| 719 | 718 | router.post('/deepseek/decode', jsonParser, createWebTokenizerDecodingHandler(deepseekTokenizer)); |
| 720 | 719 | |
| 721 | 720 | router.post('/openai/encode', jsonParser, async function (req, res) { |
| 722 | 721 | try { |
| 723 | 722 | const queryModel = String(req.query.model || ''); |
| 724 | 723 | |
| @@ -786,7 +785,7 @@ router.post('/openai/encode', jsonParser, async function (req, res) { | ||
| 786 | 785 | } |
| 787 | 786 | }); |
| 788 | 787 | |
| 789 | 788 | router.post('/openai/decode', jsonParser, async function (req, res) { |
| 790 | 789 | try { |
| 791 | 790 | const queryModel = String(req.query.model || ''); |
| 792 | 791 | |
| @@ -854,7 +853,7 @@ router.post('/openai/decode', jsonParser, async function (req, res) { | ||
| 854 | 853 | } |
| 855 | 854 | }); |
| 856 | 855 | |
| 857 | 856 | router.post('/openai/count', jsonParser, async function (req, res) { |
| 858 | 857 | try { |
| 859 | 858 | if (!req.body) return res.sendStatus(400); |
| 860 | 859 | |
| @@ -968,7 +967,7 @@ router.post('/openai/count', jsonParser, async function (req, res) { | ||
| 968 | 967 | } |
| 969 | 968 | }); |
| 970 | 969 | |
| 971 | 970 | router.post('/remote/kobold/count', jsonParser, async function (request, response) { |
| 972 | 971 | if (!request.body) { |
| 973 | 972 | return response.sendStatus(400); |
| 974 | 973 | } |
| @@ -1002,7 +1001,7 @@ router.post('/remote/kobold/count', jsonParser, async function (request, respons | ||
| 1002 | 1001 | } |
| 1003 | 1002 | }); |
| 1004 | 1003 | |
| 1005 | 1004 | router.post('/remote/textgenerationwebui/encode', jsonParser, async function (request, response) { |
| 1006 | 1005 | if (!request.body) { |
| 1007 | 1006 | return response.sendStatus(400); |
| 1008 | 1007 | } |
| @@ -8,7 +8,6 @@ import urlJoin from 'url-join'; | ||
| 8 | 8 | |
| 9 | 9 | import { readSecret, SECRET_KEYS } from './secrets.js'; |
| 10 | 10 | import { getConfigValue, uuidv4 } from '../util.js'; |
| 11 | -import { jsonParser } from '../express-common.js'; | |
| 12 | 11 | |
| 13 | 12 | const DEEPLX_URL_DEFAULT = 'http://127.0.0.1:1188/translate'; |
| 14 | 13 | const ONERING_URL_DEFAULT = 'http://127.0.0.1:4990/translate'; |
| @@ -40,7 +39,7 @@ function decodeBuffer(buffer) { | ||
| 40 | 39 | } |
| 41 | 40 | } |
| 42 | 41 | |
| 43 | 42 | router.post('/libre', jsonParser, async (request, response) => { |
| 44 | 43 | try { |
| 45 | 44 | const key = readSecret(request.user.directories, SECRET_KEYS.LIBRE); |
| 46 | 45 | const url = readSecret(request.user.directories, SECRET_KEYS.LIBRE_URL); |
| @@ -100,7 +99,7 @@ router.post('/libre', jsonParser, async (request, response) => { | ||
| 100 | 99 | } |
| 101 | 100 | }); |
| 102 | 101 | |
| 103 | 102 | router.post('/google', jsonParser, async (request, response) => { |
| 104 | 103 | try { |
| 105 | 104 | const text = request.body.text; |
| 106 | 105 | const lang = request.body.lang; |
| @@ -133,7 +132,7 @@ router.post('/google', jsonParser, async (request, response) => { | ||
| 133 | 132 | } |
| 134 | 133 | }); |
| 135 | 134 | |
| 136 | 135 | router.post('/yandex', jsonParser, async (request, response) => { |
| 137 | 136 | try { |
| 138 | 137 | if (request.body.lang === 'pt-PT') { |
| 139 | 138 | request.body.lang = 'pt'; |
| @@ -189,7 +188,7 @@ router.post('/yandex', jsonParser, async (request, response) => { | ||
| 189 | 188 | } |
| 190 | 189 | }); |
| 191 | 190 | |
| 192 | 191 | router.post('/lingva', jsonParser, async (request, response) => { |
| 193 | 192 | try { |
| 194 | 193 | const secretUrl = readSecret(request.user.directories, SECRET_KEYS.LINGVA_URL); |
| 195 | 194 | const baseUrl = secretUrl || LINGVA_DEFAULT; |
| @@ -233,7 +232,7 @@ router.post('/lingva', jsonParser, async (request, response) => { | ||
| 233 | 232 | } |
| 234 | 233 | }); |
| 235 | 234 | |
| 236 | 235 | router.post('/deepl', jsonParser, async (request, response) => { |
| 237 | 236 | try { |
| 238 | 237 | const key = readSecret(request.user.directories, SECRET_KEYS.DEEPL); |
| 239 | 238 | |
| @@ -295,7 +294,7 @@ router.post('/deepl', jsonParser, async (request, response) => { | ||
| 295 | 294 | } |
| 296 | 295 | }); |
| 297 | 296 | |
| 298 | 297 | router.post('/onering', jsonParser, async (request, response) => { |
| 299 | 298 | try { |
| 300 | 299 | const secretUrl = readSecret(request.user.directories, SECRET_KEYS.ONERING_URL); |
| 301 | 300 | const url = secretUrl || ONERING_URL_DEFAULT; |
| @@ -352,7 +351,7 @@ router.post('/onering', jsonParser, async (request, response) => { | ||
| 352 | 351 | } |
| 353 | 352 | }); |
| 354 | 353 | |
| 355 | 354 | router.post('/deeplx', jsonParser, async (request, response) => { |
| 356 | 355 | try { |
| 357 | 356 | const secretUrl = readSecret(request.user.directories, SECRET_KEYS.DEEPLX_URL); |
| 358 | 357 | const url = secretUrl || DEEPLX_URL_DEFAULT; |
| @@ -408,7 +407,7 @@ router.post('/deeplx', jsonParser, async (request, response) => { | ||
| 408 | 407 | } |
| 409 | 408 | }); |
| 410 | 409 | |
| 411 | 410 | router.post('/bing', jsonParser, async (request, response) => { |
| 412 | 411 | try { |
| 413 | 412 | const text = request.body.text; |
| 414 | 413 | let lang = request.body.lang; |
| @@ -3,7 +3,6 @@ import { promises as fsPromises } from 'node:fs'; | ||
| 3 | 3 | import storage from 'node-persist'; |
| 4 | 4 | import express from 'express'; |
| 5 | 5 | import lodash from 'lodash'; |
| 6 | -import { jsonParser } from '../express-common.js'; | |
| 7 | 6 | import { checkForNewContent, CONTENT_TYPES } from './content-manager.js'; |
| 8 | 7 | import { |
| 9 | 8 | KEY_PREFIX, |
| @@ -20,7 +19,7 @@ import { DEFAULT_USER } from '../constants.js'; | ||
| 20 | 19 | |
| 21 | 20 | export const router = express.Router(); |
| 22 | 21 | |
| 23 | 22 | router.post('/get', requireAdminMiddleware, jsonParser, async (_request, response) => { |
| 24 | 23 | try { |
| 25 | 24 | /** @type {import('../users.js').User[]} */ |
| 26 | 25 | const users = await storage.values(x => x.key.startsWith(KEY_PREFIX)); |
| @@ -50,7 +49,7 @@ router.post('/get', requireAdminMiddleware, jsonParser, async (_request, respons | ||
| 50 | 49 | } |
| 51 | 50 | }); |
| 52 | 51 | |
| 53 | 52 | router.post('/disable', requireAdminMiddleware, jsonParser, async (request, response) => { |
| 54 | 53 | try { |
| 55 | 54 | if (!request.body.handle) { |
| 56 | 55 | console.warn('Disable user failed: Missing required fields'); |
| @@ -79,7 +78,7 @@ router.post('/disable', requireAdminMiddleware, jsonParser, async (request, resp | ||
| 79 | 78 | } |
| 80 | 79 | }); |
| 81 | 80 | |
| 82 | 81 | router.post('/enable', requireAdminMiddleware, jsonParser, async (request, response) => { |
| 83 | 82 | try { |
| 84 | 83 | if (!request.body.handle) { |
| 85 | 84 | console.warn('Enable user failed: Missing required fields'); |
| @@ -103,7 +102,7 @@ router.post('/enable', requireAdminMiddleware, jsonParser, async (request, respo | ||
| 103 | 102 | } |
| 104 | 103 | }); |
| 105 | 104 | |
| 106 | 105 | router.post('/promote', requireAdminMiddleware, jsonParser, async (request, response) => { |
| 107 | 106 | try { |
| 108 | 107 | if (!request.body.handle) { |
| 109 | 108 | console.warn('Promote user failed: Missing required fields'); |
| @@ -127,7 +126,7 @@ router.post('/promote', requireAdminMiddleware, jsonParser, async (request, resp | ||
| 127 | 126 | } |
| 128 | 127 | }); |
| 129 | 128 | |
| 130 | 129 | router.post('/demote', requireAdminMiddleware, jsonParser, async (request, response) => { |
| 131 | 130 | try { |
| 132 | 131 | if (!request.body.handle) { |
| 133 | 132 | console.warn('Demote user failed: Missing required fields'); |
| @@ -156,7 +155,7 @@ router.post('/demote', requireAdminMiddleware, jsonParser, async (request, respo | ||
| 156 | 155 | } |
| 157 | 156 | }); |
| 158 | 157 | |
| 159 | 158 | router.post('/create', requireAdminMiddleware, jsonParser, async (request, response) => { |
| 160 | 159 | try { |
| 161 | 160 | if (!request.body.handle || !request.body.name) { |
| 162 | 161 | console.warn('Create user failed: Missing required fields'); |
| @@ -203,7 +202,7 @@ router.post('/create', requireAdminMiddleware, jsonParser, async (request, respo | ||
| 203 | 202 | } |
| 204 | 203 | }); |
| 205 | 204 | |
| 206 | 205 | router.post('/delete', requireAdminMiddleware, jsonParser, async (request, response) => { |
| 207 | 206 | try { |
| 208 | 207 | if (!request.body.handle) { |
| 209 | 208 | console.warn('Delete user failed: Missing required fields'); |
| @@ -235,7 +234,7 @@ router.post('/delete', requireAdminMiddleware, jsonParser, async (request, respo | ||
| 235 | 234 | } |
| 236 | 235 | }); |
| 237 | 236 | |
| 238 | 237 | router.post('/slugify', requireAdminMiddleware, jsonParser, async (request, response) => { |
| 239 | 238 | try { |
| 240 | 239 | if (!request.body.text) { |
| 241 | 240 | console.warn('Slugify failed: Missing required fields'); |
| @@ -5,7 +5,6 @@ import crypto from 'node:crypto'; | ||
| 5 | 5 | import storage from 'node-persist'; |
| 6 | 6 | import express from 'express'; |
| 7 | 7 | |
| 8 | -import { jsonParser } from '../express-common.js'; | |
| 9 | 8 | import { getUserAvatar, toKey, getPasswordHash, getPasswordSalt, createBackupArchive, ensurePublicDirectoriesExist, toAvatarKey } from '../users.js'; |
| 10 | 9 | import { SETTINGS_FILE } from '../constants.js'; |
| 11 | 10 | import { checkForNewContent, CONTENT_TYPES } from './content-manager.js'; |
| @@ -55,7 +54,7 @@ router.get('/me', async (request, response) => { | ||
| 55 | 54 | } |
| 56 | 55 | }); |
| 57 | 56 | |
| 58 | 57 | router.post('/change-avatar', jsonParser, async (request, response) => { |
| 59 | 58 | try { |
| 60 | 59 | if (!request.body.handle) { |
| 61 | 60 | console.warn('Change avatar failed: Missing required fields'); |
| @@ -90,7 +89,7 @@ router.post('/change-avatar', jsonParser, async (request, response) => { | ||
| 90 | 89 | } |
| 91 | 90 | }); |
| 92 | 91 | |
| 93 | 92 | router.post('/change-password', jsonParser, async (request, response) => { |
| 94 | 93 | try { |
| 95 | 94 | if (!request.body.handle) { |
| 96 | 95 | console.warn('Change password failed: Missing required fields'); |
| @@ -137,7 +136,7 @@ router.post('/change-password', jsonParser, async (request, response) => { | ||
| 137 | 136 | } |
| 138 | 137 | }); |
| 139 | 138 | |
| 140 | 139 | router.post('/backup', jsonParser, async (request, response) => { |
| 141 | 140 | try { |
| 142 | 141 | const handle = request.body.handle; |
| 143 | 142 | |
| @@ -158,7 +157,7 @@ router.post('/backup', jsonParser, async (request, response) => { | ||
| 158 | 157 | } |
| 159 | 158 | }); |
| 160 | 159 | |
| 161 | 160 | router.post('/reset-settings', jsonParser, async (request, response) => { |
| 162 | 161 | try { |
| 163 | 162 | const password = request.body.password; |
| 164 | 163 | |
| @@ -178,7 +177,7 @@ router.post('/reset-settings', jsonParser, async (request, response) => { | ||
| 178 | 177 | } |
| 179 | 178 | }); |
| 180 | 179 | |
| 181 | 180 | router.post('/change-name', jsonParser, async (request, response) => { |
| 182 | 181 | try { |
| 183 | 182 | if (!request.body.name || !request.body.handle) { |
| 184 | 183 | console.warn('Change name failed: Missing required fields'); |
| @@ -208,7 +207,7 @@ router.post('/change-name', jsonParser, async (request, response) => { | ||
| 208 | 207 | } |
| 209 | 208 | }); |
| 210 | 209 | |
| 211 | 210 | router.post('/reset-step1', jsonParser, async (request, response) => { |
| 212 | 211 | try { |
| 213 | 212 | const resetCode = String(crypto.randomInt(1000, 9999)); |
| 214 | 213 | console.log(); |
| @@ -222,7 +221,7 @@ router.post('/reset-step1', jsonParser, async (request, response) => { | ||
| 222 | 221 | } |
| 223 | 222 | }); |
| 224 | 223 | |
| 225 | 224 | router.post('/reset-step2', jsonParser, async (request, response) => { |
| 226 | 225 | try { |
| 227 | 226 | if (!request.body.code) { |
| 228 | 227 | console.warn('Recover step 2 failed: Missing required fields'); |
| @@ -3,7 +3,7 @@ import crypto from 'node:crypto'; | ||
| 3 | 3 | import storage from 'node-persist'; |
| 4 | 4 | import express from 'express'; |
| 5 | 5 | import { RateLimiterMemory, RateLimiterRes } from 'rate-limiter-flexible'; |
| 6 | 6 | import { jsonParser, getIpFromRequest, getRealIpFromHeader } from '../express-common.js'; |
| 7 | 7 | import { color, Cache, getConfigValue } from '../util.js'; |
| 8 | 8 | import { KEY_PREFIX, getUserAvatar, toKey, getPasswordHash, getPasswordSalt } from '../users.js'; |
| 9 | 9 | |
| @@ -56,7 +56,7 @@ router.post('/list', async (_request, response) => { | ||
| 56 | 56 | } |
| 57 | 57 | }); |
| 58 | 58 | |
| 59 | 59 | router.post('/login', jsonParser, async (request, response) => { |
| 60 | 60 | try { |
| 61 | 61 | if (!request.body.handle) { |
| 62 | 62 | console.warn('Login failed: Missing required fields'); |
| @@ -104,7 +104,7 @@ router.post('/login', jsonParser, async (request, response) => { | ||
| 104 | 104 | } |
| 105 | 105 | }); |
| 106 | 106 | |
| 107 | 107 | router.post('/recover-step1', jsonParser, async (request, response) => { |
| 108 | 108 | try { |
| 109 | 109 | if (!request.body.handle) { |
| 110 | 110 | console.warn('Recover step 1 failed: Missing required fields'); |
| @@ -144,7 +144,7 @@ router.post('/recover-step1', jsonParser, async (request, response) => { | ||
| 144 | 144 | } |
| 145 | 145 | }); |
| 146 | 146 | |
| 147 | 147 | router.post('/recover-step2', jsonParser, async (request, response) => { |
| 148 | 148 | try { |
| 149 | 149 | if (!request.body.handle || !request.body.code) { |
| 150 | 150 | console.warn('Recover step 2 failed: Missing required fields'); |
| @@ -5,7 +5,6 @@ import vectra from 'vectra'; | ||
| 5 | 5 | import express from 'express'; |
| 6 | 6 | import sanitize from 'sanitize-filename'; |
| 7 | 7 | |
| 8 | -import { jsonParser } from '../express-common.js'; | |
| 9 | 8 | import { getConfigValue } from '../util.js'; |
| 10 | 9 | |
| 11 | 10 | import { getNomicAIBatchVector, getNomicAIVector } from '../vectors/nomicai-vectors.js'; |
| @@ -384,7 +383,7 @@ async function regenerateCorruptedIndexErrorHandler(req, res, error) { | ||
| 384 | 383 | |
| 385 | 384 | export const router = express.Router(); |
| 386 | 385 | |
| 387 | 386 | router.post('/query', jsonParser, async (req, res) => { |
| 388 | 387 | try { |
| 389 | 388 | if (!req.body.collectionId || !req.body.searchText) { |
| 390 | 389 | return res.sendStatus(400); |
| @@ -404,7 +403,7 @@ router.post('/query', jsonParser, async (req, res) => { | ||
| 404 | 403 | } |
| 405 | 404 | }); |
| 406 | 405 | |
| 407 | 406 | router.post('/query-multi', jsonParser, async (req, res) => { |
| 408 | 407 | try { |
| 409 | 408 | if (!Array.isArray(req.body.collectionIds) || !req.body.searchText) { |
| 410 | 409 | return res.sendStatus(400); |
| @@ -424,7 +423,7 @@ router.post('/query-multi', jsonParser, async (req, res) => { | ||
| 424 | 423 | } |
| 425 | 424 | }); |
| 426 | 425 | |
| 427 | 426 | router.post('/insert', jsonParser, async (req, res) => { |
| 428 | 427 | try { |
| 429 | 428 | if (!Array.isArray(req.body.items) || !req.body.collectionId) { |
| 430 | 429 | return res.sendStatus(400); |
| @@ -442,7 +441,7 @@ router.post('/insert', jsonParser, async (req, res) => { | ||
| 442 | 441 | } |
| 443 | 442 | }); |
| 444 | 443 | |
| 445 | 444 | router.post('/list', jsonParser, async (req, res) => { |
| 446 | 445 | try { |
| 447 | 446 | if (!req.body.collectionId) { |
| 448 | 447 | return res.sendStatus(400); |
| @@ -459,7 +458,7 @@ router.post('/list', jsonParser, async (req, res) => { | ||
| 459 | 458 | } |
| 460 | 459 | }); |
| 461 | 460 | |
| 462 | 461 | router.post('/delete', jsonParser, async (req, res) => { |
| 463 | 462 | try { |
| 464 | 463 | if (!Array.isArray(req.body.hashes) || !req.body.collectionId) { |
| 465 | 464 | return res.sendStatus(400); |
| @@ -477,7 +476,7 @@ router.post('/delete', jsonParser, async (req, res) => { | ||
| 477 | 476 | } |
| 478 | 477 | }); |
| 479 | 478 | |
| 480 | 479 | router.post('/purge-all', jsonParser, async (req, res) => { |
| 481 | 480 | try { |
| 482 | 481 | for (const source of SOURCES) { |
| 483 | 482 | const sourcePath = path.join(req.user.directories.vectors, sanitize(source)); |
| @@ -495,7 +494,7 @@ router.post('/purge-all', jsonParser, async (req, res) => { | ||
| 495 | 494 | } |
| 496 | 495 | }); |
| 497 | 496 | |
| 498 | 497 | router.post('/purge', jsonParser, async (req, res) => { |
| 499 | 498 | try { |
| 500 | 499 | if (!req.body.collectionId) { |
| 501 | 500 | return res.sendStatus(400); |
| @@ -5,8 +5,6 @@ import express from 'express'; | ||
| 5 | 5 | import sanitize from 'sanitize-filename'; |
| 6 | 6 | import { sync as writeFileAtomicSync } from 'write-file-atomic'; |
| 7 | 7 | |
| 8 | -import { jsonParser, urlencodedParser } from '../express-common.js'; | |
| 9 | - | |
| 10 | 8 | /** |
| 11 | 9 | * Reads a World Info file and returns its contents |
| 12 | 10 | * @param {import('../users.js').UserDirectoryList} directories User directories |
| @@ -36,7 +34,7 @@ export function readWorldInfoFile(directories, worldInfoName, allowDummy) { | ||
| 36 | 34 | |
| 37 | 35 | export const router = express.Router(); |
| 38 | 36 | |
| 39 | 37 | router.post('/get', jsonParser, (request, response) => { |
| 40 | 38 | if (!request.body?.name) { |
| 41 | 39 | return response.sendStatus(400); |
| 42 | 40 | } |
| @@ -46,7 +44,7 @@ router.post('/get', jsonParser, (request, response) => { | ||
| 46 | 44 | return response.send(file); |
| 47 | 45 | }); |
| 48 | 46 | |
| 49 | 47 | router.post('/delete', jsonParser, (request, response) => { |
| 50 | 48 | if (!request.body?.name) { |
| 51 | 49 | return response.sendStatus(400); |
| 52 | 50 | } |
| @@ -64,7 +62,7 @@ router.post('/delete', jsonParser, (request, response) => { | ||
| 64 | 62 | return response.sendStatus(200); |
| 65 | 63 | }); |
| 66 | 64 | |
| 67 | 65 | router.post('/import', urlencodedParser, (request, response) => { |
| 68 | 66 | if (!request.file) return response.sendStatus(400); |
| 69 | 67 | |
| 70 | 68 | const filename = `${path.parse(sanitize(request.file.originalname)).name}.json`; |
| @@ -99,7 +97,7 @@ router.post('/import', urlencodedParser, (request, response) => { | ||
| 99 | 97 | return response.send({ name: worldName }); |
| 100 | 98 | }); |
| 101 | 99 | |
| 102 | 100 | router.post('/edit', jsonParser, (request, response) => { |
| 103 | 101 | if (!request.body) { |
| 104 | 102 | return response.sendStatus(400); |
| 105 | 103 | } |
| @@ -1,9 +1,10 @@ | ||
| 1 | -import express from 'express'; | |
| 2 | 1 | import ipaddr from 'ipaddr.js'; |
| 3 | 2 | |
| 4 | -// Instantiate parser middleware here with application-level size limits | |
| 3 | +const noopMiddleware = (_req, _res, next) => next(); | |
| 5 | -export const jsonParser = express.json({ limit: '200mb' }); | |
| 4 | +/** @deprecated Do not use. A global middleware is provided at the application level. */ | |
| 6 | -export const urlencodedParser = express.urlencoded({ extended: true, limit: '200mb' }); | |
| 5 | +export const jsonParser = noopMiddleware; | |
| 6 | +/** @deprecated Do not use. A global middleware is provided at the application level. */ | |
| 7 | +export const urlencodedParser = noopMiddleware; | |
| 7 | 8 | |
| 8 | 9 | /** |
| 9 | 10 | * Gets the IP address of the client from the request object. |