Fix comments, update function interfaces
| @@ -18,7 +18,6 @@ import responseTime from 'response-time'; | ||
| 18 | 18 | import helmet from 'helmet'; |
| 19 | 19 | import bodyParser from 'body-parser'; |
| 20 | 20 | import open from 'open'; |
| 21 | -import fetch from 'node-fetch'; | |
| 22 | 21 | |
| 23 | 22 | // local library imports |
| 24 | 23 | import { CommandLineParser } from './src/command-line.js'; |
| @@ -36,7 +35,6 @@ import { | ||
| 36 | 35 | setUserDataMiddleware, |
| 37 | 36 | shouldRedirectToLogin, |
| 38 | 37 | tryAutoLogin, |
| 39 | - router as userDataRouter, | |
| 40 | 38 | cleanUploads, |
| 41 | 39 | getSessionCookieAge, |
| 42 | 40 | } from './src/users.js'; |
| @@ -64,8 +62,6 @@ import { ensureThumbnailCache } from './src/endpoints/thumbnails.js'; | ||
| 64 | 62 | |
| 65 | 63 | // Routers |
| 66 | 64 | import { router as usersPublicRouter } from './src/endpoints/users-public.js'; |
| 67 | -import { router as usersPrivateRouter } from './src/endpoints/users-private.js'; | |
| 68 | -import { router as usersAdminRouter } from './src/endpoints/users-admin.js'; | |
| 69 | 65 | import { init as statsInit, onExit as statsOnExit } from './src/endpoints/stats.js'; |
| 70 | 66 | import { checkForNewContent } from './src/endpoints/content-manager.js'; |
| 71 | 67 | import { init as settingsInit } from './src/endpoints/settings.js'; |
| @@ -255,17 +251,10 @@ app.get('/api/ping', (request, response) => { | ||
| 255 | 251 | }); |
| 256 | 252 | |
| 257 | 253 | // File uploads |
| 258 | 254 | const uploadsPath = path.join(globalThiscliArgs.DATA_ROOTdataRoot, UPLOADS_DIRECTORY); |
| 259 | 255 | app.use(multer({ dest: uploadsPath, limits: { fieldSize: 10 * 1024 * 1024 } }).single('avatar')); |
| 260 | 256 | app.use(multerMonkeyPatch); |
| 261 | 257 | |
| 262 | -// User data mount | |
| 263 | -app.use('/', userDataRouter); | |
| 264 | -// Private endpoints | |
| 265 | -app.use('/api/users', usersPrivateRouter); | |
| 266 | -// Admin endpoints | |
| 267 | -app.use('/api/users', usersAdminRouter); | |
| 268 | - | |
| 269 | 258 | app.get('/version', async function (_, response) { |
| 270 | 259 | const data = await getVersion(); |
| 271 | 260 | response.send(data); |
| @@ -335,8 +324,8 @@ async function preSetupTasks() { | ||
| 335 | 324 | * @param {import('./src/server-startup.js').ServerStartupResult} result The result of the server startup |
| 336 | 325 | * @returns {Promise<void>} |
| 337 | 326 | */ |
| 338 | 327 | async function postSetupTasks({ v6Failed, v4Failed, useIPv6, useIPv4 }result) { |
| 339 | 328 | const autorunHostname = await cliArgs.getAutorunHostname(useIPv6, useIPv4result); |
| 340 | 329 | const autorunUrl = cliArgs.getAutorunUrl(autorunHostname); |
| 341 | 330 | console.log('Launching...'); |
| 342 | 331 | |
| @@ -348,13 +337,13 @@ async function postSetupTasks({ v6Failed, v4Failed, useIPv6, useIPv4 }) { | ||
| 348 | 337 | |
| 349 | 338 | let logListen = 'SillyTavern is listening on'; |
| 350 | 339 | |
| 351 | 340 | if (result.useIPv6 && !result.v6Failed) { |
| 352 | 341 | logListen += color.green( |
| 353 | 342 | ' IPv6: ' + cliArgs.getIPv6ListenUrl().host, |
| 354 | 343 | ); |
| 355 | 344 | } |
| 356 | 345 | |
| 357 | 346 | if (result.useIPv4 && !result.v4Failed) { |
| 358 | 347 | logListen += color.green( |
| 359 | 348 | ' IPv4: ' + cliArgs.getIPv4ListenUrl().host, |
| 360 | 349 | ); |
| @@ -4,33 +4,33 @@ import ipRegex from 'ip-regex'; | ||
| 4 | 4 | import { canResolve, color, getConfigValue, stringToBool } from './util.js'; |
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | 7 | * @typedef {object} CommandLineArguments Parsed command line arguments |
| 8 | 8 | * @property {string} dataRoot Data root directory |
| 9 | 9 | * @property {number} port Port number |
| 10 | 10 | * @property {boolean} listen If SillyTavern is listening on all network interfaces |
| 11 | 11 | * @property {string} listenAddressIPv6 IPv6 address to listen to |
| 12 | 12 | * @property {string} listenAddressIPv4 IPv4 address to listen to |
| 13 | 13 | * @property {boolean|string} enableIPv4 If enable IPv4 protocol ("auto" is also allowed) |
| 14 | 14 | * @property {boolean|string} enableIPv6 If enable IPv6 protocol ("auto" is also allowed) |
| 15 | 15 | * @property {boolean} dnsPreferIPv6 If prefer IPv6 for DNS |
| 16 | 16 | * @property {boolean} autorun If automatically launch SillyTavern in the browser |
| 17 | 17 | * @property {string} autorunHostname Autorun hostname |
| 18 | 18 | * @property {number} autorunPortOverride Autorun port override (-1 is use server port) |
| 19 | 19 | * @property {boolean} enableCorsProxy If enable CORS proxy |
| 20 | 20 | * @property {boolean} disableCsrf If disable CSRF protection |
| 21 | 21 | * @property {boolean} ssl If enable SSL |
| 22 | 22 | * @property {string} certPath Path to certificate |
| 23 | 23 | * @property {string} keyPath Path to private key |
| 24 | 24 | * @property {boolean} whitelistMode If enable whitelist mode |
| 25 | 25 | * @property {boolean} avoidLocalhost If avoid using 'localhost' for autorun in auto mode |
| 26 | 26 | * @property {boolean} basicAuthMode If enable basic authentication |
| 27 | 27 | * @property {boolean} requestProxyEnabled If enable outgoing request proxy |
| 28 | 28 | * @property {string} requestProxyUrl Request proxy URL |
| 29 | 29 | * @property {string[]} requestProxyBypass Request proxy bypass list |
| 30 | 30 | * @property {function(): URL} getIPv4ListenUrl Get IPv4 listen URL |
| 31 | 31 | * @property {function(): URL} getIPv6ListenUrl Get IPv6 listen URL |
| 32 | 32 | * @property {function(boolean, booleanimport('./server-startup.js').ServerStartupResult): Promise<string>} getAutorunHostname Get autorun hostname |
| 33 | 33 | * @property {function(string): URL} getAutorunUrl Get autorun URL |
| 34 | 34 | */ |
| 35 | 35 | |
| 36 | 36 | /** |
| @@ -220,7 +220,7 @@ export class CommandLineParser { | ||
| 220 | 220 | (':' + this.port), |
| 221 | 221 | ); |
| 222 | 222 | }, |
| 223 | 223 | getAutorunHostname: async function ({ useIPv6, useIPv4 }) { |
| 224 | 224 | if (this.autorunHostname === 'auto') { |
| 225 | 225 | let localhostResolve = await canResolve('localhost', useIPv6, useIPv4); |
| 226 | 226 | |
| @@ -4,6 +4,9 @@ import fs from 'node:fs'; | ||
| 4 | 4 | import { color, urlHostnameToIPv6, getHasIP } from './util.js'; |
| 5 | 5 | |
| 6 | 6 | // Express routers |
| 7 | +import { router as userDataRouter } from './users.js'; | |
| 8 | +import { router as usersPrivateRouter } from './endpoints/users-private.js'; | |
| 9 | +import { router as usersAdminRouter } from './endpoints/users-admin.js'; | |
| 7 | 10 | import { router as movingUIRouter } from './endpoints/moving-ui.js'; |
| 8 | 11 | import { router as imagesRouter } from './endpoints/images.js'; |
| 9 | 12 | import { router as quickRepliesRouter } from './endpoints/quick-replies.js'; |
| @@ -128,6 +131,9 @@ export function redirectDeprecatedEndpoints(app) { | ||
| 128 | 131 | * @param {import('express').Express} app The Express app to use |
| 129 | 132 | */ |
| 130 | 133 | export function setupPrivateEndpoints(app) { |
| 134 | + app.use('/', userDataRouter); | |
| 135 | + app.use('/api/users', usersPrivateRouter); | |
| 136 | + app.use('/api/users', usersAdminRouter); | |
| 131 | 137 | app.use('/api/moving-ui', movingUIRouter); |
| 132 | 138 | app.use('/api/images', imagesRouter); |
| 133 | 139 | app.use('/api/quick-replies', quickRepliesRouter); |
| @@ -274,13 +280,10 @@ export class ServerStartup { | ||
| 274 | 280 | |
| 275 | 281 | /** |
| 276 | 282 | * Handles the case where the server failed to start on one or both protocols. |
| 277 | 283 | * @param {booleanServerStartupResult} v6Failed If theresult serverThe failedresults toof startthe onserver IPv6startup |
| 278 | - * @param {boolean} v4Failed If the server failed to start on IPv4 | |
| 279 | - * @param {boolean} useIPv6 If use IPv6 | |
| 280 | - * @param {boolean} useIPv4 If use IPv4 | |
| 281 | 284 | * @returns {void} |
| 282 | 285 | */ |
| 283 | 286 | #handleServerListenFail({ v6Failed, v4Failed, useIPv6, useIPv4 }) { |
| 284 | 287 | if (v6Failed && !useIPv4) { |
| 285 | 288 | console.error(color.red('fatal error: Failed to start server on IPv6 and IPv4 disabled')); |
| 286 | 289 | process.exit(1); |
| @@ -353,7 +356,8 @@ export class ServerStartup { | ||
| 353 | 356 | } |
| 354 | 357 | |
| 355 | 358 | const [v6Failed, v4Failed] = await this.#startHTTPorHTTPS(useIPv6, useIPv4); |
| 356 | 359 | this.#handleServerListenFail(const result = { v6Failed, v4Failed, useIPv6, useIPv4) }; |
| 357 | - return { v6Failed, v4Failed, useIPv6, useIPv4 }; | |
| 360 | + this.#handleServerListenFail(result); | |
| 361 | + return result; | |
| 358 | 362 | } |
| 359 | 363 | } |