A TypeScript/Node.js service that schedules and executes waifu2x-ncnn-vulkan image upscaling jobs with PostgreSQL-backed caching, filesystem storage, configurable concurrency, web page window, and a simple test client.
Mainly used for custom processImage in venera.
- Express 5 API exposing
/upscaleand/downloadendpoints with rate limiting, auth hooks, and structured log output. - Task orchestration powered by a PostgreSQL table (
waifu2x_tasks), a file cache, and a dynamicp-queuescheduler honoring FIFO/LIFO strategies. - Cache deduplication that reuses completed results and in-flight jobs using deterministic cache keys.
- Runtime configuration hot-reloaded from
config.json, covering waifu2x parameters, scheduler tuning, logging, and filesystem paths. - Real-time log page served at
/log, including optional token auth, live streaming output, and client-side persistence for gated access. - Visual Upscaling Studio hosted at
/studio, providing drag-and-drop uploads, parameter tuning (scale/noise/model/format/tile/gpu/threads, TTA), queue status, and auto-download flows. - Test utilities for exercising the API (
test/processImage.js,test/test_database.js) and resetting the database (test/reset_database.js).
- Node.js 18+
- pnpm 8+
- PostgreSQL 14+ running and reachable via the configured
connectionString - waifu2x-ncnn-vulkan binary (or compatible) accessible at the path defined in
config.json
- Install dependencies
pnpm install
- Configure the service
- Copy
config.example.jsontoconfig.json. - Adjust:
apihost/port and optionalmaxInputSizeMB.postgres.connectionString(andsslif needed).waifu2xexecutable path and default upscale parameters.schedulersettings (concurrency,queueStrategy,maxQueueSize,taskTimeoutMs).cache.ttlSeconds, filesystem paths.
- Copy
- Prepare PostgreSQL
- Ensure the target database exists and the
connectionStringuser has privileges. - Initialize/reset the schema with (auto-initialize on startup):
node test/reset_database.js
- Ensure the target database exists and the
- Build dist
pnpm build
- Run the service
With pm2 (recommended):
Or directly:
pnpm start
node . - Interact with the API
- POST binary data to
http://<host>:<port>/api/upscalewith required query params (sourceKey,cid, etc.). - Poll
.../download/<taskId>until the result is ready (legacy.../download?taskId=...remains supported). - Use
test/processImage.jsas a reference client for venera.
- POST binary data to
The custom logger (log4js + chalk) emits color-coded, bracketed tags to differentiate subsystems. Log level hot-reloads when config.json changes.
- Visit
http://<host>:<port>/logto watch structured logs live; append?token=<config.api.logToken>(and set the token inconfig.json) to gate access. The page remembers your token inlocalStoragefor future reloads. - Five consecutive invalid tokens from the same IP will push that IP into
config.api.blackIPs, so share URLs carefully.
- Open
http://<host>:<port>/studioto access the drag-and-drop interface. It supports file validation, parameter tweaking (scale/noise/model/format/tile/gpu/threads), TTA toggles, queue status visualization, and automatic polling with download + copy-link actions. - Just for fun. It is quite cool.
| Command | Description |
|---|---|
pnpm start |
Start the API under PM2 using pm2.json |
pnpm logs |
Tail PM2 logs for waifu2x-api with raw output |
pnpm stop |
Stop the waifu2x-api process managed by PM2 |
pnpm restart |
Restart the PM2 process to pick up new builds |
pnpm build |
Compile TypeScript sources via tsc |
pnpm build:css -- resources/<dir> |
Build Tailwind assets for resources/log or resources/studio (<dir> = target folder) |
pnpm re |
Pull latest git changes, rebuild, and restart PM2 |
pnpm run |
Execute the API directly with node . |
pnpm dev |
Watch src changes via nodemon (tsc && node .) |
test/processImage.jsdemonstrates how to call the API in Venera.test/test_database.jsconfirms DB connectivity and prints query timing.test/reset_database.jssafely rebuilds the schema.test/test_waifu2x.jstest script for waifu2x upscaling functionality.

