diff --git a/default/config.yaml b/default/config.yaml index 16248ef83..f4bacf9ff 100644 --- a/default/config.yaml +++ b/default/config.yaml @@ -1,8 +1,6 @@ # -- DATA CONFIGURATION -- # Root directory for user data storage dataRoot: ./data -# The maximum amount of memory that parsed character cards can use in MB -cardsCacheCapacity: 100 # -- SERVER CONFIGURATION -- # Listen for incoming connections listen: false @@ -135,6 +133,14 @@ thumbnails: # Maximum thumbnail dimensions per type [width, height] dimensions: { 'bg': [160, 90], 'avatar': [96, 144] } +# PERFORMANCE-RELATED CONFIGURATION +performance: + # Enables lazy loading of character cards. Improves performances with large card libraries. + # May have compatibility issues with some extensions. + lazyLoadCharacters: false + # The maximum amount of memory that parsed character cards can use. Set to 0 to disable memory caching. + memoryCacheCapacity: '100mb' + # Allow secret keys exposure via API allowKeysExposure: false # Skip new default content checks diff --git a/index.d.ts b/index.d.ts index 83eb8f9b1..b566dc355 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,8 +1,36 @@ -import { UserDirectoryList, User } from "./src/users"; -import { CommandLineArguments } from "./src/command-line"; -import { CsrfSyncedToken } from "csrf-sync"; +import { EventEmitter } from 'node:events'; +import { CsrfSyncedToken } from 'csrf-sync'; +import { UserDirectoryList, User } from './src/users.js'; +import { CommandLineArguments } from './src/command-line.js'; +import { EVENT_NAMES } from './src/server-events.js'; + +/** + * Event payload for SERVER_STARTED event. + */ +export interface ServerStartedEvent { + /** + * The URL the server is listening on. + */ + url: URL; +} + +/** + * Map of all server events to their payload types. + */ +export interface ServerEventMap { + [EVENT_NAMES.SERVER_STARTED]: [ServerStartedEvent]; +} declare global { + declare namespace NodeJS { + export interface Process { + /** + * A global instance of the server events emitter. + */ + serverEvents: EventEmitter; + } + } + declare namespace CookieSessionInterfaces { export interface CookieSessionObject { /** diff --git a/package-lock.json b/package-lock.json index 49994110d..0e97d11c7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,7 @@ "bing-translate-api": "^4.0.2", "body-parser": "^1.20.2", "bowser": "^2.11.0", + "bytes": "^3.1.2", "chalk": "^5.4.1", "command-exists": "^1.2.9", "compression": "^1.8.0", @@ -83,6 +84,7 @@ }, "devDependencies": { "@types/archiver": "^6.0.3", + "@types/bytes": "^3.1.5", "@types/command-exists": "^1.2.3", "@types/compression": "^1.7.5", "@types/cookie-parser": "^1.4.8", @@ -1105,6 +1107,13 @@ "@types/node": "*" } }, + "node_modules/@types/bytes": { + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/@types/bytes/-/bytes-3.1.5.tgz", + "integrity": "sha512-VgZkrJckypj85YxEsEavcMmmSOIzkUHqWmM4CCyia5dc54YwsXzJ5uT4fYxBQNEXx+oF1krlhgCbvfubXqZYsQ==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/cacheable-request": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/@types/cacheable-request/-/cacheable-request-6.0.3.tgz", @@ -3399,6 +3408,9 @@ "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", "license": "MIT", + "dependencies": { + "get-intrinsic": "^1.2.4" + }, "engines": { "node": ">= 0.4" } diff --git a/package.json b/package.json index 5ba2f8cc7..2a9009aae 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "bing-translate-api": "^4.0.2", "body-parser": "^1.20.2", "bowser": "^2.11.0", + "bytes": "^3.1.2", "chalk": "^5.4.1", "command-exists": "^1.2.9", "compression": "^1.8.0", @@ -92,7 +93,8 @@ "version": "1.12.12", "scripts": { "start": "node server.js", - "debug": "node server.js --inspect", + "debug": "node --inspect server.js", + "electron": "electron ./src/electron", "start:deno": "deno run --allow-run --allow-net --allow-read --allow-write --allow-sys --allow-env server.js", "start:bun": "bun server.js", "start:no-csrf": "node server.js --disableCsrf", @@ -112,6 +114,7 @@ "main": "server.js", "devDependencies": { "@types/archiver": "^6.0.3", + "@types/bytes": "^3.1.5", "@types/command-exists": "^1.2.3", "@types/compression": "^1.7.5", "@types/cookie-parser": "^1.4.8", diff --git a/post-install.js b/post-install.js index 1989b61aa..0048d9c6f 100644 --- a/post-install.js +++ b/post-install.js @@ -96,6 +96,11 @@ const keyMigrationMap = [ newKey: 'logging.minLogLevel', migrate: (value) => value, }, + { + oldKey: 'cardsCacheCapacity', + newKey: 'performance.memoryCacheCapacity', + migrate: (value) => `${value}mb`, + }, // uncomment one release after 1.12.13 /* { diff --git a/public/index.html b/public/index.html index aab2a0c11..ea4305051 100644 --- a/public/index.html +++ b/public/index.html @@ -1951,7 +1951,18 @@ -
+
+ +
+ + Use search capabilities provided by the backend. + +
+
+