diff --git a/.env.production.example b/.env.production.example new file mode 100644 index 0000000..73055a4 --- /dev/null +++ b/.env.production.example @@ -0,0 +1,32 @@ +# Copy to .env.production on the server and fill in. Never commit the real one. + +# The database password. Anything long and random. +POSTGRES_PASSWORD= + +# The two hostnames: the web app, and the NestJS API the browser talks to. +# Both get their own certificate from Let's Encrypt at ACME_EMAIL. +APP_HOST=content.yourcompany.com +API_HOST=api.content.yourcompany.com +ACME_EMAIL=you@yourcompany.com + +# The session cookie has to be readable on BOTH hosts: the API sets it, the +# web app's proxy checks for it. A shared parent domain does that. Leave +# COOKIE_SAMESITE at lax while the two hosts share a site; set it to none +# only if they do not (then Secure is forced, and the domain must be set). +COOKIE_DOMAIN=.content.yourcompany.com +COOKIE_SAMESITE=lax + +# Encrypts the API keys stored in the settings table. +# +# MOVE THE EXISTING VALUE from your local .env. A different secret does not +# fail loudly — it makes every key already saved unreadable, which reads as +# "the key vanished". +CONTENTOS_SECRET= + +# How the model is reached on a server. +# +# Your laptop runs the `claude` CLI and bills your subscription. A server has +# no CLI and no login, so it needs a key; the app falls back to the API path +# when the command is missing. Set the brain to the matching model in +# Settings → Generation after the first sign-in. +ANTHROPIC_API_KEY= diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..ce345f4 --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,29 @@ +# Typecheck, lint, tests, and a production build — the same four things +# `npm run check` and `npm run build:check` do on a laptop. +# +# No database and no model: nothing here talks to Postgres or spends a credit. +# The tests are the pure ones in tests/, and the build only has to compile. +name: check + +on: + push: + branches: ["**"] + pull_request: + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 24 + cache: npm + - run: npm ci + - run: npm ci --prefix api + - run: npm run check + # Into .next-check, so it can never be confused with a dev server's + # output — see next.config.ts. + - run: npm run build:check + # The API compiles on its own; the image is what a server runs. + - run: npm run build --prefix api diff --git a/.gitignore b/.gitignore index 5ce0008..2f0ba7c 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,9 @@ yarn-error.log* # env files (can opt-in for committing if needed) .env* +# …except the template a fresh clone copies from — DEPLOYING.md tells you to +# `cp` it, which needs it to be in the repo. +!.env.production.example # vercel .vercel @@ -54,3 +57,7 @@ next-env.d.ts # the real production secrets .env.production + +# the NestJS API has its own install and build output +api/node_modules +api/dist diff --git a/Dockerfile b/Dockerfile index 6bf366c..c29e1cb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,6 +12,9 @@ FROM node:24-bookworm-slim AS build WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . +# Read by the browser bundle, so it has to be known when the bundle is built. +ARG NEXT_PUBLIC_API_URL +ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL # `output: "standalone"` in next.config.ts is what makes .next/standalone a # server that can run without node_modules beside it. RUN npm run build @@ -21,20 +24,11 @@ WORKDIR /app ENV NODE_ENV=production ENV PORT=3333 -# The tools the Integrations page probes for. Without them the app still runs; -# source-video features report the binary as missing, which is the truth. -RUN apt-get update \ - && apt-get install -y --no-install-recommends ffmpeg python3 ca-certificates curl \ - && curl -fsSL https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp \ - && chmod a+rx /usr/local/bin/yt-dlp \ - && rm -rf /var/lib/apt/lists/* +# No ffmpeg or yt-dlp here any more: the ingest runs in the API's image. COPY --from=build /app/public ./public COPY --from=build /app/.next/standalone ./ COPY --from=build /app/.next/static ./.next/static -# Migrations run from the image on deploy, before the server takes traffic. -COPY --from=build /app/scripts ./scripts -COPY --from=build /app/lib/server/db ./lib/server/db EXPOSE 3333 CMD ["node", "server.js"] diff --git a/README.md b/README.md index f452431..6bcabbe 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,9 @@ production dashboard where **topics** feed **packs**, packs run to produce ```bash npm run db:up # Postgres in Docker, on 5437 -./start.sh # dev server on http://localhost:3333 -./start.sh prod # production build, then serve it on 3333 -PORT=4000 ./start.sh # any other port +./start.sh # the NestJS API on :4000 and the Next dev server on :3333 +./start.sh prod # production builds of both, then serve both +PORT=3400 ./start.sh # any other web port (API_PORT for the API's) ``` `./start.sh` brings the database up itself and says so if it cannot — every @@ -29,7 +29,10 @@ which default to port 3000. ## Stack -Next.js 16 (App Router, Turbopack) · React 19 · TypeScript. No CSS framework: +**Frontend:** Next.js 16 (App Router, Turbopack) · React 19 · TypeScript. +**Backend:** NestJS 12 in `api/`, its own process on port 4000, sharing +`lib/server` (the repos, the run driver, the ingest) with the root. The +browser calls it directly at `NEXT_PUBLIC_API_URL`; there is no `app/api`. No CSS framework: the design is expressed in inline styles, matching the source canvas one declaration at a time, with shared fragments in [lib/theme.ts](lib/theme.ts). Fonts are self-hosted through `next/font` (Inter, Inter Tight, JetBrains Mono, @@ -45,11 +48,15 @@ and Noto Sans Bengali for the Bangla script screens). | `/content/[topic]` | One document | | `/packs` | Pack library — the shipped pack and anything written here | | `/pack/[slug]` | One pack: its real sections, its rules, what it asks for | -| `/builder` | Writing a pack — saves to the database | +| `/builder` | Writing a new template — saving moves it to its own URL | +| `/builder/[slug]` | Editing that template | | `/runs/[id]` | A run as it happens, section by section | | `/login`, `/signup` | Sign in; claim the console (open only while it has no owner) | | `/integrations` | What this machine can actually reach, probed live | -| `/tools`, `/settings` | Tools; preferences, keys and the account | +| `/tools` | This workspace's bench, grouped by category | +| `/tools/manage` | Every tool: category, on/off, which workspaces it stands in | +| `/tools/[tool]` | One tool — Content Research, or the video researcher | +| `/settings` | Preferences, keys, team and the account | Three overlays render above any route: the **Run Pack** sheet, the **Add Section** sheet, and the **command palette** (`⌘K` / `Ctrl+K`, `Esc` to close). @@ -66,14 +73,20 @@ components/ views/ one component per screen overlays/ run-setup, add-section, command palette ui/ Hov (hover/press styles), Popover, Icons + tools/ the interactive pieces of a tool's screen (FramePicker) lib/ data.ts what is left of the design's strings and numbers store.tsx client state, hydrated from the API and written back + use-*.ts a screen's data logic as a hook (content list, run document) + slug.ts the one rule for turning a name into part of a URL packs-client.ts the pack API, and the brief <-> runtime translation + packs-transfer.ts a template as a file: export, import, validation runs-client.ts the run API + tools-client.ts the tool bench, uploads, and the researcher theme.ts fonts, colors, repeated style fragments config.ts advancedNav / runSpeed, the canvas's two props server/ everything that touches the database (see below) +tests/ vitest, pure functions only — `npm run check` design/ the imported source canvas, for reference ``` @@ -86,7 +99,10 @@ matters lives in React state any more. ``` docker-compose.yml Postgres 17 on 5437, one named volume -middleware.ts the lock on the front door +proxy.ts the front door: pages need a session cookie +api/src/main.ts the NestJS service: CORS, cookies, migrate + seed +api/src/common/ SessionGuard (global, closed by default), errors +api/src// one controller per feature, over lib/server lib/server/db/schema.ts the schema, as an ordered list of migrations lib/server/db/client.ts the pool, `q` / `one` / `tx`, and `ready()` lib/server/auth.ts scrypt passwords, session rows, `requireUser` @@ -94,12 +110,11 @@ lib/server/tools.ts what is installed, by running it lib/server/brains.ts the four models, each over a CLI or an API lib/server/repos/ rows in, objects out — workspaces, series, packs, runs, sources, settings -lib/server/services/ the rules that are not the database's job, - including the yt-dlp / ffmpeg / whisper ingest +lib/server/services/ the rules that are not the database's job: + runs, the yt-dlp / ffmpeg / whisper ingest, the + researcher that reads frames lib/packs/enbn-website.ts the shipped pack: rules, 12 sections, instructions lib/server/prompt.ts system = voice + rules, user = source + inputs + deps -app/api/ auth, settings, integrations, sources, workspaces, - series, topics, packs, runs ``` ### Signing in diff --git a/api/Dockerfile b/api/Dockerfile new file mode 100644 index 0000000..5577c39 --- /dev/null +++ b/api/Dockerfile @@ -0,0 +1,48 @@ +# The API, as a server runs it. +# +# Built from the REPO ROOT as context (`docker build -f api/Dockerfile .`), +# because the service shares lib/server with the web app: the repos, the run +# driver, the ingest. The image carries only what a request actually reaches — +# the compiled TypeScript and the binaries the ingest shells out to. +FROM node:24-bookworm-slim AS deps +WORKDIR /app/api +COPY api/package.json api/package-lock.json* ./ +RUN npm ci + +FROM node:24-bookworm-slim AS build +WORKDIR /app +COPY --from=deps /app/api/node_modules ./api/node_modules +# The shared code, and the root packages it imports (pg, the Anthropic SDK). +COPY package.json package-lock.json* ./ +RUN npm ci --omit=dev +COPY lib ./lib +COPY api ./api +RUN cd api && npm run build + +FROM node:24-bookworm-slim AS runtime +WORKDIR /app +ENV NODE_ENV=production +ENV PORT=4000 +# `@/lib/...` inside the compiled output points at dist, not at the sources. +ENV TS_NODE_BASEURL=./dist +# Downloads and frames live here; mount a volume on it. +ENV CONTENTOS_DATA_DIR=/app/.data + +# The tools the ingest runs. Without them the API still starts; source-video +# features report the binary as missing, which is the truth. +RUN apt-get update \ + && apt-get install -y --no-install-recommends ffmpeg python3 ca-certificates curl \ + && curl -fsSL https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp \ + && chmod a+rx /usr/local/bin/yt-dlp \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=build /app/node_modules ./node_modules +COPY --from=build /app/api/node_modules ./api/node_modules +COPY --from=build /app/api/dist ./api/dist +COPY --from=build /app/api/package.json /app/api/tsconfig.json ./api/ + +WORKDIR /app/api +EXPOSE 4000 +# tsconfig-paths resolves the `@/` imports inside the compiled output, the +# same way ts-node does in development. +CMD ["node", "-r", "tsconfig-paths/register", "dist/api/src/main.js"] diff --git a/api/nest-cli.json b/api/nest-cli.json new file mode 100644 index 0000000..2566481 --- /dev/null +++ b/api/nest-cli.json @@ -0,0 +1,5 @@ +{ + "$schema": "https://json.schemastore.org/nest-cli", + "collection": "@nestjs/schematics", + "sourceRoot": "src" +} diff --git a/api/package-lock.json b/api/package-lock.json new file mode 100644 index 0000000..54eb391 --- /dev/null +++ b/api/package-lock.json @@ -0,0 +1,1868 @@ +{ + "name": "contentos-api", + "version": "0.1.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "contentos-api", + "version": "0.1.0", + "dependencies": { + "@nestjs/common": "^12.0.1", + "@nestjs/core": "^12.0.1", + "@nestjs/platform-express": "^12.0.1", + "busboy": "^1.6.0", + "cookie-parser": "^1.4.7", + "reflect-metadata": "^0.2.2", + "rxjs": "^7.8.2", + "tsconfig-paths": "^4.2.0" + }, + "devDependencies": { + "@types/busboy": "^1.5.4", + "@types/cookie-parser": "^1.4.9", + "@types/express": "^5.0.3", + "@types/node": "^24.13.3", + "cross-env": "^7.0.3", + "ts-node": "^10.9.2", + "typescript": "^5" + } + }, + "node_modules/@borewit/text-codec": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/@borewit/text-codec/-/text-codec-0.2.2.tgz", + "integrity": "sha512-DDaRehssg1aNrH4+2hnj1B7vnUGEjU6OIlyRdkMd0aUdIUvKXrJfXsy8LVtXAy7DRvYVluWbMspsRhz2lcW0mQ==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Borewit" + } + }, + "node_modules/@cspotcode/source-map-support": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", + "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/trace-mapping": "0.3.9" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz", + "integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.6.0.tgz", + "integrity": "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw==", + "dev": true, + "license": "MIT" + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", + "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, + "node_modules/@lukeed/csprng": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@lukeed/csprng/-/csprng-1.1.0.tgz", + "integrity": "sha512-Z7C/xXCiGWsg0KuKsHTKJxbWhpI3Vs5GwLfOean7MGyVFGqdRgBbAjOCh6u4bbjPc/8MJ2pZmK/0DLdCbivLDA==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/@nestjs/common": { + "version": "12.0.1", + "resolved": "https://registry.npmjs.org/@nestjs/common/-/common-12.0.1.tgz", + "integrity": "sha512-v0zTaRCTV2K2xSnb3GnJoQKtaR6VxouJtm+P2gpr5w61dlXeWpXl1WVknCSzUqx2QwTV10tBkHETxvQvkf2Exg==", + "license": "MIT", + "peer": true, + "dependencies": { + "@standard-schema/spec": "1.1.0", + "file-type": "22.0.2", + "iterare": "1.2.1", + "load-esm": "1.0.3", + "tslib": "2.8.1", + "uid": "2.0.2" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/nest" + }, + "peerDependencies": { + "class-transformer": ">=0.4.1", + "class-validator": ">=0.13.2", + "reflect-metadata": "^0.1.12 || ^0.2.0", + "rxjs": "^7.1.0" + }, + "peerDependenciesMeta": { + "class-transformer": { + "optional": true + }, + "class-validator": { + "optional": true + } + } + }, + "node_modules/@nestjs/core": { + "version": "12.0.1", + "resolved": "https://registry.npmjs.org/@nestjs/core/-/core-12.0.1.tgz", + "integrity": "sha512-rU6tAi8vDdyzHgN0iW0J4UJvziroOqzHqzlqL7phOSPizaXVEePfv+OUOsdJEOh0Qd14mslc3udOheLrAEcZow==", + "license": "MIT", + "peer": true, + "dependencies": { + "fast-safe-stringify": "2.1.1", + "iterare": "1.2.1", + "path-to-regexp": "8.4.2", + "tslib": "2.8.1", + "uid": "2.0.2" + }, + "engines": { + "node": ">= 20" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/nest" + }, + "peerDependencies": { + "@nestjs/common": "^12.0.0", + "@nestjs/microservices": "^12.0.0", + "@nestjs/platform-express": "^12.0.0", + "@nestjs/websockets": "^12.0.0", + "reflect-metadata": "^0.1.12 || ^0.2.0", + "rxjs": "^7.1.0" + }, + "peerDependenciesMeta": { + "@nestjs/microservices": { + "optional": true + }, + "@nestjs/platform-express": { + "optional": true + }, + "@nestjs/websockets": { + "optional": true + } + } + }, + "node_modules/@nestjs/platform-express": { + "version": "12.0.1", + "resolved": "https://registry.npmjs.org/@nestjs/platform-express/-/platform-express-12.0.1.tgz", + "integrity": "sha512-nF8bRgROptMyixYBfiJUAsjj2o9k13zxAjUKYaqHTPk8mTSd+gk7hXz6NykXNrfHWmMEYC9RttQlMUdMHNTbuA==", + "license": "MIT", + "peer": true, + "dependencies": { + "cors": "2.8.6", + "express": "5.2.1", + "multer": "2.2.0", + "path-to-regexp": "8.4.2", + "tslib": "2.8.1" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/nest" + }, + "peerDependencies": { + "@nestjs/common": "^12.0.0", + "@nestjs/core": "^12.0.0" + } + }, + "node_modules/@standard-schema/spec": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@standard-schema/spec/-/spec-1.1.0.tgz", + "integrity": "sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w==", + "license": "MIT" + }, + "node_modules/@tokenizer/inflate": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/@tokenizer/inflate/-/inflate-0.4.1.tgz", + "integrity": "sha512-2mAv+8pkG6GIZiF1kNg1jAjh27IDxEPKwdGul3snfztFerfPGI1LjDezZp3i7BElXompqEtPmoPx6c2wgtWsOA==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.3", + "token-types": "^6.1.1" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Borewit" + } + }, + "node_modules/@tokenizer/token": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/@tokenizer/token/-/token-0.3.0.tgz", + "integrity": "sha512-OvjF+z51L3ov0OyAU0duzsYuvO01PH7x4t6DJx+guahgTnBHkhJdG7soQeTSFLWN3efnHyibZ4Z8l2EuWwJN3A==", + "license": "MIT" + }, + "node_modules/@tsconfig/node10": { + "version": "1.0.13", + "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.13.tgz", + "integrity": "sha512-gcLdvR9HO1ZJBypsOGqaP6TFEzb6vIta0KSTLt9NAQ6pXQO3cRgSVyCN6pzYqI9DlJgY71XKO0dpDhCf08b3pg==", + "dev": true, + "license": "MIT" + }, + "node_modules/@tsconfig/node12": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", + "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==", + "dev": true, + "license": "MIT" + }, + "node_modules/@tsconfig/node14": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", + "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", + "dev": true, + "license": "MIT" + }, + "node_modules/@tsconfig/node16": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz", + "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/body-parser": { + "version": "1.19.6", + "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.6.tgz", + "integrity": "sha512-HLFeCYgz89uk22N5Qg3dvGvsv46B8GLvKKo1zKG4NybA8U2DiEO3w9lqGg29t/tfLRJpJ6iQxnVw4OnB7MoM9g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/connect": "*", + "@types/node": "*" + } + }, + "node_modules/@types/busboy": { + "version": "1.5.4", + "resolved": "https://registry.npmjs.org/@types/busboy/-/busboy-1.5.4.tgz", + "integrity": "sha512-kG7WrUuAKK0NoyxfQHsVE6j1m01s6kMma64E+OZenQABMQyTJop1DumUWcLwAQ2JzpefU7PDYoRDKl8uZosFjw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/@types/connect": { + "version": "3.4.38", + "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.38.tgz", + "integrity": "sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/@types/cookie-parser": { + "version": "1.4.10", + "resolved": "https://registry.npmjs.org/@types/cookie-parser/-/cookie-parser-1.4.10.tgz", + "integrity": "sha512-B4xqkqfZ8Wek+rCOeRxsjMS9OgvzebEzzLYw7NHYuvzb7IdxOkI0ZHGgeEBX4PUM7QGVvNSK60T3OvWj3YfBRg==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "@types/express": "*" + } + }, + "node_modules/@types/express": { + "version": "5.0.6", + "resolved": "https://registry.npmjs.org/@types/express/-/express-5.0.6.tgz", + "integrity": "sha512-sKYVuV7Sv9fbPIt/442koC7+IIwK5olP1KWeD88e/idgoJqDm3JV/YUiPwkoKK92ylff2MGxSz1CSjsXelx0YA==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "@types/body-parser": "*", + "@types/express-serve-static-core": "^5.0.0", + "@types/serve-static": "^2" + } + }, + "node_modules/@types/express-serve-static-core": { + "version": "5.1.3", + "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-5.1.3.tgz", + "integrity": "sha512-dPfW8NFiOF4wOHc7+N/QSxlY9cfSsenewGbAz8C8U/MULPd/YZ27LvJUIlzaXie7e6Ove9YunJGgC9tbHD2cKw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*", + "@types/qs": "*", + "@types/range-parser": "*", + "@types/send": "*" + } + }, + "node_modules/@types/http-errors": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@types/http-errors/-/http-errors-2.0.5.tgz", + "integrity": "sha512-r8Tayk8HJnX0FztbZN7oVqGccWgw98T/0neJphO91KkmOzug1KkofZURD4UaD5uH8AqcFLfdPErnBod0u71/qg==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/node": { + "version": "24.13.3", + "resolved": "https://registry.npmjs.org/@types/node/-/node-24.13.3.tgz", + "integrity": "sha512-Dh8vAsV36ig5wa9OX4pXvMc9D3Veibfw2wix0CUwYODLD8nkj9UsLjASr49nPg+2eKzxhBV+v7L8pXvT4e639Q==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "undici-types": "~7.18.0" + } + }, + "node_modules/@types/qs": { + "version": "6.15.1", + "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.15.1.tgz", + "integrity": "sha512-GZHUBZR9hckSUhrxmp1nG6NwdpM9fCunJwyThLW1X3AyHgd9IlHb6VANpQQqDr2o/qQp6McZ3y/IA2rVzKzSbw==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/range-parser": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.7.tgz", + "integrity": "sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/send": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@types/send/-/send-1.2.1.tgz", + "integrity": "sha512-arsCikDvlU99zl1g69TcAB3mzZPpxgw0UQnaHeC1Nwb015xp8bknZv5rIfri9xTOcMuaVgvabfIRA7PSZVuZIQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/@types/serve-static": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-2.2.0.tgz", + "integrity": "sha512-8mam4H1NHLtu7nmtalF7eyBH14QyOASmcxHhSfEoRyr0nP/YdoesEtU+uSRvMe96TW/HPTtkoKqQLl53N7UXMQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/http-errors": "*", + "@types/node": "*" + } + }, + "node_modules/accepts": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz", + "integrity": "sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng==", + "license": "MIT", + "dependencies": { + "mime-types": "^3.0.0", + "negotiator": "^1.0.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/acorn": { + "version": "8.18.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.18.0.tgz", + "integrity": "sha512-lGq+9yr1/GuAWaVYIHRjvvySG5/4VfKIvC8EWxStPdcDh/Ka7FG3twP6v4d5BkravUilhIAsG4Qj83t02LWUPQ==", + "dev": true, + "license": "MIT", + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/acorn-walk": { + "version": "8.3.5", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.5.tgz", + "integrity": "sha512-HEHNfbars9v4pgpW6SO1KSPkfoS0xVOM/9UzkJltjlsHZmJasxg8aXkuZa7SMf8vKGIBhpUsPluQSqhJFCqebw==", + "dev": true, + "license": "MIT", + "dependencies": { + "acorn": "^8.11.0" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/append-field": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/append-field/-/append-field-1.0.0.tgz", + "integrity": "sha512-klpgFSWLW1ZEs8svjfb7g4qWY0YS5imI82dTg+QahUvJ8YqAY0P10Uk8tTyh9ZGuYEZEMaeJYCF5BFuX552hsw==", + "license": "MIT" + }, + "node_modules/arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "dev": true, + "license": "MIT" + }, + "node_modules/body-parser": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.3.0.tgz", + "integrity": "sha512-2cGmJupaNgg+QUwVLAucDuWuoMZ6EX9iHDRswZ5lsNYEmwPaRknMPCLZz07yTzVq/83p4o/wzbDZbBrTvGGTIw==", + "license": "MIT", + "dependencies": { + "bytes": "^3.1.2", + "content-type": "^2.0.0", + "debug": "^4.4.3", + "http-errors": "^2.0.1", + "iconv-lite": "^0.7.2", + "on-finished": "^2.4.1", + "qs": "^6.15.2", + "raw-body": "^3.0.2", + "type-is": "^2.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/body-parser/node_modules/content-type": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-2.1.0.tgz", + "integrity": "sha512-mj7UPXE0jaqaOsukNZRUEfEi2AcL7C/vwmwcHV0O97eO1E1pxBZuyjlZrx5seTaNBg1U6+o35wpa35Qfcc+7ag==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/buffer-from": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", + "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", + "license": "MIT" + }, + "node_modules/busboy": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", + "integrity": "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==", + "dependencies": { + "streamsearch": "^1.1.0" + }, + "engines": { + "node": ">=10.16.0" + } + }, + "node_modules/bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/call-bound": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", + "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "get-intrinsic": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/concat-stream": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-2.0.0.tgz", + "integrity": "sha512-MWufYdFw53ccGjCA+Ol7XJYpAlW6/prSMzuPOTRnJGcGzuhLn4Scrz7qf6o8bROZ514ltazcIFJZevcfbo0x7A==", + "engines": [ + "node >= 6.0" + ], + "license": "MIT", + "dependencies": { + "buffer-from": "^1.0.0", + "inherits": "^2.0.3", + "readable-stream": "^3.0.2", + "typedarray": "^0.0.6" + } + }, + "node_modules/content-disposition": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-1.1.0.tgz", + "integrity": "sha512-5jRCH9Z/+DRP7rkvY83B+yGIGX96OYdJmzngqnw2SBSxqCFPd0w2km3s5iawpGX8krnwSGmF0FW5Nhr0Hfai3g==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/content-type": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", + "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", + "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie-parser": { + "version": "1.4.7", + "resolved": "https://registry.npmjs.org/cookie-parser/-/cookie-parser-1.4.7.tgz", + "integrity": "sha512-nGUvgXnotP3BsjiLX2ypbQnWoGUPIIfHQNZkkC668ntrzGWEZVW70HDEB1qnNGMicPje6EttlIgzo51YSwNQGw==", + "license": "MIT", + "dependencies": { + "cookie": "0.7.2", + "cookie-signature": "1.0.6" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/cookie-signature": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", + "integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==", + "license": "MIT" + }, + "node_modules/cors": { + "version": "2.8.6", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.6.tgz", + "integrity": "sha512-tJtZBBHA6vjIAaF6EnIaq6laBBP9aq/Y3ouVJjEfoHbRBcHBAHYcMh/w8LDrk2PvIMMq8gmopa5D4V8RmbrxGw==", + "license": "MIT", + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/cross-env": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", + "integrity": "sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==", + "dev": true, + "license": "MIT", + "dependencies": { + "cross-spawn": "^7.0.1" + }, + "bin": { + "cross-env": "src/bin/cross-env.js", + "cross-env-shell": "src/bin/cross-env-shell.js" + }, + "engines": { + "node": ">=10.14", + "npm": ">=6", + "yarn": ">=1" + } + }, + "node_modules/cross-spawn": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", + "dev": true, + "license": "MIT", + "dependencies": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/diff": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.4.tgz", + "integrity": "sha512-X07nttJQkwkfKfvTPG/KSnE2OMdcUCao6+eXF3wmnIQRn2aPAHH3VxDbDOdegkd6JbPsXqShpvEOHfAT+nCNwQ==", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.3.1" + } + }, + "node_modules/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", + "license": "MIT" + }, + "node_modules/encodeurl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", + "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-object-atoms": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.2.tgz", + "integrity": "sha512-HWcBoN6NileqtSydK2FqHbS/LoDd2pqrnQHLyJzBj4kOp/ky2MWMN694xOfkK8/SnUsW2DH7EfyVlydKCsm1Zw==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", + "license": "MIT" + }, + "node_modules/etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/express": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/express/-/express-5.2.1.tgz", + "integrity": "sha512-hIS4idWWai69NezIdRt2xFVofaF4j+6INOpJlVOLDO8zXGpUVEVzIYk12UUi2JzjEzWL3IOAxcTubgz9Po0yXw==", + "license": "MIT", + "dependencies": { + "accepts": "^2.0.0", + "body-parser": "^2.2.1", + "content-disposition": "^1.0.0", + "content-type": "^1.0.5", + "cookie": "^0.7.1", + "cookie-signature": "^1.2.1", + "debug": "^4.4.0", + "depd": "^2.0.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "finalhandler": "^2.1.0", + "fresh": "^2.0.0", + "http-errors": "^2.0.0", + "merge-descriptors": "^2.0.0", + "mime-types": "^3.0.0", + "on-finished": "^2.4.1", + "once": "^1.4.0", + "parseurl": "^1.3.3", + "proxy-addr": "^2.0.7", + "qs": "^6.14.0", + "range-parser": "^1.2.1", + "router": "^2.2.0", + "send": "^1.1.0", + "serve-static": "^2.2.0", + "statuses": "^2.0.1", + "type-is": "^2.0.1", + "vary": "^1.1.2" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/express/node_modules/cookie-signature": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.2.2.tgz", + "integrity": "sha512-D76uU73ulSXrD1UXF4KE2TMxVVwhsnCgfAyTg9k8P6KGZjlXKrOLe4dJQKI3Bxi5wjesZoFXJWElNWBjPZMbhg==", + "license": "MIT", + "engines": { + "node": ">=6.6.0" + } + }, + "node_modules/fast-safe-stringify": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz", + "integrity": "sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==", + "license": "MIT" + }, + "node_modules/file-type": { + "version": "22.0.2", + "resolved": "https://registry.npmjs.org/file-type/-/file-type-22.0.2.tgz", + "integrity": "sha512-0H8TsCUGBLx+V5adH3EY52hTAcyLKbV1D4gq5cIOJ6DnQAHeV9Z2Hhuc5CoBX4YmvB2oL+JIC84z0qO7JsCoNw==", + "license": "MIT", + "dependencies": { + "@tokenizer/inflate": "^0.4.1", + "strtok3": "^10.3.5", + "token-types": "^6.1.2", + "uint8array-extras": "^1.5.0" + }, + "engines": { + "node": ">=22" + }, + "funding": { + "url": "https://github.com/sindresorhus/file-type?sponsor=1" + } + }, + "node_modules/finalhandler": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-2.1.1.tgz", + "integrity": "sha512-S8KoZgRZN+a5rNwqTxlZZePjT/4cnm0ROV70LedRHZ0p8u9fRID0hJUZQpkKLzro8LfmC8sx23bY6tVNxv8pQA==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "on-finished": "^2.4.1", + "parseurl": "^1.3.3", + "statuses": "^2.0.1" + }, + "engines": { + "node": ">= 18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/forwarded": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", + "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/fresh": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-2.0.0.tgz", + "integrity": "sha512-Rx/WycZ60HOaqLKAi6cHRKKI7zxWbJ31MhntmtwMoaTeF7XFH9hhBp8vITaMidfljRQ6eYWCKkaTK+ykVJHP2A==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-intrinsic": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", + "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", + "function-bind": "^1.1.2", + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "license": "MIT", + "dependencies": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz", + "integrity": "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/http-errors": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz", + "integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==", + "license": "MIT", + "dependencies": { + "depd": "~2.0.0", + "inherits": "~2.0.4", + "setprototypeof": "~1.2.0", + "statuses": "~2.0.2", + "toidentifier": "~1.0.1" + }, + "engines": { + "node": ">= 0.8" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/iconv-lite": { + "version": "0.7.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.3.tgz", + "integrity": "sha512-IKXpvIzjnC9XTAUbVBcMfGS0EPaIXtW6v+zr+RRp+hqULEpo0owZax6wyRwPOJbWbzjYspQwusTsfVr0ifh4uQ==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/ieee754": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "BSD-3-Clause" + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "license": "ISC" + }, + "node_modules/ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", + "license": "MIT", + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/is-promise": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-4.0.0.tgz", + "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", + "license": "MIT" + }, + "node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "dev": true, + "license": "ISC" + }, + "node_modules/iterare": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/iterare/-/iterare-1.2.1.tgz", + "integrity": "sha512-RKYVTCjAnRthyJes037NX/IiqeidgN1xc3j1RjFfECFp28A1GVwK9nA+i0rJPaHqSZwygLzRnFlzUuHFoWWy+Q==", + "license": "ISC", + "engines": { + "node": ">=6" + } + }, + "node_modules/json5": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", + "license": "MIT", + "bin": { + "json5": "lib/cli.js" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/load-esm": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/load-esm/-/load-esm-1.0.3.tgz", + "integrity": "sha512-v5xlu8eHD1+6r8EHTg6hfmO97LN8ugKtiXcy5e6oN72iD2r6u0RPfLl6fxM+7Wnh2ZRq15o0russMst44WauPA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/Borewit" + }, + { + "type": "buymeacoffee", + "url": "https://buymeacoffee.com/borewit" + } + ], + "license": "MIT", + "engines": { + "node": ">=13.2.0" + } + }, + "node_modules/make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", + "dev": true, + "license": "ISC" + }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/media-typer": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-1.1.1.tgz", + "integrity": "sha512-yz3xRaG20c6/BOzvYoDaGtPmGscs7YivItZEEqe6GbwNfHuxu9YNmvnEkMzKldAGY4/80pRcQRZSEnhquk9XuQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/merge-descriptors": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-2.0.0.tgz", + "integrity": "sha512-Snk314V5ayFLhp3fkUREub6WtjBfPdCPY1Ln8/8munuLuiYhsABgBVWsozAG+MWMbVEvcdcpbi9R7ww22l9Q3g==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/mime-db": { + "version": "1.54.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.54.0.tgz", + "integrity": "sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.2.tgz", + "integrity": "sha512-Lbgzdk0h4juoQ9fCKXW4by0UJqj+nOOrI9MJ1sSj4nI8aI2eo1qmvQEie4VD1glsS250n15LsWsYtCugiStS5A==", + "license": "MIT", + "dependencies": { + "mime-db": "^1.54.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/multer": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/multer/-/multer-2.2.0.tgz", + "integrity": "sha512-6rdyFg2kLrMh9Jee7/BMPuV9lEAd7lLW2YUpF9/YxR7njyoUwwQ0ZPh3TaIY50Sw6vlyD2HW3wGOkTS4P79xrQ==", + "license": "MIT", + "dependencies": { + "append-field": "^1.0.0", + "busboy": "^1.6.0", + "concat-stream": "^2.0.0", + "type-is": "^1.6.18" + }, + "engines": { + "node": ">= 10.16.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/multer/node_modules/media-typer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/multer/node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/multer/node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/multer/node_modules/type-is": { + "version": "1.6.18", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", + "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", + "license": "MIT", + "dependencies": { + "media-typer": "0.3.0", + "mime-types": "~2.1.24" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/negotiator": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.1.0.tgz", + "integrity": "sha512-NMPBRMJgiQHjbd8phG3Vebdx4kZ1H121rbl5IkMqeOsahptB9BKo/d7oJ3zTXqTgagn2bWlNSXkh0QUGM31RYg==", + "license": "MIT", + "dependencies": { + "content-type": "^2.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/negotiator/node_modules/content-type": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-2.1.0.tgz", + "integrity": "sha512-mj7UPXE0jaqaOsukNZRUEfEi2AcL7C/vwmwcHV0O97eO1E1pxBZuyjlZrx5seTaNBg1U6+o35wpa35Qfcc+7ag==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/object-inspect": { + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", + "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/on-finished": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", + "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", + "license": "MIT", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "license": "ISC", + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/path-to-regexp": { + "version": "8.4.2", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.4.2.tgz", + "integrity": "sha512-qRcuIdP69NPm4qbACK+aDogI5CBDMi1jKe0ry5rSQJz8JVLsC7jV8XpiJjGRLLol3N+R5ihGYcrPLTno6pAdBA==", + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/proxy-addr": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", + "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==", + "license": "MIT", + "dependencies": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/qs": { + "version": "6.16.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.16.0.tgz", + "integrity": "sha512-h6fhOIaRrID2CbEY2fqs+7t+UXZo+MLAnU5gRIq85uFtdiUPCdsApMlHhXogKVM4HM2DVbIjGNTTYH2OcmP1vA==", + "license": "BSD-3-Clause", + "dependencies": { + "es-define-property": "^1.0.1", + "side-channel": "^1.1.1" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/range-parser": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.3.0.tgz", + "integrity": "sha512-hek2mFQpPuI4E1BBKrSto+BU3e3x4xuarsbiwr3+lf7p44juvFMV0XFWQAP3xUyqXA4RrXLIoaSUGbSt056ZMw==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/raw-body": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-3.0.2.tgz", + "integrity": "sha512-K5zQjDllxWkf7Z5xJdV0/B0WTNqx6vxG70zJE4N0kBs4LovmEYWJzQGxC9bS9RAKu3bgM40lrd5zoLJ12MQ5BA==", + "license": "MIT", + "dependencies": { + "bytes": "~3.1.2", + "http-errors": "~2.0.1", + "iconv-lite": "~0.7.0", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/readable-stream": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", + "license": "MIT", + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/reflect-metadata": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.2.2.tgz", + "integrity": "sha512-urBwgfrvVP/eAyXx4hluJivBKzuEbSQs9rKWCrCkbSxNv8mxPcUZKeuoF3Uy4mJl3Lwprp6yy5/39VWigZ4K6Q==", + "license": "Apache-2.0", + "peer": true + }, + "node_modules/router": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/router/-/router-2.2.0.tgz", + "integrity": "sha512-nLTrUKm2UyiL7rlhapu/Zl45FwNgkZGaCpZbIHajDYgwlJCOzLSk+cIPAnsEqV955GjILJnKbdQC1nVPz+gAYQ==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.0", + "depd": "^2.0.0", + "is-promise": "^4.0.0", + "parseurl": "^1.3.3", + "path-to-regexp": "^8.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/rxjs": { + "version": "7.8.2", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.2.tgz", + "integrity": "sha512-dhKf903U/PQZY6boNNtAGdWbG85WAbjT/1xYoZIC7FAY0yWapOBQVsVrDl58W86//e1VpMNBtRV4MaXfdMySFA==", + "license": "Apache-2.0", + "peer": true, + "dependencies": { + "tslib": "^2.1.0" + } + }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "license": "MIT" + }, + "node_modules/send": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/send/-/send-1.2.1.tgz", + "integrity": "sha512-1gnZf7DFcoIcajTjTwjwuDjzuz4PPcY2StKPlsGAQ1+YH20IRVrBaXSWmdjowTJ6u8Rc01PoYOGHXfP1mYcZNQ==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.3", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "fresh": "^2.0.0", + "http-errors": "^2.0.1", + "mime-types": "^3.0.2", + "ms": "^2.1.3", + "on-finished": "^2.4.1", + "range-parser": "^1.2.1", + "statuses": "^2.0.2" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/serve-static": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-2.2.1.tgz", + "integrity": "sha512-xRXBn0pPqQTVQiC8wyQrKs2MOlX24zQ0POGaj0kultvoOCstBQM5yvOhAVSUwOMjQtTvsPWoNCHfPGwaaQJhTw==", + "license": "MIT", + "dependencies": { + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "parseurl": "^1.3.3", + "send": "^1.2.0" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", + "license": "ISC" + }, + "node_modules/shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dev": true, + "license": "MIT", + "dependencies": { + "shebang-regex": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/side-channel": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.1.tgz", + "integrity": "sha512-6x6dK6zJdpTzF4sQeNYxwtvBzf6Eg4GtlesS94HOvTudUeyK2WXAaIfmDgsyslYrRBeFIlsi54AYsFGUuhmvrQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.4", + "side-channel-list": "^1.0.1", + "side-channel-map": "^1.0.1", + "side-channel-weakmap": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-list": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.1.tgz", + "integrity": "sha512-mjn/0bi/oUURjc5Xl7IaWi/OJJJumuoJFQJfDDyO46+hBWsfaVM65TBHq2eoZBhzl9EchxOijpkbRC8SVBQU0w==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.4" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-map": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", + "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-weakmap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", + "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3", + "side-channel-map": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/statuses": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz", + "integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/streamsearch": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz", + "integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==", + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/string_decoder": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", + "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", + "license": "MIT", + "dependencies": { + "safe-buffer": "~5.2.0" + } + }, + "node_modules/strip-bom": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", + "integrity": "sha512-vavAMRXOgBVNF6nyEEmL3DBK19iRpDcoIwW+swQ+CbGiu7lju6t+JklA1MHweoWtadgt4ISVUsXLyDq34ddcwA==", + "license": "MIT", + "engines": { + "node": ">=4" + } + }, + "node_modules/strtok3": { + "version": "10.3.5", + "resolved": "https://registry.npmjs.org/strtok3/-/strtok3-10.3.5.tgz", + "integrity": "sha512-ki4hZQfh5rX0QDLLkOCj+h+CVNkqmp/CMf8v8kZpkNVK6jGQooMytqzLZYUVYIZcFZ6yDB70EfD8POcFXiF5oA==", + "license": "MIT", + "dependencies": { + "@tokenizer/token": "^0.3.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Borewit" + } + }, + "node_modules/toidentifier": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "license": "MIT", + "engines": { + "node": ">=0.6" + } + }, + "node_modules/token-types": { + "version": "6.1.2", + "resolved": "https://registry.npmjs.org/token-types/-/token-types-6.1.2.tgz", + "integrity": "sha512-dRXchy+C0IgK8WPC6xvCHFRIWYUbqqdEIKPaKo/AcTUNzwLTK6AH7RjdLWsEZcAN/TBdtfUw3PYEgPr5VPr6ww==", + "license": "MIT", + "dependencies": { + "@borewit/text-codec": "^0.2.1", + "@tokenizer/token": "^0.3.0", + "ieee754": "^1.2.1" + }, + "engines": { + "node": ">=14.16" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Borewit" + } + }, + "node_modules/ts-node": { + "version": "10.9.2", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", + "integrity": "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@cspotcode/source-map-support": "^0.8.0", + "@tsconfig/node10": "^1.0.7", + "@tsconfig/node12": "^1.0.7", + "@tsconfig/node14": "^1.0.0", + "@tsconfig/node16": "^1.0.2", + "acorn": "^8.4.1", + "acorn-walk": "^8.1.1", + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "v8-compile-cache-lib": "^3.0.1", + "yn": "3.1.1" + }, + "bin": { + "ts-node": "dist/bin.js", + "ts-node-cwd": "dist/bin-cwd.js", + "ts-node-esm": "dist/bin-esm.js", + "ts-node-script": "dist/bin-script.js", + "ts-node-transpile-only": "dist/bin-transpile.js", + "ts-script": "dist/bin-script-deprecated.js" + }, + "peerDependencies": { + "@swc/core": ">=1.2.50", + "@swc/wasm": ">=1.2.50", + "@types/node": "*", + "typescript": ">=2.7" + }, + "peerDependenciesMeta": { + "@swc/core": { + "optional": true + }, + "@swc/wasm": { + "optional": true + } + } + }, + "node_modules/tsconfig-paths": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-4.2.0.tgz", + "integrity": "sha512-NoZ4roiN7LnbKn9QqE1amc9DJfzvZXxF4xDavcOWt1BPkdx+m+0gJuPM+S0vCe7zTJMYUP0R8pO2XMr+Y8oLIg==", + "license": "MIT", + "dependencies": { + "json5": "^2.2.2", + "minimist": "^1.2.6", + "strip-bom": "^3.0.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/tslib": { + "version": "2.8.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", + "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", + "license": "0BSD" + }, + "node_modules/type-is": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-2.1.0.tgz", + "integrity": "sha512-faYHw0anBbc/kWF3zFTEnxSFOAGUX9GFbOBthvDdLsIlEoWOFOtS0zgCiQYwIskL9iGXZL3kAXD8OoZ4GmMATA==", + "license": "MIT", + "dependencies": { + "content-type": "^2.0.0", + "media-typer": "^1.1.0", + "mime-types": "^3.0.0" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/type-is/node_modules/content-type": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-2.1.0.tgz", + "integrity": "sha512-mj7UPXE0jaqaOsukNZRUEfEi2AcL7C/vwmwcHV0O97eO1E1pxBZuyjlZrx5seTaNBg1U6+o35wpa35Qfcc+7ag==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/typedarray": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", + "integrity": "sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==", + "license": "MIT" + }, + "node_modules/typescript": { + "version": "5.9.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", + "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", + "dev": true, + "license": "Apache-2.0", + "peer": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/uid": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/uid/-/uid-2.0.2.tgz", + "integrity": "sha512-u3xV3X7uzvi5b1MncmZo3i2Aw222Zk1keqLA1YkHldREkAhAqi65wuPfe7lHx8H/Wzy+8CE7S7uS3jekIM5s8g==", + "license": "MIT", + "dependencies": { + "@lukeed/csprng": "^1.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/uint8array-extras": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/uint8array-extras/-/uint8array-extras-1.5.0.tgz", + "integrity": "sha512-rvKSBiC5zqCCiDZ9kAOszZcDvdAHwwIKJG33Ykj43OKcWsnmcBRL09YTU4nOeHZ8Y2a7l1MgTd08SBe9A8Qj6A==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/undici-types": { + "version": "7.18.2", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.18.2.tgz", + "integrity": "sha512-AsuCzffGHJybSaRrmr5eHr81mwJU3kjw6M+uprWvCXiNeN9SOGwQ3Jn8jb8m3Z6izVgknn1R0FTCEAP2QrLY/w==", + "dev": true, + "license": "MIT" + }, + "node_modules/unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", + "license": "MIT" + }, + "node_modules/v8-compile-cache-lib": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", + "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", + "dev": true, + "license": "MIT" + }, + "node_modules/vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, + "license": "ISC", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "license": "ISC" + }, + "node_modules/yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + } + } +} diff --git a/api/package.json b/api/package.json new file mode 100644 index 0000000..ce4f013 --- /dev/null +++ b/api/package.json @@ -0,0 +1,32 @@ +{ + "name": "contentos-api", + "version": "0.1.0", + "private": true, + "description": "The Content OS backend, as a NestJS service. Shares lib/server with the repo root.", + "scripts": { + "dev": "cross-env TS_NODE_TRANSPILE_ONLY=1 CONTENTOS_DATA_DIR=../.data ts-node -r tsconfig-paths/register src/main.ts", + "build": "tsc -p tsconfig.json", + "start": "cross-env TS_NODE_BASEURL=./dist node -r tsconfig-paths/register dist/api/src/main.js", + "start:local": "cross-env TS_NODE_BASEURL=./dist CONTENTOS_DATA_DIR=../.data node -r tsconfig-paths/register dist/api/src/main.js", + "typecheck": "tsc -p tsconfig.json --noEmit" + }, + "dependencies": { + "@nestjs/common": "^12.0.1", + "@nestjs/core": "^12.0.1", + "@nestjs/platform-express": "^12.0.1", + "busboy": "^1.6.0", + "cookie-parser": "^1.4.7", + "reflect-metadata": "^0.2.2", + "rxjs": "^7.8.2", + "tsconfig-paths": "^4.2.0" + }, + "devDependencies": { + "@types/busboy": "^1.5.4", + "@types/cookie-parser": "^1.4.9", + "@types/express": "^5.0.3", + "@types/node": "^24.13.3", + "cross-env": "^7.0.3", + "ts-node": "^10.9.2", + "typescript": "^5" + } +} diff --git a/api/src/app.module.ts b/api/src/app.module.ts new file mode 100644 index 0000000..e647f3f --- /dev/null +++ b/api/src/app.module.ts @@ -0,0 +1,49 @@ +import { Module } from "@nestjs/common"; +import { APP_GUARD } from "@nestjs/core"; + +import { SessionGuard } from "./common/session.guard"; +import { AuthController } from "./auth/auth.controller"; +import { WorkspacesController } from "./workspaces/workspaces.controller"; +import { + SeriesController, + TopicsController, +} from "./series/series.controller"; +import { PacksController } from "./packs/packs.controller"; +import { ToolsController } from "./tools/tools.controller"; +import { SettingsController } from "./settings/settings.controller"; +import { IntegrationsController } from "./integrations/integrations.controller"; +import { RunsController } from "./runs/runs.controller"; +import { SourcesController } from "./sources/sources.controller"; +import { ResearchController } from "./research/research.controller"; + +/** + * One module, because there is one database and one set of rules. + * + * Nest's usual shape is a module per feature, each with its own providers. + * Here the "providers" are the functions in `lib/server` — repos and services + * shared with the repo root — and a controller is a thin translation from HTTP + * to those. Ten controllers in one module is honest about that; ten modules + * each importing nothing would be ceremony. + * + * The session guard is global. Every route is behind it unless the handler + * says otherwise with `@Public()` — the auth gap that the audit found was + * fifteen routes that each had to remember a line, and a default that fails + * closed cannot be forgotten. + */ +@Module({ + controllers: [ + AuthController, + WorkspacesController, + SeriesController, + TopicsController, + PacksController, + ToolsController, + SettingsController, + IntegrationsController, + RunsController, + SourcesController, + ResearchController, + ], + providers: [{ provide: APP_GUARD, useClass: SessionGuard }], +}) +export class AppModule {} diff --git a/api/src/auth/auth.controller.ts b/api/src/auth/auth.controller.ts new file mode 100644 index 0000000..f94c1a7 --- /dev/null +++ b/api/src/auth/auth.controller.ts @@ -0,0 +1,164 @@ +import { + Body, + Controller, + Delete, + Get, + Headers, + HttpCode, + NotFoundException, + Param, + Post, + Res, +} from "@nestjs/common"; +import type { Response } from "express"; + +import { + authenticate, + createInvite, + createUser, + endOtherSessions, + endSession, + listInvites, + listSessions, + listUsers, + removeUser, + revokeInvite, + signupOpen, + startSession, + sweepSessions, + updatePassword, + type User, +} from "@/lib/server/auth"; + +import { clearSession, setSession } from "../common/cookie"; +import { Public } from "../common/session.guard"; +import { CurrentUser, SessionId } from "../common/user.decorator"; + +/** + * Signing in, signing up, and the people who can. + * + * The four routes a visitor reaches before they have a session are `@Public()`; + * everything else is behind the global guard. The cookie is set by this + * process, on this origin — see common/cookie.ts for what that means when the + * web app is somewhere else. + */ +@Controller() +export class AuthController { + @Public() + @Post("auth/login") + @HttpCode(200) + async login( + @Body() body: { email?: string; password?: string }, + @Headers("user-agent") agent: string | undefined, + @Res({ passthrough: true }) res: Response, + ) { + const user = await authenticate(body.email ?? "", body.password ?? ""); + void sweepSessions(); + setSession(res, await startSession(user.id, agent ?? "")); + return user; + } + + @Public() + @Get("auth/signup") + async signupOpen() { + return { open: await signupOpen() }; + } + + @Public() + @Post("auth/signup") + async signup( + @Body() + body: { email?: string; password?: string; name?: string; invite?: string }, + @Headers("user-agent") agent: string | undefined, + @Res({ passthrough: true }) res: Response, + ) { + const user = await createUser({ + email: body.email ?? "", + password: body.password ?? "", + name: body.name, + invite: body.invite, + }); + setSession(res, await startSession(user.id, agent ?? "")); + return user; + } + + @Public() + @Post("auth/logout") + @HttpCode(200) + async logout( + @SessionId() sid: string, + @Res({ passthrough: true }) res: Response, + ) { + if (sid) await endSession(sid); + clearSession(res); + return { ok: true }; + } + + /** Who is signed in, and whether the console still has no owner. */ + @Public() + @Get("auth/me") + async me(@CurrentUser() user: User | null) { + return { user, signupOpen: await signupOpen() }; + } + + @Post("auth/password") + @HttpCode(200) + async password( + @CurrentUser() user: User, + @Body() body: { current?: string; next?: string }, + @Headers("user-agent") agent: string | undefined, + @Res({ passthrough: true }) res: Response, + ) { + await updatePassword(user.id, body.current ?? "", body.next ?? ""); + // A new session on a new password: whatever knew the old one is out. + setSession(res, await startSession(user.id, agent ?? "")); + return { ok: true }; + } + + @Get("auth/sessions") + sessions(@CurrentUser() user: User, @SessionId() sid: string) { + return listSessions(user.id, sid); + } + + @Delete("auth/sessions") + async endOthers(@CurrentUser() user: User, @SessionId() sid: string) { + return { ended: await endOtherSessions(user.id, sid) }; + } + + @Get("invites") + invites() { + return listInvites(); + } + + @Post("invites") + invite( + @CurrentUser() user: User, + @Body() body: { email?: string; note?: string; days?: number }, + ) { + return createInvite({ + createdBy: user.id, + email: body.email, + note: body.note, + days: body.days, + }); + } + + @Delete("invites/:token") + async revoke(@Param("token") token: string) { + const gone = await revokeInvite(token); + if (!gone) throw new NotFoundException("That invite is already used"); + return { ok: true }; + } + + @Get("users") + users() { + return listUsers(); + } + + @Delete("users/:id") + async remove(@CurrentUser() me: User, @Param("id") id: string) { + const gone = await removeUser(id, me.id); + if (!gone) throw new NotFoundException("No such account"); + return { ok: true }; + } +} diff --git a/api/src/common/cookie.ts b/api/src/common/cookie.ts new file mode 100644 index 0000000..e10b889 --- /dev/null +++ b/api/src/common/cookie.ts @@ -0,0 +1,40 @@ +import type { CookieOptions, Response } from "express"; + +import { SESSION_COOKIE } from "@/lib/server/auth"; + +const SESSION_DAYS = 30; + +/** + * How the session cookie is set, on an API that lives on its own origin. + * + * The Next handlers set it same-origin with SameSite=Lax. Here the browser + * may be on app.example.com and this on api.example.com — same *site*, so Lax + * still travels — or on two unrelated hosts, where only SameSite=None with + * Secure does. Which one is a deployment fact, not a code one, so it is env: + * + * COOKIE_SAMESITE lax (default) | none | strict + * COOKIE_DOMAIN ".example.com" to share the cookie across subdomains, + * which is also what lets the Next proxy see it and send + * a signed-out visitor to /login instead of a blank shell. + * + * Secure is on in production regardless — a session cookie over plain HTTP + * is a session handed to the network. + */ +export function cookieOptions(maxAgeDays = SESSION_DAYS): CookieOptions { + const sameSite = (process.env.COOKIE_SAMESITE ?? "lax").toLowerCase(); + return { + httpOnly: true, + sameSite: + sameSite === "none" ? "none" : sameSite === "strict" ? "strict" : "lax", + secure: process.env.NODE_ENV === "production" || sameSite === "none", + path: "/", + ...(process.env.COOKIE_DOMAIN ? { domain: process.env.COOKIE_DOMAIN } : {}), + maxAge: maxAgeDays * 24 * 60 * 60 * 1000, + }; +} + +export const setSession = (res: Response, sid: string) => + res.cookie(SESSION_COOKIE, sid, cookieOptions()); + +export const clearSession = (res: Response) => + res.clearCookie(SESSION_COOKIE, { ...cookieOptions(), maxAge: undefined }); diff --git a/api/src/common/errors.filter.ts b/api/src/common/errors.filter.ts new file mode 100644 index 0000000..279a35d --- /dev/null +++ b/api/src/common/errors.filter.ts @@ -0,0 +1,70 @@ +import { + ArgumentsHost, + Catch, + ExceptionFilter, + HttpException, +} from "@nestjs/common"; +import type { Response } from "express"; + +import { DuplicateName } from "@/lib/server/repos/series"; + +/** + * Every thrown thing, as the JSON the browser already understands. + * + * The same rules `caught()` in lib/server/http.ts applies for the Next + * handlers, so the API answers identically whichever process is behind it: + * `{ error }` with the status the service asked for, 503 with a sentence + * when Postgres is not there, and `existing` beside the error on a duplicate + * name so the screen can offer the merge. + */ + +const OFFLINE = + /ECONNREFUSED|ENOTFOUND|EHOSTUNREACH|ETIMEDOUT|Connection terminated|connect ECONN/i; + +const isOffline = (e: unknown) => { + const code = (e as { code?: string })?.code ?? ""; + const message = e instanceof Error ? e.message : String(e); + return OFFLINE.test(code) || OFFLINE.test(message); +}; + +@Catch() +export class ErrorsFilter implements ExceptionFilter { + catch(e: unknown, host: ArgumentsHost) { + const res = host.switchToHttp().getResponse(); + + if (e instanceof HttpException) { + const body = e.getResponse(); + const message = + typeof body === "string" + ? body + : ((body as { message?: string | string[] }).message ?? e.message); + res.status(e.getStatus()).json({ + error: Array.isArray(message) ? message.join(", ") : message, + }); + return; + } + + if (e instanceof DuplicateName) { + res.status(409).json({ error: e.message, existing: e.existing }); + return; + } + + if (isOffline(e)) { + res.status(503).json({ + error: + "The database is not running. Start Docker Desktop, then run: npm run db:up", + }); + return; + } + + // AuthError, RunError, IngestError, ResearchError, FetchError all carry + // the status they want; anything without one is a 500 with its message. + const status = + typeof e === "object" && e && "status" in e + ? Number((e as { status: number }).status) + : 500; + res + .status(Number.isFinite(status) && status >= 400 ? status : 500) + .json({ error: e instanceof Error ? e.message : "Something went wrong" }); + } +} diff --git a/api/src/common/session.guard.ts b/api/src/common/session.guard.ts new file mode 100644 index 0000000..eadda0b --- /dev/null +++ b/api/src/common/session.guard.ts @@ -0,0 +1,52 @@ +import { + CanActivate, + ExecutionContext, + Injectable, + SetMetadata, + UnauthorizedException, +} from "@nestjs/common"; +import { Reflector } from "@nestjs/core"; +import type { Request } from "express"; + +import { SESSION_COOKIE, sessionUser, type User } from "@/lib/server/auth"; + +/** Marks a handler reachable without a session — the sign-in routes. */ +export const PUBLIC = "contentos:public"; +export const Public = () => SetMetadata(PUBLIC, true); + +/** The request, once the guard has run: the user rides on it. */ +export type SessionRequest = Request & { user?: User; sessionId: string }; + +/** + * The lock on every route. + * + * Reads the session cookie off the request, looks the session up, and puts + * the user on the request for `@CurrentUser()`. Global, so a new controller + * is closed by default: the audit found fifteen Next route handlers that + * each had to remember to call `requireUser()`, and did not. + * + * A route that must be open — login, signup, the "is signup open" probe — + * says so with `@Public()`. The session id is put on the request either way, + * because logout needs it whether or not the session is still valid. + */ +@Injectable() +export class SessionGuard implements CanActivate { + constructor(private readonly reflector: Reflector) {} + + async canActivate(context: ExecutionContext) { + const req = context.switchToHttp().getRequest(); + req.sessionId = String(req.cookies?.[SESSION_COOKIE] ?? ""); + + const open = this.reflector.getAllAndOverride(PUBLIC, [ + context.getHandler(), + context.getClass(), + ]); + + const user = req.sessionId ? await sessionUser(req.sessionId) : null; + if (user) req.user = user; + if (open) return true; + + if (!user) throw new UnauthorizedException("Sign in first"); + return true; + } +} diff --git a/api/src/common/user.decorator.ts b/api/src/common/user.decorator.ts new file mode 100644 index 0000000..e6c639a --- /dev/null +++ b/api/src/common/user.decorator.ts @@ -0,0 +1,21 @@ +import { createParamDecorator, type ExecutionContext } from "@nestjs/common"; + +import type { SessionRequest } from "./session.guard"; + +/** + * The signed-in user, as a handler parameter. + * + * `@CurrentUser()` on a guarded route is never undefined — the guard has + * already refused the request otherwise. On a `@Public()` route it may be + * null, which is how /auth/me says "nobody" without failing. + */ +export const CurrentUser = createParamDecorator( + (_data: unknown, ctx: ExecutionContext) => + ctx.switchToHttp().getRequest().user ?? null, +); + +/** The session id off the cookie, valid or not — logout needs it either way. */ +export const SessionId = createParamDecorator( + (_data: unknown, ctx: ExecutionContext) => + ctx.switchToHttp().getRequest().sessionId, +); diff --git a/app/api/integrations/test/route.ts b/api/src/integrations/integrations.controller.ts similarity index 51% rename from app/api/integrations/test/route.ts rename to api/src/integrations/integrations.controller.ts index b67009c..1bc2a69 100644 --- a/app/api/integrations/test/route.ts +++ b/api/src/integrations/integrations.controller.ts @@ -1,31 +1,68 @@ -import { requireUser } from "@/lib/server/auth"; +import { + BadRequestException, + Body, + Controller, + ConflictException, + Get, + HttpCode, + Patch, + Post, + Query, +} from "@nestjs/common"; + import { brainStatuses, findBrain, write } from "@/lib/server/brains"; -import { caught, fail, ok, ready } from "@/lib/server/http"; +import { getSettings, listSecrets, setSettings } from "@/lib/server/repos/settings"; +import { toolStatuses } from "@/lib/server/tools"; -/** A cold CLI can take a while to answer its first prompt. */ -export const maxDuration = 200; +const MEDIA = ["yt-dlp", "ffmpeg", "ffprobe", "whisper"]; /** - * Ask a model to say one word, and report exactly what happened. + * What this machine can actually reach, probed by running it. * - * Installed is not the same as working, and the difference is invisible until - * something is actually sent: a CLI can be on PATH, report a version, even be - * logged in, and still fail — out of date, no auth method configured, a model - * name the account cannot reach. Every one of those looks identical to a - * `--version` probe, and the first time you would otherwise find out is six - * minutes into a twelve-section run. + * The models and the local binaries, each checked by invoking it rather than + * by reading a flag somebody set. `?recheck=1` runs the probes again instead + * of answering from the cache. */ -export async function POST(request: Request) { - try { - await ready(); - await requireUser(); - const body = (await request.json().catch(() => ({}))) as { id?: string }; +@Controller("integrations") +export class IntegrationsController { + @Get() + async wiring(@Query("recheck") recheck?: string) { + const again = recheck === "1"; + const [brains, tools, settings, keys] = await Promise.all([ + again ? toolStatuses(true).then(brainStatuses) : brainStatuses(), + toolStatuses(again), + getSettings(), + listSecrets(), + ]); + return { + brains, + tools: tools.filter((t) => MEDIA.includes(t.id)), + settings, + keys: Object.keys(keys), + }; + } + + /** Pick the brain, or switch local tools on and off. */ + @Patch() + async update(@Body() body: { brain?: string; enabled?: string[] }) { + if (body.brain) { + const status = (await brainStatuses()).find((b) => b.id === body.brain); + if (!status) throw new BadRequestException(`No model called "${body.brain}"`); + if (!status.available) throw new ConflictException(status.reason); + } + return setSettings(body); + } + + /** Ask a model for two words, and report what happened. */ + @Post("test") + @HttpCode(200) + async test(@Body() body: { id?: string }) { const def = findBrain(body.id ?? ""); - if (!def) return fail("No such model"); + if (!def) throw new BadRequestException("No such model"); const status = (await brainStatuses()).find((b) => b.id === def.id)!; if (!status.available) { - return ok({ ok: false, ms: 0, reply: "", error: status.reason, fix: "" }); + return { ok: false, ms: 0, reply: "", error: status.reason, fix: "" }; } const started = Date.now(); @@ -36,44 +73,32 @@ export async function POST(request: Request) { tier: "cheap", timeoutMs: 150_000, }); - return ok({ + return { ok: Boolean(reply.trim()), ms: Date.now() - started, reply: reply.slice(0, 200), error: reply.trim() ? "" : "It answered with nothing", fix: "", transport: status.transport, - }); + }; } catch (e) { - return ok({ + return { ok: false, ms: Date.now() - started, reply: "", - // The tool's own words, not a summary of them. "Please set an Auth - // method" is the whole fix; "could not reach Gemini" is not. error: e instanceof Error ? e.message.slice(0, 400) : "It did not answer", fix: e instanceof Error ? fixFor(def.id, e.message) : "", transport: status.transport, - }); + }; } - } catch (e) { - return caught(e); } } -/** - * The command that fixes the failure, when the failure names itself. - * - * A CLI's error is precise about what is wrong and silent about what to do — - * "unknown variant `max`" is a version mismatch, but only if you already know - * that. These map the handful of failures that have one obvious fix. - */ +/** The one-line remedy for the failures people actually hit. */ function fixFor(id: string, message: string) { const m = message.toLowerCase(); if (m.includes("unknown variant") || m.includes("failed to refresh available models")) { - // The CLI is older than the service it is talking to and cannot parse the - // reply any more. Nothing about the account or the prompt is wrong. return id === "codex-cli" ? "That CLI is out of date — run: npm i -g @openai/codex@latest" : "That CLI is out of date — reinstall it at the latest version"; diff --git a/api/src/main.ts b/api/src/main.ts new file mode 100644 index 0000000..b7ea029 --- /dev/null +++ b/api/src/main.ts @@ -0,0 +1,70 @@ +import "reflect-metadata"; + +import { NestFactory } from "@nestjs/core"; +import type { NestExpressApplication } from "@nestjs/platform-express"; +import cookieParser from "cookie-parser"; + +import { ready } from "@/lib/server/http"; +import { resumeOrphans } from "@/lib/server/services/runs"; + +import { AppModule } from "./app.module"; +import { ErrorsFilter } from "./common/errors.filter"; + +/** + * The Content OS API, as its own process. + * + * Everything the Next.js route handlers used to do, on its own port, reached + * by the browser directly. It shares `lib/server` with the repo root — the + * repos, the services, the run driver — so what changed is who answers HTTP, + * not what happens underneath. + * + * Cross-origin on purpose: the web app is on one origin and this on another, + * so CORS is on for exactly the origins named in WEB_ORIGIN, with credentials, + * and the session cookie is what carries the session across. + */ +async function main() { + const app = await NestFactory.create(AppModule, { + // The seed and the migrations log through here; Nest's own startup lines + // are noise on a dev terminal that already has Next's. + logger: ["error", "warn"], + }); + + app.setGlobalPrefix("api"); + app.use(cookieParser()); + app.useGlobalFilters(new ErrorsFilter()); + + const origins = (process.env.WEB_ORIGIN ?? "http://localhost:3333") + .split(",") + .map((o) => o.trim()) + .filter(Boolean); + app.enableCors({ + origin: origins, + credentials: true, + methods: ["GET", "POST", "PATCH", "PUT", "DELETE", "OPTIONS"], + }); + + // Uploads are streamed by the sources controller; nothing else needs a body + // over a megabyte, and a JSON body that size is a bug being sent. + app.useBodyParser("json", { limit: "1mb" }); + + /* + * Migrations and the seed before the first request, not on it. + * + * `ready()` is the same memoised seed the route handlers call; running it + * here means a deploy that adds a column is never taking traffic against a + * database that has not got it yet. + */ + await ready(); + + // Whatever the last process was writing when it stopped, this one finishes. + const resumed = await resumeOrphans(); + if (resumed.length) { + console.log(`Resuming ${resumed.length} run(s) left mid-write: ${resumed.join(", ")}`); + } + + const port = Number(process.env.PORT ?? 4000); + await app.listen(port); + console.log(`Content OS API on http://localhost:${port}/api`); +} + +void main(); diff --git a/api/src/packs/packs.controller.ts b/api/src/packs/packs.controller.ts new file mode 100644 index 0000000..12e3a2f --- /dev/null +++ b/api/src/packs/packs.controller.ts @@ -0,0 +1,73 @@ +import { + BadRequestException, + Body, + Controller, + Delete, + Get, + HttpCode, + NotFoundException, + Param, + Patch, + Post, +} from "@nestjs/common"; + +import { + createPack, + deletePack, + getPack, + listPacks, + restorePack, + updatePack, + type PackPatch, +} from "@/lib/server/repos/packs"; + +/** + * The template library. + * + * Instructions come back with the list — the builder edits them, so it needs + * them. Any pack can be edited, the shipped ones included; POST on a slug puts + * a shipped one back the way it came. + */ +@Controller("packs") +export class PacksController { + @Get() + list() { + return listPacks(); + } + + @Post() + create(@Body() body: PackPatch) { + if (!body?.name?.trim()) throw new BadRequestException("A pack needs a name"); + return createPack(body); + } + + @Get(":slug") + async get(@Param("slug") slug: string) { + const pack = await getPack(slug); + if (!pack) throw new NotFoundException("No such pack"); + return pack; + } + + @Patch(":slug") + async update(@Param("slug") slug: string, @Body() body: PackPatch) { + const pack = await updatePack(slug, body ?? {}); + if (!pack) throw new NotFoundException("No such pack"); + return pack; + } + + /** Restore the shipped version, section by section. */ + @Post(":slug") + @HttpCode(200) + async restore(@Param("slug") slug: string) { + const pack = await restorePack(slug); + if (!pack) { + throw new NotFoundException("No version of that pack ships with the app"); + } + return pack; + } + + @Delete(":slug") + async remove(@Param("slug") slug: string) { + return { ok: await deletePack(slug) }; + } +} diff --git a/api/src/research/research.controller.ts b/api/src/research/research.controller.ts new file mode 100644 index 0000000..bd78455 --- /dev/null +++ b/api/src/research/research.controller.ts @@ -0,0 +1,23 @@ +import { BadRequestException, Body, Controller, HttpCode, Post } from "@nestjs/common"; + +import { research } from "@/lib/server/services/researcher"; + +/** + * Watch a reel and say what it is about. + * + * Minutes: eight stills go to the model as pictures. Nothing here times out + * on purpose — the service has its own ten-minute ceiling on the model call. + */ +@Controller("research") +export class ResearchController { + @Post() + @HttpCode(200) + run(@Body() body: { sourceId?: string; frames?: string[]; note?: string }) { + if (!body.sourceId) throw new BadRequestException("Fetch a video first"); + return research({ + sourceId: body.sourceId, + frames: body.frames, + note: body.note, + }); + } +} diff --git a/api/src/runs/runs.controller.ts b/api/src/runs/runs.controller.ts new file mode 100644 index 0000000..683162c --- /dev/null +++ b/api/src/runs/runs.controller.ts @@ -0,0 +1,130 @@ +import { + BadRequestException, + Body, + Controller, + Delete, + Get, + HttpCode, + NotFoundException, + Param, + Patch, + Post, + Query, +} from "@nestjs/common"; + +import { + deleteRun, + getRun, + listRuns, + requeueFailed, + setRunDecision, +} from "@/lib/server/repos/runs"; +import { + driveRun, + editSection, + isDriving, + startRun, + writeSection, +} from "@/lib/server/services/runs"; + +/** + * Runs, and the sections written into them. + * + * The driver is `driveRun` in lib/server/services — a loop inside THIS + * process, one section at a time, carrying on whether or not anybody is + * watching. That is the reason the API is its own long-lived service and not + * a serverless function: a run takes minutes and shells out to a local + * model, and both need somewhere to stand. + */ +@Controller("runs") +export class RunsController { + @Get() + list(@Query("workspaceId") workspaceId?: string) { + return listRuns(workspaceId || undefined); + } + + /** Create a run with every section queued. It does not start writing. */ + @Post() + create( + @Body() + body: { + workspaceId?: string; + topicId?: string | null; + sourceId?: string | null; + packSlug?: string; + inputs?: Record; + title?: string; + }, + ) { + return startRun({ + workspaceId: body.workspaceId ?? "", + topicId: body.topicId ?? null, + sourceId: body.sourceId ?? null, + packSlug: body.packSlug ?? "enbn-website-package", + inputs: body.inputs ?? {}, + title: body.title, + }); + } + + @Get(":id") + async get(@Param("id") id: string) { + const run = await getRun(id); + if (!run) throw new NotFoundException("No such run"); + return run; + } + + @Patch(":id") + async decide(@Param("id") id: string, @Body() body: { decision?: string }) { + const d = body.decision; + if (d !== "used" && d !== "ready" && d !== "ignored") { + throw new BadRequestException("decision must be used, ready or ignored"); + } + if (!(await setRunDecision(id, d))) throw new NotFoundException("No such run"); + return { id, decision: d }; + } + + @Delete(":id") + async remove(@Param("id") id: string) { + return { ok: await deleteRun(id) }; + } + + /** + * Write everything that is left, on the server, and return at once. + * + * Pressing this on a run that failed is a retry: the failures go back in + * the queue first, so the loop tries them again rather than skipping them. + */ + @Post(":id/start") + @HttpCode(200) + async start(@Param("id") id: string) { + if (!(await getRun(id))) throw new NotFoundException("No such run"); + const retried = await requeueFailed(id); + return { ...driveRun(id), retried, running: true }; + } + + /** Is this run being written right now, by anyone? */ + @Get(":id/start") + running(@Param("id") id: string) { + return { running: isDriving(id) }; + } + + /** Write one section, now, and answer with the whole run. */ + @Post(":id/sections/:sectionId") + @HttpCode(200) + write(@Param("id") id: string, @Param("sectionId") sectionId: string) { + return writeSection(id, sectionId); + } + + /** Replace a section's text by hand. It counts as finished from then on. */ + @Patch(":id/sections/:sectionId") + edit( + @Param("id") id: string, + @Param("sectionId") sectionId: string, + @Body() body: { content?: unknown }, + ) { + if (typeof body.content !== "string") { + throw new BadRequestException("content must be text"); + } + return editSection(id, sectionId, body.content); + } +} diff --git a/api/src/series/series.controller.ts b/api/src/series/series.controller.ts new file mode 100644 index 0000000..e33e9b4 --- /dev/null +++ b/api/src/series/series.controller.ts @@ -0,0 +1,158 @@ +import { + BadRequestException, + Body, + Controller, + Delete, + Get, + HttpCode, + NotFoundException, + Param, + Patch, + Post, + Query, + Res, +} from "@nestjs/common"; +import type { Response } from "express"; + +import { + addTopics, + createSeries, + deleteSeries, + deleteTopic, + getSeries, + listSeries, + mergeSeries, + updateSeries, + updateTopic, +} from "@/lib/server/repos/series"; +import { FetchError, fetchSource } from "@/lib/server/services/webfetch"; + +type SeriesPatch = Parameters[1]; +type TopicPatch = Parameters[1]; + +/** Shelves: the series under a workspace, and the topics that stand on them. */ +@Controller("series") +export class SeriesController { + @Get() + list(@Query("workspaceId") workspaceId?: string) { + if (!workspaceId) throw new BadRequestException("workspaceId is required"); + return listSeries(workspaceId); + } + + @Post() + create( + @Body() + body: { + workspaceId?: string; + name?: string; + context?: string; + pack?: string; + numbered?: boolean; + partLabel?: string; + }, + ) { + if (!body.workspaceId) throw new BadRequestException("workspaceId is required"); + if (!body.name?.trim()) throw new BadRequestException("A series needs a name"); + // DuplicateName is answered by the errors filter as a 409 with `existing`. + return createSeries({ + workspaceId: body.workspaceId, + name: body.name.trim(), + context: body.context, + pack: body.pack, + numbered: body.numbered, + partLabel: body.partLabel, + }); + } + + @Get(":id") + async get(@Param("id") id: string) { + const s = await getSeries(id); + if (!s) throw new NotFoundException("No such series"); + return s; + } + + @Patch(":id") + async update(@Param("id") id: string, @Body() body: SeriesPatch) { + const s = await updateSeries(id, body ?? {}); + if (!s) throw new NotFoundException("No such series"); + return s; + } + + /** `?keepTopics=1` moves the topics to the Misc shelf instead of deleting them. */ + @Delete(":id") + remove(@Param("id") id: string, @Query("keepTopics") keep?: string) { + return deleteSeries(id, { keepTopics: keep === "1" }); + } + + /** + * Add topics — one or fifty, same call. + * + * 201 when something was added, 200 when everything was already there: the + * body says which, and the status is what the screen reads first. + */ + @Post(":id") + async add( + @Param("id") id: string, + @Body() + body: { topics?: { name: string; context?: string; status?: string }[] }, + @Res({ passthrough: true }) res: Response, + ) { + const topics = (body.topics ?? []).filter((t) => t?.name?.trim()); + if (!topics.length) throw new BadRequestException("Nothing to add"); + const result = await addTopics(id, topics); + res.status(result.added.length ? 201 : 200); + return result; + } + + @Post(":id/merge") + @HttpCode(200) + merge(@Param("id") id: string, @Body() body: { into?: string }) { + if (!body.into) { + throw new BadRequestException("Which series should it merge into?"); + } + return mergeSeries(id, body.into); + } + + /** Read a link or a feed into the shelf's brief. */ + @Post(":id/source") + @HttpCode(200) + async source( + @Param("id") id: string, + @Body() body: { url?: string; kind?: string }, + ) { + if (!(await getSeries(id))) throw new NotFoundException("No such series"); + try { + const source = await fetchSource(String(body.url ?? "")); + const briefFrom = source.kind === "feed" ? "feed" : "link"; + return await updateSeries(id, { source, briefFrom }); + } catch (e) { + if (e instanceof FetchError) { + throw new BadRequestException(e.message); + } + throw e; + } + } + + @Delete(":id/source") + async clearSource(@Param("id") id: string) { + const s = await updateSeries(id, { source: null, briefFrom: "typed" }); + if (!s) throw new NotFoundException("No such series"); + return s; + } +} + +/** One topic: rename it, move it, decide about it, or take it off the shelf. */ +@Controller("topics") +export class TopicsController { + @Patch(":id") + async update(@Param("id") id: string, @Body() body: TopicPatch) { + const t = await updateTopic(id, body ?? {}); + if (!t) throw new NotFoundException("No such topic"); + return t; + } + + @Delete(":id") + async remove(@Param("id") id: string) { + return { ok: await deleteTopic(id) }; + } +} diff --git a/api/src/settings/settings.controller.ts b/api/src/settings/settings.controller.ts new file mode 100644 index 0000000..a3d3d16 --- /dev/null +++ b/api/src/settings/settings.controller.ts @@ -0,0 +1,58 @@ +import { + BadRequestException, + Body, + Controller, + Delete, + Get, + Patch, + Post, + Query, +} from "@nestjs/common"; + +import { + clearSecret, + getSettings, + listSecrets, + setSecret, + setSettings, + type Settings, +} from "@/lib/server/repos/settings"; + +/** + * Preferences, and the API keys beside them. + * + * Keys go in and never come back out: `listSecrets` answers with which ids + * are stored, not their values. The settings table encrypts them with + * CONTENTOS_SECRET — see the repo for why a dump is not a list of live keys. + */ +@Controller("settings") +export class SettingsController { + @Get() + get() { + return getSettings(); + } + + @Patch() + update(@Body() body: Partial) { + return setSettings(body ?? {}); + } + + @Get("keys") + keys() { + return listSecrets(); + } + + @Post("keys") + async setKey(@Body() body: { id?: string; value?: string }) { + if (!body.id) throw new BadRequestException("Which key?"); + await setSecret(body.id, body.value ?? ""); + return listSecrets(); + } + + @Delete("keys") + async clearKey(@Query("id") id?: string) { + if (!id) throw new BadRequestException("Which key?"); + await clearSecret(id); + return listSecrets(); + } +} diff --git a/api/src/sources/sources.controller.ts b/api/src/sources/sources.controller.ts new file mode 100644 index 0000000..ed67a4f --- /dev/null +++ b/api/src/sources/sources.controller.ts @@ -0,0 +1,160 @@ +import { + BadRequestException, + Body, + Controller, + Delete, + Get, + HttpCode, + NotFoundException, + Param, + PayloadTooLargeException, + Post, + Query, + Req, + Res, +} from "@nestjs/common"; +import busboy from "busboy"; +import type { Request, Response } from "express"; + +import { getSource, listSources } from "@/lib/server/repos/sources"; +import { + MAX_UPLOAD_BYTES, + addFrameAt, + frameFile, + ingest, + ingestFile, + removeSource, +} from "@/lib/server/services/ingest"; + +/** + * Source videos: fetched from a link, or uploaded from a machine. + * + * Slow on purpose. A fetch holds while yt-dlp downloads, ffmpeg cuts stills + * and a transcriber runs — minutes, not seconds — and the browser waits with + * a spinner on it. Express has no request timeout of its own, so there is + * nothing here to raise; the Next handlers needed `maxDuration` and this does + * not. + */ +@Controller("sources") +export class SourcesController { + @Get() + list(@Query("workspaceId") workspaceId?: string) { + return listSources(workspaceId || undefined); + } + + /** Fetch a reel by link, or hand back the one already fetched. */ + @Post() + fetch( + @Body() body: { url?: string; workspaceId?: string | null; refresh?: boolean }, + ) { + if (!body.url?.trim()) throw new BadRequestException("Paste a link first"); + return ingest({ + url: body.url, + workspaceId: body.workspaceId ?? null, + refresh: body.refresh, + }); + } + + /** + * A video off somebody's machine, streamed to disk as it arrives. + * + * Read straight off the request with busboy rather than through a body + * parser: a parser buffers, and the whole point of the ingest's streaming + * path is that a 400MB recording never sits in memory. The declared size is + * refused up front as a courtesy; the ingest counts the bytes itself. + */ + @Post("upload") + upload(@Req() req: Request) { + const declared = Number(req.headers["content-length"] ?? 0); + if (declared > MAX_UPLOAD_BYTES) { + throw new PayloadTooLargeException( + `That file is over ${Math.round(MAX_UPLOAD_BYTES / 1048576)}MB — trim it or export it smaller.`, + ); + } + + return new Promise((resolve, reject) => { + const bb = busboy({ headers: req.headers, limits: { files: 1 } }); + let workspaceId: string | null = null; + let handled = false; + + bb.on("field", (name, value) => { + if (name === "workspaceId" && value) workspaceId = value; + }); + + bb.on("file", (name, file, info) => { + if (name !== "file") { + file.resume(); + return; + } + handled = true; + // Node's Readable, as the Web stream the ingest takes: the ingest is + // shared with code that gets a fetch() body, so it speaks that shape. + const web = ReadableStreamFromNode(file); + ingestFile({ filename: info.filename, stream: web, workspaceId }) + .then(resolve) + .catch(reject); + }); + + bb.on("error", reject); + bb.on("finish", () => { + if (!handled) reject(new BadRequestException("Choose a video file")); + }); + + req.pipe(bb); + }); + } + + @Get(":id") + async get(@Param("id") id: string) { + const source = await getSource(id); + if (!source) throw new NotFoundException("No such source"); + return source; + } + + /** The row and the download go together. */ + @Delete(":id") + async remove(@Param("id") id: string) { + return { ok: await removeSource(id) }; + } + + /** One more still, at a moment somebody asked for. */ + @Post(":id/frames") + @HttpCode(201) + addFrame(@Param("id") id: string, @Body() body: { at?: number }) { + const at = Number(body.at); + if (!Number.isFinite(at) || at < 0) { + throw new BadRequestException("Give a time in seconds"); + } + return addFrameAt(id, at); + } + + /** The frame's bytes. Immutable: a frame at a second never changes. */ + @Get(":id/frames/:file") + async frame( + @Param("id") id: string, + @Param("file") file: string, + @Res() res: Response, + ) { + const bytes = await frameFile(id, file); + if (!bytes) throw new NotFoundException("No such frame"); + res + .set({ + "content-type": "image/jpeg", + "cache-control": "private, max-age=31536000, immutable", + }) + .send(bytes); + } +} + +/** A Node readable as a Web ReadableStream, without the whole of node:stream/web's types. */ +function ReadableStreamFromNode( + file: NodeJS.ReadableStream, +): ReadableStream { + return new ReadableStream({ + start(controller) { + file.on("data", (chunk: Buffer) => controller.enqueue(new Uint8Array(chunk))); + file.on("end", () => controller.close()); + file.on("error", (e) => controller.error(e)); + }, + }); +} diff --git a/api/src/tools/tools.controller.ts b/api/src/tools/tools.controller.ts new file mode 100644 index 0000000..7b44bb7 --- /dev/null +++ b/api/src/tools/tools.controller.ts @@ -0,0 +1,47 @@ +import { + Body, + Controller, + Get, + NotFoundException, + Param, + Patch, + Query, +} from "@nestjs/common"; + +import { + getTool, + listTools, + toolsFor, + updateTool, + type ToolPatch, +} from "@/lib/server/repos/tools"; + +/** + * The tool bench. + * + * `?workspace=` is one workspace's bench — what it is allowed to see. + * Without it you get every tool and its assignment, which is what the screen + * that manages them needs and nothing else should be reading. + */ +@Controller("tools") +export class ToolsController { + @Get() + list(@Query("workspace") workspace?: string) { + return workspace ? toolsFor(workspace) : listTools(); + } + + @Get(":slug") + async get(@Param("slug") slug: string) { + const tool = await getTool(slug); + if (!tool) throw new NotFoundException("No such tool"); + return tool; + } + + /** Rename it, recategorise it, switch it off, or say where it appears. */ + @Patch(":slug") + async update(@Param("slug") slug: string, @Body() body: ToolPatch) { + const tool = await updateTool(slug, body ?? {}); + if (!tool) throw new NotFoundException("No such tool"); + return tool; + } +} diff --git a/api/src/workspaces/workspaces.controller.ts b/api/src/workspaces/workspaces.controller.ts new file mode 100644 index 0000000..37c57c9 --- /dev/null +++ b/api/src/workspaces/workspaces.controller.ts @@ -0,0 +1,64 @@ +import { + Body, + ConflictException, + Controller, + Delete, + Get, + NotFoundException, + Param, + Patch, + Post, +} from "@nestjs/common"; + +import { listSeries } from "@/lib/server/repos/series"; +import { + createWorkspace, + deleteWorkspace, + getWorkspace, + listWorkspaces, + updateWorkspace, +} from "@/lib/server/repos/workspaces"; + +type Patch = Parameters[1]; +type Create = Parameters[0]; + +/** Workspaces, each answered with its shelves — the shape the store hydrates from. */ +@Controller("workspaces") +export class WorkspacesController { + @Get() + async list() { + const list = await listWorkspaces(); + return Promise.all( + list.map(async (w) => ({ ...w, series: await listSeries(w.id) })), + ); + } + + @Post() + async create(@Body() body: Create) { + return { ...(await createWorkspace(body)), series: [] }; + } + + @Get(":id") + async get(@Param("id") id: string) { + const ws = await getWorkspace(id); + if (!ws) throw new NotFoundException("No such workspace"); + return { ...ws, series: await listSeries(id) }; + } + + @Patch(":id") + async update(@Param("id") id: string, @Body() body: Patch) { + const ws = await updateWorkspace(id, body ?? {}); + if (!ws) throw new NotFoundException("No such workspace"); + return { ...ws, series: await listSeries(id) }; + } + + @Delete(":id") + async remove(@Param("id") id: string) { + if ((await listWorkspaces()).length <= 1) { + throw new ConflictException( + "This is the only workspace — there would be nothing left", + ); + } + return { ok: await deleteWorkspace(id) }; + } +} diff --git a/api/tsconfig.json b/api/tsconfig.json new file mode 100644 index 0000000..f8f2ebc --- /dev/null +++ b/api/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es2022", + "lib": ["es2023"], + "types": ["node"], + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "moduleResolution": "node", + "resolveJsonModule": true, + "sourceMap": true, + "baseUrl": "..", + "paths": { "@/*": ["./*"] }, + "rootDir": "..", + "outDir": "dist" + }, + "include": ["src/**/*.ts"] +} diff --git a/app/api/auth/login/route.ts b/app/api/auth/login/route.ts deleted file mode 100644 index 4a6922d..0000000 --- a/app/api/auth/login/route.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { cookies } from "next/headers"; - -import { - authenticate, - cookieOptions, - SESSION_COOKIE, - startSession, - sweepSessions, -} from "@/lib/server/auth"; -import { caught, ok, ready } from "@/lib/server/http"; - -export async function POST(request: Request) { - try { - await ready(); - const body = (await request.json().catch(() => ({}))) as { - email?: string; - password?: string; - }; - - const user = await authenticate(body.email ?? "", body.password ?? ""); - void sweepSessions(); - - const sid = await startSession( - user.id, - request.headers.get("user-agent") ?? "", - ); - (await cookies()).set(SESSION_COOKIE, sid, cookieOptions()); - return ok(user); - } catch (e) { - return caught(e); - } -} diff --git a/app/api/auth/logout/route.ts b/app/api/auth/logout/route.ts deleted file mode 100644 index fbd986d..0000000 --- a/app/api/auth/logout/route.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { cookies } from "next/headers"; - -import { - currentSessionId, - endSession, - SESSION_COOKIE, -} from "@/lib/server/auth"; -import { caught, ok, ready } from "@/lib/server/http"; - -export async function POST() { - try { - await ready(); - // The row goes as well as the cookie: clearing only the cookie leaves a - // working session id behind for anything that kept a copy. - await endSession(await currentSessionId()); - (await cookies()).delete(SESSION_COOKIE); - return ok({ ok: true }); - } catch (e) { - return caught(e); - } -} diff --git a/app/api/auth/me/route.ts b/app/api/auth/me/route.ts deleted file mode 100644 index 199626b..0000000 --- a/app/api/auth/me/route.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { currentUser, signupOpen } from "@/lib/server/auth"; -import { caught, ok, ready } from "@/lib/server/http"; - -/** Who is signed in, and whether anyone can sign up. Never 401s — it is the question. */ -export async function GET() { - try { - await ready(); - return ok({ user: await currentUser(), signupOpen: await signupOpen() }); - } catch (e) { - return caught(e); - } -} diff --git a/app/api/auth/password/route.ts b/app/api/auth/password/route.ts deleted file mode 100644 index 67a3c93..0000000 --- a/app/api/auth/password/route.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { cookies } from "next/headers"; - -import { - cookieOptions, - requireUser, - SESSION_COOKIE, - startSession, - updatePassword, -} from "@/lib/server/auth"; -import { caught, ok, ready } from "@/lib/server/http"; - -export async function POST(request: Request) { - try { - await ready(); - const user = await requireUser(); - const body = (await request.json().catch(() => ({}))) as { - current?: string; - next?: string; - }; - - await updatePassword(user.id, body.current ?? "", body.next ?? ""); - - // Every session was dropped, including this one. A fresh cookie so the - // person who just changed their password is not logged out by doing it. - const sid = await startSession( - user.id, - request.headers.get("user-agent") ?? "", - ); - (await cookies()).set(SESSION_COOKIE, sid, cookieOptions()); - return ok({ ok: true }); - } catch (e) { - return caught(e); - } -} diff --git a/app/api/auth/sessions/route.ts b/app/api/auth/sessions/route.ts deleted file mode 100644 index a060c57..0000000 --- a/app/api/auth/sessions/route.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { - currentSessionId, - endOtherSessions, - listSessions, - requireUser, -} from "@/lib/server/auth"; -import { caught, ok, ready } from "@/lib/server/http"; - -/** Where this account is signed in. The one you are using is marked. */ -export async function GET() { - try { - await ready(); - const user = await requireUser(); - return ok(await listSessions(user.id, await currentSessionId())); - } catch (e) { - return caught(e); - } -} - -/** Signs out everywhere except here. */ -export async function DELETE() { - try { - await ready(); - const user = await requireUser(); - const ended = await endOtherSessions(user.id, await currentSessionId()); - return ok({ ended }); - } catch (e) { - return caught(e); - } -} diff --git a/app/api/auth/signup/route.ts b/app/api/auth/signup/route.ts deleted file mode 100644 index 351288b..0000000 --- a/app/api/auth/signup/route.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { cookies } from "next/headers"; - -import { - cookieOptions, - createUser, - SESSION_COOKIE, - signupOpen, - startSession, -} from "@/lib/server/auth"; -import { caught, ok, ready } from "@/lib/server/http"; - -/** Whether the console still has room for an owner. The form asks before it renders. */ -export async function GET() { - try { - await ready(); - return ok({ open: await signupOpen() }); - } catch (e) { - return caught(e); - } -} - -export async function POST(request: Request) { - try { - await ready(); - const body = (await request.json().catch(() => ({}))) as { - email?: string; - password?: string; - name?: string; - invite?: string; - }; - - const user = await createUser({ - email: body.email ?? "", - password: body.password ?? "", - name: body.name, - invite: body.invite, - }); - - // Signed in immediately. Making someone type the password they just chose - // into a second form proves nothing and loses people. - const sid = await startSession( - user.id, - request.headers.get("user-agent") ?? "", - ); - (await cookies()).set(SESSION_COOKIE, sid, cookieOptions()); - return ok(user, 201); - } catch (e) { - return caught(e); - } -} diff --git a/app/api/integrations/route.ts b/app/api/integrations/route.ts deleted file mode 100644 index 026a5f4..0000000 --- a/app/api/integrations/route.ts +++ /dev/null @@ -1,72 +0,0 @@ -import { requireUser } from "@/lib/server/auth"; -import { brainStatuses } from "@/lib/server/brains"; -import { toolStatuses } from "@/lib/server/tools"; -import { getSettings, listSecrets, setSettings } from "@/lib/server/repos/settings"; -import { caught, fail, ok, ready } from "@/lib/server/http"; - -/** A section of a run reaches for tools; probing five processes can be slow. */ -export const maxDuration = 60; - -/** - * What this machine can actually do. - * - * Every field is the result of running something or reading a row — the page - * that renders this used to hold a set of ids in memory and call it a - * connection, so it would cheerfully report yt-dlp as connected on a machine - * that had never had it. - */ -export async function GET(request: Request) { - try { - await ready(); - await requireUser(); - // ?recheck=1 skips the one-minute probe cache, for the button that says - // "I have just installed it". - const recheck = new URL(request.url).searchParams.get("recheck") === "1"; - - const [brains, tools, settings, keys] = await Promise.all([ - recheck ? toolStatuses(true).then(brainStatuses) : brainStatuses(), - toolStatuses(recheck), - getSettings(), - listSecrets(), - ]); - - /* - * The model CLIs are probed with the rest, but they belong to the Models - * section — listing `claude` under Local tools as well would offer a - * switch that turns off the thing writing every section. - */ - const MEDIA = ["yt-dlp", "ffmpeg", "ffprobe", "whisper"]; - return ok({ - brains, - tools: tools.filter((t) => MEDIA.includes(t.id)), - settings, - keys: Object.keys(keys), - }); - } catch (e) { - return caught(e); - } -} - -export async function PATCH(request: Request) { - try { - await ready(); - await requireUser(); - const body = (await request.json().catch(() => ({}))) as { - brain?: string; - enabled?: string[]; - }; - - if (body.brain) { - // Refused rather than accepted-and-broken: a brain that cannot be - // reached fails at the next section, several minutes and one confusing - // error message later. - const status = (await brainStatuses()).find((b) => b.id === body.brain); - if (!status) return fail(`No model called "${body.brain}"`); - if (!status.available) return fail(status.reason, 409); - } - - return ok(await setSettings(body)); - } catch (e) { - return caught(e); - } -} diff --git a/app/api/invites/[token]/route.ts b/app/api/invites/[token]/route.ts deleted file mode 100644 index 8c188ec..0000000 --- a/app/api/invites/[token]/route.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { requireUser, revokeInvite } from "@/lib/server/auth"; -import { caught, fail, ok, ready } from "@/lib/server/http"; - -/** Take a link back. Only an unused one can go — a spent invite is history. */ -export async function DELETE( - _r: Request, - { params }: { params: Promise<{ token: string }> }, -) { - try { - await ready(); - await requireUser(); - const { token } = await params; - const gone = await revokeInvite(token); - return gone ? ok({ ok: true }) : fail("That invite is already used", 409); - } catch (e) { - return caught(e); - } -} diff --git a/app/api/invites/route.ts b/app/api/invites/route.ts deleted file mode 100644 index 6082d69..0000000 --- a/app/api/invites/route.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { createInvite, listInvites, requireUser } from "@/lib/server/auth"; -import { caught, ok, ready } from "@/lib/server/http"; - -/** - * The links that let anyone else in. - * - * Any signed-in person can make one. There is no admin tier in this console — - * everyone who is here can already read and change everything, so pretending - * invites are privileged would be a lock on a door with no walls. What stops - * a stranger is that they need a link at all. - */ -export async function GET() { - try { - await ready(); - await requireUser(); - return ok(await listInvites()); - } catch (e) { - return caught(e); - } -} - -export async function POST(request: Request) { - try { - await ready(); - const user = await requireUser(); - const body = (await request.json().catch(() => ({}))) as { - email?: string; - note?: string; - days?: number; - }; - return ok( - await createInvite({ - createdBy: user.id, - email: body.email, - note: body.note, - days: body.days, - }), - 201, - ); - } catch (e) { - return caught(e); - } -} diff --git a/app/api/packs/[slug]/route.ts b/app/api/packs/[slug]/route.ts deleted file mode 100644 index 1598810..0000000 --- a/app/api/packs/[slug]/route.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { - deletePack, - getPack, - restorePack, - updatePack, -} from "@/lib/server/repos/packs"; -import { caught, fail, ok, ready } from "@/lib/server/http"; - -export async function GET( - _r: Request, - { params }: { params: Promise<{ slug: string }> }, -) { - try { - await ready(); - const { slug } = await params; - const pack = await getPack(slug); - return pack ? ok(pack) : fail("No such pack", 404); - } catch (e) { - return caught(e); - } -} - -/** - * Edit a pack — any pack. - * - * The shipped ones used to be refused here, on the reasoning that a tuned - * prompt belongs with the code that reads it. That was true of a pack you - * could only read; it is the wrong trade for a library you are meant to build - * on. They are seeded into the table as ordinary rows now, and POST below puts - * one back the way it shipped if an edit goes wrong. - */ -export async function PATCH( - request: Request, - { params }: { params: Promise<{ slug: string }> }, -) { - try { - await ready(); - const { slug } = await params; - const pack = await updatePack(slug, await request.json().catch(() => ({}))); - return pack ? ok(pack) : fail("No such pack", 404); - } catch (e) { - return caught(e); - } -} - -/** Restore the shipped version of a pack, section by section. */ -export async function POST( - _r: Request, - { params }: { params: Promise<{ slug: string }> }, -) { - try { - await ready(); - const { slug } = await params; - const pack = await restorePack(slug); - return pack - ? ok(pack) - : fail("No version of that pack ships with the app", 404); - } catch (e) { - return caught(e); - } -} - -export async function DELETE( - _r: Request, - { params }: { params: Promise<{ slug: string }> }, -) { - try { - await ready(); - const { slug } = await params; - return ok({ ok: await deletePack(slug) }); - } catch (e) { - return caught(e); - } -} diff --git a/app/api/packs/route.ts b/app/api/packs/route.ts deleted file mode 100644 index 5829287..0000000 --- a/app/api/packs/route.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { createPack, listPacks } from "@/lib/server/repos/packs"; -import { caught, fail, ok, ready } from "@/lib/server/http"; - -/** - * The pack library. - * - * Instructions come back with it — the builder edits them, so it needs them. - * The list is small and read once per screen, which is a different trade from - * the run endpoints and the reason the earlier version stripped them out. - */ -export async function GET() { - try { - await ready(); - return ok(await listPacks()); - } catch (e) { - return caught(e); - } -} - -export async function POST(request: Request) { - try { - await ready(); - const body = await request.json().catch(() => ({})); - if (!body?.name?.trim()) return fail("A pack needs a name"); - return ok(await createPack(body), 201); - } catch (e) { - return caught(e); - } -} diff --git a/app/api/research/route.ts b/app/api/research/route.ts deleted file mode 100644 index 708e0a5..0000000 --- a/app/api/research/route.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { requireUser } from "@/lib/server/auth"; -import { research } from "@/lib/server/services/researcher"; -import { caught, fail, ok, ready } from "@/lib/server/http"; - -/** Reading eight stills with a model is minutes, not seconds. */ -export const maxDuration = 800; - -export async function POST(request: Request) { - try { - await ready(); - await requireUser(); - const body = (await request.json().catch(() => ({}))) as { - sourceId?: string; - frames?: string[]; - note?: string; - }; - if (!body.sourceId) return fail("Fetch a video first"); - return ok( - await research({ - sourceId: body.sourceId, - frames: body.frames, - note: body.note, - }), - ); - } catch (e) { - return caught(e); - } -} diff --git a/app/api/runs/[id]/route.ts b/app/api/runs/[id]/route.ts deleted file mode 100644 index d66d7a4..0000000 --- a/app/api/runs/[id]/route.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { deleteRun, getRun, setRunDecision } from "@/lib/server/repos/runs"; -import { caught, fail, ok, ready } from "@/lib/server/http"; - -export async function GET( - _r: Request, - { params }: { params: Promise<{ id: string }> }, -) { - try { - await ready(); - const { id } = await params; - const run = await getRun(id); - return run ? ok(run) : fail("No such run", 404); - } catch (e) { - return caught(e); - } -} - -/** - * Mark a run used, ready or ignored. - * - * Only the decision is patchable. A run's inputs and its sections are the - * record of what happened, and letting a PATCH rewrite them would make that - * record a guess. - */ -export async function PATCH( - request: Request, - { params }: { params: Promise<{ id: string }> }, -) { - try { - await ready(); - const { id } = await params; - const body = (await request.json().catch(() => ({}))) as { - decision?: string; - }; - if ( - body.decision !== "used" && - body.decision !== "ready" && - body.decision !== "ignored" - ) { - return fail("decision must be used, ready or ignored", 400); - } - return (await setRunDecision(id, body.decision)) - ? ok({ id, decision: body.decision }) - : fail("No such run", 404); - } catch (e) { - return caught(e); - } -} - -export async function DELETE( - _r: Request, - { params }: { params: Promise<{ id: string }> }, -) { - try { - await ready(); - const { id } = await params; - return ok({ ok: await deleteRun(id) }); - } catch (e) { - return caught(e); - } -} diff --git a/app/api/runs/[id]/sections/[sectionId]/route.ts b/app/api/runs/[id]/sections/[sectionId]/route.ts deleted file mode 100644 index 9e3be15..0000000 --- a/app/api/runs/[id]/sections/[sectionId]/route.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { editSection, writeSection } from "@/lib/server/services/runs"; -import { caught, fail, ok, ready } from "@/lib/server/http"; - -/** Research reads pages and a script thinks; the default would cut both off. */ -export const maxDuration = 800; - -export async function POST( - _r: Request, - { params }: { params: Promise<{ id: string; sectionId: string }> }, -) { - try { - await ready(); - const { id, sectionId } = await params; - return ok(await writeSection(id, sectionId)); - } catch (e) { - return caught(e); - } -} - -/** - * Save what a person typed into this section. - * - * PATCH rather than POST, which on this route means "run it": one asks the - * model for new words and costs money, the other keeps the words already on - * screen. They must not be the same verb. - */ -export async function PATCH( - request: Request, - { params }: { params: Promise<{ id: string; sectionId: string }> }, -) { - try { - await ready(); - const { id, sectionId } = await params; - const body = (await request.json().catch(() => ({}))) as { - content?: unknown; - }; - if (typeof body.content !== "string") { - return fail("content must be text", 400); - } - return ok(await editSection(id, sectionId, body.content)); - } catch (e) { - return caught(e); - } -} diff --git a/app/api/runs/[id]/start/route.ts b/app/api/runs/[id]/start/route.ts deleted file mode 100644 index 4c29684..0000000 --- a/app/api/runs/[id]/start/route.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { driveRun, isDriving } from "@/lib/server/services/runs"; -import { getRun, requeueFailed } from "@/lib/server/repos/runs"; -import { caught, fail, ok, ready } from "@/lib/server/http"; - -/** - * Write the whole run, without being asked again. - * - * Answers as soon as the loop is started rather than when it finishes: a run - * is twelve model calls and several minutes, which no request should be held - * open for. The page follows along by reading the run. - * - * Failed sections go back in the queue first, which is what makes this Retry - * as well as Run. The drive deliberately skips a section that failed — looping - * on the one thing that does not work would spend the model's whole afternoon - * on it — so without this a second press finished instantly having written - * nothing, and the Retry button on a failed row did nothing at all. - */ -export async function POST( - _r: Request, - { params }: { params: Promise<{ id: string }> }, -) { - try { - await ready(); - const { id } = await params; - const run = await getRun(id); - if (!run) return fail("No such run", 404); - const retried = await requeueFailed(id); - return ok({ ...driveRun(id), retried, running: true }); - } catch (e) { - return caught(e); - } -} - -/** Whether it is being written right now — for a page that just loaded. */ -export async function GET( - _r: Request, - { params }: { params: Promise<{ id: string }> }, -) { - try { - await ready(); - const { id } = await params; - return ok({ running: isDriving(id) }); - } catch (e) { - return caught(e); - } -} diff --git a/app/api/runs/route.ts b/app/api/runs/route.ts deleted file mode 100644 index dc14cfc..0000000 --- a/app/api/runs/route.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { listRuns } from "@/lib/server/repos/runs"; -import { startRun } from "@/lib/server/services/runs"; -import { caught, ok, ready } from "@/lib/server/http"; - -export async function GET(request: Request) { - try { - await ready(); - const workspaceId = new URL(request.url).searchParams.get("workspaceId"); - return ok(await listRuns(workspaceId ?? undefined)); - } catch (e) { - return caught(e); - } -} - -/** - * Start a run. - * - * Creates it with every section queued and returns immediately — it does not - * generate. The client drives the sections one call at a time, so progress is - * visible while it happens rather than arriving as one long silence. - */ -export async function POST(request: Request) { - try { - await ready(); - const body = (await request.json().catch(() => ({}))) as { - workspaceId?: string; - topicId?: string | null; - sourceId?: string | null; - packSlug?: string; - inputs?: Record; - title?: string; - }; - return ok( - await startRun({ - workspaceId: body.workspaceId ?? "", - topicId: body.topicId ?? null, - sourceId: body.sourceId ?? null, - packSlug: body.packSlug ?? "enbn-website-package", - inputs: body.inputs ?? {}, - title: body.title, - }), - 201, - ); - } catch (e) { - return caught(e); - } -} diff --git a/app/api/series/[id]/merge/route.ts b/app/api/series/[id]/merge/route.ts deleted file mode 100644 index b5e1e8d..0000000 --- a/app/api/series/[id]/merge/route.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { mergeSeries } from "@/lib/server/repos/series"; -import { caught, fail, ok, ready } from "@/lib/server/http"; - -/** - * Fold this series into another one. - * - * A POST rather than a PATCH on the target: it deletes one row, moves every - * topic on it and renumbers them, which is a job being asked for rather than - * a field being set. - */ -export async function POST( - request: Request, - { params }: { params: Promise<{ id: string }> }, -) { - try { - await ready(); - const { id } = await params; - const body = (await request.json().catch(() => ({}))) as { into?: string }; - if (!body.into) return fail("Which series should it merge into?"); - return ok(await mergeSeries(id, body.into)); - } catch (e) { - return caught(e); - } -} diff --git a/app/api/series/[id]/route.ts b/app/api/series/[id]/route.ts deleted file mode 100644 index 6e07c45..0000000 --- a/app/api/series/[id]/route.ts +++ /dev/null @@ -1,98 +0,0 @@ -import { - DuplicateName, - addTopics, - deleteSeries, - getSeries, - updateSeries, -} from "@/lib/server/repos/series"; -import { caught, fail, ok, ready } from "@/lib/server/http"; - -export async function GET( - _r: Request, - { params }: { params: Promise<{ id: string }> }, -) { - try { - await ready(); - const { id } = await params; - const s = await getSeries(id); - return s ? ok(s) : fail("No such series", 404); - } catch (e) { - return caught(e); - } -} - -export async function PATCH( - request: Request, - { params }: { params: Promise<{ id: string }> }, -) { - try { - await ready(); - const { id } = await params; - const s = await updateSeries(id, await request.json().catch(() => ({}))); - return s ? ok(s) : fail("No such series", 404); - } catch (e) { - if (e instanceof DuplicateName) { - return Response.json( - { error: e.message, existing: e.existing }, - { status: 409 }, - ); - } - return caught(e); - } -} - -/** - * Delete a series, with or without what is standing on it. - * - * `?keepTopics=1` moves its topics to the holding shelf first, so the shelf - * can go without taking a dozen ideas with it. Without the flag the topics go - * too — which is what a delete usually means, and why it is the one you have - * to ask for. - */ -export async function DELETE( - request: Request, - { params }: { params: Promise<{ id: string }> }, -) { - try { - await ready(); - const { id } = await params; - const keepTopics = - new URL(request.url).searchParams.get("keepTopics") === "1"; - return ok(await deleteSeries(id, { keepTopics })); - } catch (e) { - return caught(e); - } -} - -/** - * Add topics to a series. - * - * One endpoint for one topic and for fifty, because the part numbering is the - * same problem either way and splitting it would mean two places that assign - * numbers. - */ -export async function POST( - request: Request, - { params }: { params: Promise<{ id: string }> }, -) { - try { - await ready(); - const { id } = await params; - const body = (await request.json().catch(() => ({}))) as { - topics?: { name: string; context?: string; status?: string }[]; - }; - const topics = (body.topics ?? []).filter((t) => t?.name?.trim()); - if (!topics.length) return fail("Nothing to add"); - - /* - * `{ added, skipped }` rather than the rows alone: a request for five - * topics that produces two is not an error, and it is not a success the - * caller can report honestly without being told which three were already - * covered and where. - */ - const result = await addTopics(id, topics); - return ok(result, result.added.length ? 201 : 200); - } catch (e) { - return caught(e); - } -} diff --git a/app/api/series/[id]/source/route.ts b/app/api/series/[id]/source/route.ts deleted file mode 100644 index eb004c4..0000000 --- a/app/api/series/[id]/source/route.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { getSeries, updateSeries } from "@/lib/server/repos/series"; -import { FetchError, fetchSource } from "@/lib/server/services/webfetch"; -import { caught, fail, ok, ready } from "@/lib/server/http"; - -/** Reading a site is a network round trip, and some of them are slow. */ -export const maxDuration = 60; - -/** - * Read a page or a feed, and hang it on this series. - * - * The fetch and the save are one request rather than two: a source that was - * saved but never read, or read but never saved, is a state the UI would have - * to explain, and there is nothing useful a person could do about either. - */ -export async function POST( - request: Request, - { params }: { params: Promise<{ id: string }> }, -) { - try { - await ready(); - const { id } = await params; - if (!(await getSeries(id))) return fail("No such series", 404); - - const body = (await request.json().catch(() => ({}))) as { - url?: string; - kind?: string; - }; - const source = await fetchSource(String(body.url ?? "")); - - /* - * What the tab said, unless the site disagreed. - * - * Paste a feed into "From a link" and it is still a feed — refusing it - * would be the app correcting you about something it can plainly see. - */ - const briefFrom = source.kind === "feed" ? "feed" : "link"; - return ok(await updateSeries(id, { source, briefFrom })); - } catch (e) { - if (e instanceof FetchError) return fail(e.message, e.status); - return caught(e); - } -} - -/** Detach the source and go back to whatever was typed. */ -export async function DELETE( - _r: Request, - { params }: { params: Promise<{ id: string }> }, -) { - try { - await ready(); - const { id } = await params; - const s = await updateSeries(id, { source: null, briefFrom: "typed" }); - return s ? ok(s) : fail("No such series", 404); - } catch (e) { - return caught(e); - } -} diff --git a/app/api/series/route.ts b/app/api/series/route.ts deleted file mode 100644 index 72ec8b8..0000000 --- a/app/api/series/route.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { - DuplicateName, - createSeries, - listSeries, -} from "@/lib/server/repos/series"; -import { caught, fail, ok, ready } from "@/lib/server/http"; - -export async function GET(request: Request) { - try { - await ready(); - const workspaceId = new URL(request.url).searchParams.get("workspaceId"); - if (!workspaceId) return fail("workspaceId is required"); - return ok(await listSeries(workspaceId)); - } catch (e) { - return caught(e); - } -} - -export async function POST(request: Request) { - try { - await ready(); - const body = (await request.json().catch(() => ({}))) as { - workspaceId?: string; - name?: string; - context?: string; - pack?: string; - numbered?: boolean; - partLabel?: string; - }; - if (!body.workspaceId) return fail("workspaceId is required"); - if (!body.name?.trim()) return fail("A series needs a name"); - return ok( - await createSeries({ - workspaceId: body.workspaceId, - name: body.name.trim(), - context: body.context, - pack: body.pack, - numbered: body.numbered, - partLabel: body.partLabel, - }), - 201, - ); - } catch (e) { - // Not just a 409: the screen offers to open the shelf that has the name, - // which it can only do if it is told which one that is. - if (e instanceof DuplicateName) { - return Response.json( - { error: e.message, existing: e.existing }, - { status: 409 }, - ); - } - return caught(e); - } -} diff --git a/app/api/settings/keys/route.ts b/app/api/settings/keys/route.ts deleted file mode 100644 index bd0e339..0000000 --- a/app/api/settings/keys/route.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { requireUser } from "@/lib/server/auth"; -import { - clearSecret, - listSecrets, - setSecret, -} from "@/lib/server/repos/settings"; -import { caught, fail, ok, ready } from "@/lib/server/http"; - -/** - * Service keys. - * - * Masked on the way out, always. The server is the only thing that ever needs - * the real value, and a key that can be read back out of an API is a key that - * leaks through any XSS this app ever has. - */ -export async function GET() { - try { - await ready(); - await requireUser(); - return ok(await listSecrets()); - } catch (e) { - return caught(e); - } -} - -export async function POST(request: Request) { - try { - await ready(); - await requireUser(); - const body = (await request.json().catch(() => ({}))) as { - id?: string; - value?: string; - }; - if (!body.id) return fail("Which key?"); - await setSecret(body.id, body.value ?? ""); - return ok(await listSecrets()); - } catch (e) { - return caught(e); - } -} - -export async function DELETE(request: Request) { - try { - await ready(); - await requireUser(); - const id = new URL(request.url).searchParams.get("id"); - if (!id) return fail("Which key?"); - await clearSecret(id); - return ok(await listSecrets()); - } catch (e) { - return caught(e); - } -} diff --git a/app/api/settings/route.ts b/app/api/settings/route.ts deleted file mode 100644 index 216bc0b..0000000 --- a/app/api/settings/route.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { requireUser } from "@/lib/server/auth"; -import { getSettings, setSettings } from "@/lib/server/repos/settings"; -import { caught, ok, ready } from "@/lib/server/http"; - -export async function GET() { - try { - await ready(); - await requireUser(); - return ok(await getSettings()); - } catch (e) { - return caught(e); - } -} - -export async function PATCH(request: Request) { - try { - await ready(); - await requireUser(); - return ok(await setSettings(await request.json().catch(() => ({})))); - } catch (e) { - return caught(e); - } -} diff --git a/app/api/sources/[id]/frames/[file]/route.ts b/app/api/sources/[id]/frames/[file]/route.ts deleted file mode 100644 index 4c9acf1..0000000 --- a/app/api/sources/[id]/frames/[file]/route.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { requireUser } from "@/lib/server/auth"; -import { frameFile } from "@/lib/server/services/ingest"; -import { caught, fail, ready } from "@/lib/server/http"; - -/** - * One still out of a downloaded video. - * - * Served through a route rather than from /public: these are somebody's - * research material, not site assets, and putting them under /public would - * make every frame of every source readable by anyone who can guess a path. - */ -export async function GET( - _r: Request, - { params }: { params: Promise<{ id: string; file: string }> }, -) { - try { - await ready(); - await requireUser(); - const { id, file } = await params; - const bytes = await frameFile(id, file); - if (!bytes) return fail("No such frame", 404); - return new Response(new Uint8Array(bytes), { - headers: { - "content-type": "image/jpeg", - // The file for a given id never changes; a rewrite makes a new source. - "cache-control": "private, max-age=31536000, immutable", - }, - }); - } catch (e) { - return caught(e); - } -} diff --git a/app/api/sources/[id]/frames/route.ts b/app/api/sources/[id]/frames/route.ts deleted file mode 100644 index ec8414d..0000000 --- a/app/api/sources/[id]/frames/route.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { requireUser } from "@/lib/server/auth"; -import { addFrameAt } from "@/lib/server/services/ingest"; -import { caught, fail, ok, ready } from "@/lib/server/http"; - -/** ffmpeg seeking into a downloaded file — seconds, but not instant. */ -export const maxDuration = 120; - -/** One more still, at a moment somebody asked for. */ -export async function POST( - request: Request, - { params }: { params: Promise<{ id: string }> }, -) { - try { - await ready(); - await requireUser(); - const { id } = await params; - const body = (await request.json().catch(() => ({}))) as { at?: number }; - const at = Number(body.at); - if (!Number.isFinite(at) || at < 0) return fail("Give a time in seconds"); - return ok(await addFrameAt(id, at), 201); - } catch (e) { - return caught(e); - } -} diff --git a/app/api/sources/[id]/route.ts b/app/api/sources/[id]/route.ts deleted file mode 100644 index 2eec00e..0000000 --- a/app/api/sources/[id]/route.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { requireUser } from "@/lib/server/auth"; -import { deleteSource, getSource } from "@/lib/server/repos/sources"; -import { caught, fail, ok, ready } from "@/lib/server/http"; - -export async function GET( - _r: Request, - { params }: { params: Promise<{ id: string }> }, -) { - try { - await ready(); - await requireUser(); - const { id } = await params; - const source = await getSource(id); - return source ? ok(source) : fail("No such source", 404); - } catch (e) { - return caught(e); - } -} - -export async function DELETE( - _r: Request, - { params }: { params: Promise<{ id: string }> }, -) { - try { - await ready(); - await requireUser(); - const { id } = await params; - return ok({ ok: await deleteSource(id) }); - } catch (e) { - return caught(e); - } -} diff --git a/app/api/sources/route.ts b/app/api/sources/route.ts deleted file mode 100644 index 1ab22c2..0000000 --- a/app/api/sources/route.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { requireUser } from "@/lib/server/auth"; -import { listSources } from "@/lib/server/repos/sources"; -import { ingest } from "@/lib/server/services/ingest"; -import { caught, fail, ok, ready } from "@/lib/server/http"; - -/** A download, frames and a transcript. Minutes, not seconds. */ -export const maxDuration = 800; - -export async function GET(request: Request) { - try { - await ready(); - await requireUser(); - const workspaceId = new URL(request.url).searchParams.get("workspaceId"); - return ok(await listSources(workspaceId ?? undefined)); - } catch (e) { - return caught(e); - } -} - -/** - * Fetch a video. - * - * Synchronous on purpose. A background job would need a queue, a worker and a - * way to ask how it is going; this is one person's machine pulling one reel, - * and the browser can wait with a spinner on it. - */ -export async function POST(request: Request) { - try { - await ready(); - await requireUser(); - const body = (await request.json().catch(() => ({}))) as { - url?: string; - workspaceId?: string | null; - refresh?: boolean; - }; - if (!body.url?.trim()) return fail("Paste a link first"); - return ok( - await ingest({ - url: body.url, - workspaceId: body.workspaceId ?? null, - refresh: body.refresh, - }), - 201, - ); - } catch (e) { - return caught(e); - } -} diff --git a/app/api/sources/upload/route.ts b/app/api/sources/upload/route.ts deleted file mode 100644 index a8d3196..0000000 --- a/app/api/sources/upload/route.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { requireUser } from "@/lib/server/auth"; -import { ingestFile } from "@/lib/server/services/ingest"; -import { caught, fail, ok, ready } from "@/lib/server/http"; - -/** Frames and a transcript off an uploaded file. Minutes. */ -export const maxDuration = 800; - -/** - * A video from the person's own machine. - * - * Multipart rather than base64 JSON: a 200MB reel encodes to 270MB of string, - * and the body has to be held in memory twice to parse it. - */ -export async function POST(request: Request) { - try { - await ready(); - await requireUser(); - - const form = await request.formData().catch(() => null); - const file = form?.get("file"); - if (!(file instanceof File)) return fail("Choose a video file"); - if (!file.size) return fail("That file is empty"); - - const workspaceId = form?.get("workspaceId"); - return ok( - await ingestFile({ - filename: file.name, - bytes: Buffer.from(await file.arrayBuffer()), - workspaceId: typeof workspaceId === "string" ? workspaceId : null, - }), - 201, - ); - } catch (e) { - return caught(e); - } -} diff --git a/app/api/tools/[slug]/route.ts b/app/api/tools/[slug]/route.ts deleted file mode 100644 index 874a8d5..0000000 --- a/app/api/tools/[slug]/route.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { getTool, updateTool } from "@/lib/server/repos/tools"; -import { caught, fail, ok, ready } from "@/lib/server/http"; - -export async function GET( - _r: Request, - { params }: { params: Promise<{ slug: string }> }, -) { - try { - await ready(); - const { slug } = await params; - const tool = await getTool(slug); - return tool ? ok(tool) : fail("No such tool", 404); - } catch (e) { - return caught(e); - } -} - -/** Rename it, recategorise it, switch it off, or say where it appears. */ -export async function PATCH( - request: Request, - { params }: { params: Promise<{ slug: string }> }, -) { - try { - await ready(); - const { slug } = await params; - const tool = await updateTool(slug, await request.json().catch(() => ({}))); - return tool ? ok(tool) : fail("No such tool", 404); - } catch (e) { - return caught(e); - } -} diff --git a/app/api/tools/route.ts b/app/api/tools/route.ts deleted file mode 100644 index 37f8b3c..0000000 --- a/app/api/tools/route.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { listTools, toolsFor } from "@/lib/server/repos/tools"; -import { caught, ok, ready } from "@/lib/server/http"; - -/** - * The tool bench. - * - * `?workspace=` asks for one workspace's bench — what it is allowed to - * see. Without it you get every tool and its assignment, which is what the - * screen that manages them needs and nothing else should be reading. - */ -export async function GET(request: Request) { - try { - await ready(); - const workspace = new URL(request.url).searchParams.get("workspace"); - return ok(workspace ? await toolsFor(workspace) : await listTools()); - } catch (e) { - return caught(e); - } -} diff --git a/app/api/topics/[id]/route.ts b/app/api/topics/[id]/route.ts deleted file mode 100644 index 663f76a..0000000 --- a/app/api/topics/[id]/route.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { deleteTopic, updateTopic } from "@/lib/server/repos/series"; -import { caught, fail, ok, ready } from "@/lib/server/http"; - -export async function PATCH( - request: Request, - { params }: { params: Promise<{ id: string }> }, -) { - try { - await ready(); - const { id } = await params; - const t = await updateTopic(id, await request.json().catch(() => ({}))); - return t ? ok(t) : fail("No such topic", 404); - } catch (e) { - return caught(e); - } -} - -export async function DELETE( - _r: Request, - { params }: { params: Promise<{ id: string }> }, -) { - try { - await ready(); - const { id } = await params; - return ok({ ok: await deleteTopic(id) }); - } catch (e) { - return caught(e); - } -} diff --git a/app/api/users/[id]/route.ts b/app/api/users/[id]/route.ts deleted file mode 100644 index 13aee8a..0000000 --- a/app/api/users/[id]/route.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { removeUser, requireUser } from "@/lib/server/auth"; -import { caught, fail, ok, ready } from "@/lib/server/http"; - -/** Remove someone. Their sessions go with them; their work stays. */ -export async function DELETE( - _r: Request, - { params }: { params: Promise<{ id: string }> }, -) { - try { - await ready(); - const me = await requireUser(); - const { id } = await params; - const gone = await removeUser(id, me.id); - return gone ? ok({ ok: true }) : fail("No such account", 404); - } catch (e) { - return caught(e); - } -} diff --git a/app/api/users/route.ts b/app/api/users/route.ts deleted file mode 100644 index 5f77771..0000000 --- a/app/api/users/route.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { listUsers, requireUser } from "@/lib/server/auth"; -import { caught, ok, ready } from "@/lib/server/http"; - -/** Who has access to this console. */ -export async function GET() { - try { - await ready(); - await requireUser(); - return ok(await listUsers()); - } catch (e) { - return caught(e); - } -} diff --git a/app/api/workspaces/[id]/route.ts b/app/api/workspaces/[id]/route.ts deleted file mode 100644 index ef59698..0000000 --- a/app/api/workspaces/[id]/route.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { - deleteWorkspace, - getWorkspace, - listWorkspaces, - updateWorkspace, -} from "@/lib/server/repos/workspaces"; -import { listSeries } from "@/lib/server/repos/series"; -import { caught, fail, ok, ready } from "@/lib/server/http"; - -export async function GET( - _r: Request, - { params }: { params: Promise<{ id: string }> }, -) { - try { - await ready(); - const { id } = await params; - const ws = await getWorkspace(id); - return ws - ? ok({ ...ws, series: await listSeries(id) }) - : fail("No such workspace", 404); - } catch (e) { - return caught(e); - } -} - -export async function PATCH( - request: Request, - { params }: { params: Promise<{ id: string }> }, -) { - try { - await ready(); - const { id } = await params; - const ws = await updateWorkspace(id, await request.json().catch(() => ({}))); - return ws - ? ok({ ...ws, series: await listSeries(id) }) - : fail("No such workspace", 404); - } catch (e) { - return caught(e); - } -} - -export async function DELETE( - _r: Request, - { params }: { params: Promise<{ id: string }> }, -) { - try { - await ready(); - const { id } = await params; - // The last one cannot go: every screen reads the current workspace's packs, - // series and voice, and an empty list is a shell with nothing to render. - if ((await listWorkspaces()).length <= 1) { - return fail("This is the only workspace — there would be nothing left", 409); - } - return ok({ ok: await deleteWorkspace(id) }); - } catch (e) { - return caught(e); - } -} diff --git a/app/api/workspaces/route.ts b/app/api/workspaces/route.ts deleted file mode 100644 index 79acb9d..0000000 --- a/app/api/workspaces/route.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { createWorkspace, listWorkspaces } from "@/lib/server/repos/workspaces"; -import { listSeries } from "@/lib/server/repos/series"; -import { caught, ok, ready } from "@/lib/server/http"; - -/** Every workspace, each with its series and their topics. */ -export async function GET() { - try { - await ready(); - const list = await listWorkspaces(); - // Concurrently rather than in sequence: the queries are independent, and - // four workspaces should cost one round trip of latency, not four. - return ok( - await Promise.all( - list.map(async (w) => ({ ...w, series: await listSeries(w.id) })), - ), - ); - } catch (e) { - return caught(e); - } -} - -export async function POST(request: Request) { - try { - await ready(); - const body = await request.json().catch(() => ({})); - return ok({ ...(await createWorkspace(body)), series: [] }, 201); - } catch (e) { - return caught(e); - } -} diff --git a/components/ApiDownBanner.tsx b/components/ApiDownBanner.tsx new file mode 100644 index 0000000..5abddd9 --- /dev/null +++ b/components/ApiDownBanner.tsx @@ -0,0 +1,57 @@ +"use client"; + +import { API_URL } from "@/lib/api-base"; +import { useStore } from "@/lib/store"; +import { font } from "@/lib/theme"; + +/** + * "The API is not running" — said plainly, at the top, in red. + * + * Without this the console rendered the design's sample workspaces and + * "0 templates" whenever the API process was down, which reads as "my work + * is gone". It is not gone; nothing is answering on the port. The store + * asks every few seconds whether it is back and reloads when it is, so this + * disappears on its own once `./start.sh` is up. + */ +export function ApiDownBanner() { + const { apiDown } = useStore(); + if (!apiDown) return null; + + return ( +
+ + + The API is not running — + nothing is answering at{" "} + {API_URL}. + Your templates and content are in the database and will be back the + moment it is. Start it with{" "} + ./start.sh{" "} + (or npm run api:dev); + this page reloads on its own when it answers. + +
+ ); +} diff --git a/components/AppShell.tsx b/components/AppShell.tsx index 6b00c53..4c81c03 100644 --- a/components/AppShell.tsx +++ b/components/AppShell.tsx @@ -5,6 +5,7 @@ import { useEffect } from "react"; import { usePathname } from "next/navigation"; import { useStore } from "@/lib/store"; +import { ApiDownBanner } from "@/components/ApiDownBanner"; import { Header } from "@/components/Header"; import { Sidebar } from "@/components/Sidebar"; import { AddSectionSheet } from "@/components/overlays/AddSectionSheet"; @@ -107,6 +108,7 @@ export function AppShell({ children }: { children: ReactNode }) { minWidth: 0, }} > +
{children} diff --git a/components/Header.tsx b/components/Header.tsx index f99dc0c..f9fd0fb 100644 --- a/components/Header.tsx +++ b/components/Header.tsx @@ -1,5 +1,6 @@ "use client"; +import { apiFetch } from "@/lib/api-base"; import { useEffect, useRef, useState, type CSSProperties } from "react"; import { useRouter } from "next/navigation"; @@ -370,7 +371,7 @@ function Account() { useEffect(() => { let cancelled = false; - void fetch("/api/auth/me", { cache: "no-store" }) + void apiFetch("/api/auth/me", { cache: "no-store" }) .then((r) => r.json()) .then((body: { user?: { email: string; name: string } | null }) => { if (!cancelled) setMe(body.user ?? null); @@ -455,7 +456,7 @@ function Account() { role="menuitem" onClick={() => { setOpen(false); - void fetch("/api/auth/logout", { method: "POST" }).then(() => + void apiFetch("/api/auth/logout", { method: "POST" }).then(() => router.replace("/login"), ); }} diff --git a/components/overlays/RunSetupSheet.tsx b/components/overlays/RunSetupSheet.tsx index 37f2c9f..3c3eed2 100644 --- a/components/overlays/RunSetupSheet.tsx +++ b/components/overlays/RunSetupSheet.tsx @@ -21,6 +21,7 @@ export function RunSetupSheet() { setQuality, go, project, + projectsLoaded, seriesList, runTopicName, setRunTopicName, @@ -129,9 +130,23 @@ export function RunSetupSheet() { const [fetching, setFetching] = useState(false); const [sourceError, setSourceError] = useState(""); + /* + * Nothing is written against a workspace the server has not confirmed. + * + * The store opens on sample workspaces with empty ids until the first + * request answers. A run or a download in that window would go out with + * workspaceId "" and come back as a foreign-key error — reported as + * "something went wrong", on a button that looked ready. + */ + const ready = projectsLoaded && Boolean(project.id); + const pullSource = async () => { const url = sourceUrl.trim(); if (!url || fetching) return; + if (!ready) { + setSourceError("Still loading the workspace — try again in a second."); + return; + } setFetching(true); setSourceError(""); try { @@ -155,6 +170,10 @@ export function RunSetupSheet() { */ const start = async () => { if (starting) return; + if (!ready) { + setStartError("Still loading the workspace — try again in a second."); + return; + } setStarting(true); setStartError(""); try { @@ -741,6 +760,7 @@ export function RunSetupSheet() { { - void fetch("/api/invites", { cache: "no-store" }) + void apiFetch("/api/invites", { cache: "no-store" }) .then((r) => json(r)) .then(setInvites) .catch((e: unknown) => setError(e instanceof Error ? e.message : "Could not read the invites"), ); - void fetch("/api/users", { cache: "no-store" }) + void apiFetch("/api/users", { cache: "no-store" }) .then((r) => json(r)) .then(setPeople) .catch(() => setPeople([])); @@ -79,7 +80,7 @@ export function TeamPanel() { setBusy(true); setError(""); try { - const made = await fetch("/api/invites", { + const made = await apiFetch("/api/invites", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email: email.trim(), note: note.trim() }), @@ -102,13 +103,13 @@ export function TeamPanel() { const revoke = async (token: string) => { setInvites((prev) => (prev ?? []).filter((i) => i.token !== token)); - await fetch(`/api/invites/${token}`, { method: "DELETE" }).catch(() => {}); + await apiFetch(`/api/invites/${token}`, { method: "DELETE" }).catch(() => {}); load(); }; const removePerson = async (person: Person) => { setPeople((prev) => (prev ?? []).filter((p) => p.id !== person.id)); - await fetch(`/api/users/${person.id}`, { method: "DELETE" }).catch(() => {}); + await apiFetch(`/api/users/${person.id}`, { method: "DELETE" }).catch(() => {}); load(); }; diff --git a/components/tools/FramePicker.tsx b/components/tools/FramePicker.tsx new file mode 100644 index 0000000..5e37f16 --- /dev/null +++ b/components/tools/FramePicker.tsx @@ -0,0 +1,334 @@ +"use client"; + +import type { Source } from "@/lib/sources-client"; +import { frameUrl } from "@/lib/sources-client"; +import { font, spring, t, w } from "@/lib/theme"; +import { Hov } from "@/components/ui/Hov"; +import { Button } from "@/components/ui"; +import { CheckIcon } from "@/components/ui/Icons"; + +/** + * Which moments of the video the model is going to look at. + * + * Lifted out of the researcher screen, which was doing three jobs in one file: + * fetching a video, choosing frames, and reading an answer. This is the middle + * one, and it is the only part with real interaction in it. + * + * It owns no state. The picked list, the timestamp box and the cutting all + * belong to the screen — a picker that held its own selection would have to be + * told to forget it every time a new video arrived, which is exactly the sort + * of thing that gets missed. + */ + +const kicker = { + fontFamily: font.mono, + fontSize: 9.5, + letterSpacing: "0.14em", + color: t(0.38), +} as const; + +/** m:ss — how a person says a moment in a reel. */ +export const clock = (seconds: number) => { + const m = Math.floor(seconds / 60); + const s = Math.floor(seconds % 60); + return `${m}:${String(s).padStart(2, "0")}`; +}; + +export function FramePicker({ + source, + picked, + setPicked, + chosen, + at, + setAt, + onCut, +}: { + source: Source; + /** The files ticked, by name. */ + picked: string[]; + setPicked: (next: string[] | ((list: string[]) => string[])) => void; + /** What will actually be sent — every frame when nothing is ticked. */ + chosen: string[]; + /** The "another moment" box, held by the screen so a cut can clear it. */ + at: string; + setAt: (value: string) => void; + onCut: () => void; +}) { + const frames = source.frames; + + const toggle = (file: string) => + setPicked((list) => + list.includes(file) ? list.filter((f) => f !== file) : [...list, file], + ); + + return ( + <> +

+ Pick the moments worth reading — the address bar, the result on + screen. Every picked frame is sent as a picture, so the right four + beat all eight. +

+ + {/* + The strip, and the toolbar that acts on it. + + The count comes first, because "how many am I sending" is the + question the price of this run turns on. All and None sit beside it + rather than under the grid: picking eight things one at a time is + the work this screen exists to save. + */} +
+ + {chosen.length} OF {frames.length} PICKED + + + + + + {/* + Adding a moment belongs here, not under the grid: it is the same + job as picking one — deciding what gets looked at — and it was + two rows away from the thing it adds to. + */} + + AT + setAt(e.target.value)} + onKeyDown={(e) => { + if (e.key === "Enter") onCut(); + }} + placeholder="1:12" + aria-label="Cut a frame at this time" + style={{ + width: 54, + height: 24, + border: "none", + outline: "none", + background: "transparent", + fontFamily: font.mono, + fontSize: 12, + color: "#f0f0f4", + }} + /> + + +
+ + {/* + The video as a line, with a node per frame. + + Eight thumbnails say what was captured; they do not say WHEN, and + "the bit where the address bar is up" is a question about time. The + track is the video, each node sits where it was taken, and clicking + one picks it — the same act as clicking its thumbnail, approached + from the other side. + */} + {frames.length && source.duration ? ( +
+ + {frames.map((frame) => { + const on = picked.includes(frame.file); + const left = Math.min( + 100, + Math.max(0, (frame.at / (source.duration || 1)) * 100), + ); + return ( + toggle(frame.file)} + style={{ + position: "absolute", + left: left + "%", + top: on ? 5 : 7, + width: on ? 13 : 9, + height: on ? 13 : 9, + marginLeft: on ? -6.5 : -4.5, + borderRadius: "50%", + cursor: "pointer", + background: on ? "#0057fc" : w(0.22), + boxShadow: on ? "0 0 10px rgba(0,87,252,0.55)" : "none", + transition: "all 180ms " + spring, + }} + hover={{ background: on ? "#3b7bff" : w(0.4) }} + /> + ); + })} +
+ ) : null} + + {frames.length ? ( +
+ {frames.map((frame) => { + const on = picked.includes(frame.file); + return ( + toggle(frame.file)} + style={{ + position: "relative", + aspectRatio: "16 / 10", + borderRadius: 13, + overflow: "hidden", + cursor: "pointer", + background: "#0b0d12", + border: "1px solid " + (on ? "transparent" : w(0.08)), + /* + * A ring rather than a fat border: a 2px border on a + * 148px card reflows the picture inside it every time one + * is picked, and the whole grid twitches under the cursor. + */ + boxShadow: on + ? "0 0 0 2px #0057fc, 0 10px 24px -12px rgba(0,87,252,0.8)" + : "0 1px 2px rgba(0,0,0,0.35)", + transition: + "transform 180ms " + spring + ", box-shadow 180ms " + spring, + }} + hover={{ transform: "translateY(-2px)" }} + > + {/* eslint-disable-next-line @next/next/no-img-element */} + {"Frame + + + + + {clock(frame.at)} + + + + {on ? : null} + + + ); + })} +
+ ) : ( +

+ No frames were cut — the video itself was not downloaded, or + ffmpeg is off in Integrations. It can still read the transcript. +

+ )} + + + ); +} diff --git a/components/views/AuthView.tsx b/components/views/AuthView.tsx index d22f2c8..1f9f135 100644 --- a/components/views/AuthView.tsx +++ b/components/views/AuthView.tsx @@ -1,5 +1,6 @@ "use client"; +import { apiFetch } from "@/lib/api-base"; import { useEffect, useState, type FormEvent } from "react"; import { useRouter, useSearchParams } from "next/navigation"; @@ -42,7 +43,7 @@ export function AuthView({ mode }: { mode: "login" | "signup" }) { useEffect(() => { let cancelled = false; - void fetch("/api/auth/me", { cache: "no-store" }) + void apiFetch("/api/auth/me", { cache: "no-store" }) .then(async (r) => ({ status: r.status, body: await r.json().catch(() => ({})) })) .then(({ status, body }: { status: number; body: { user?: unknown; signupOpen?: boolean; error?: string } }) => { if (cancelled) return; @@ -77,7 +78,7 @@ export function AuthView({ mode }: { mode: "login" | "signup" }) { setBusy(true); setError(""); try { - const res = await fetch(`/api/auth/${signup ? "signup" : "login"}`, { + const res = await apiFetch(`/api/auth/${signup ? "signup" : "login"}`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify( diff --git a/components/views/ContentGroupsView.tsx b/components/views/ContentGroupsView.tsx index 1f36b93..fd1ec46 100644 --- a/components/views/ContentGroupsView.tsx +++ b/components/views/ContentGroupsView.tsx @@ -3,7 +3,6 @@ import { useCallback, useEffect, - useMemo, useRef, useState, type CSSProperties, @@ -11,39 +10,27 @@ import { import { USAGE, - USAGE_ORDER, STATE_STYLE, - docsByPack, outputsFor, type ContentDoc, type Decision, - type UsageStatus, } from "@/lib/content-docs"; -import { - isEditable, - setDecision, - statusOf, - useDecisions, -} from "@/lib/decisions"; +import { isEditable, setDecision, statusOf } from "@/lib/decisions"; import { useStore } from "@/lib/store"; -import { slugify } from "@/lib/content-docs"; -import { partName } from "@/lib/topics"; +import { deleteRun } from "@/lib/runs-client"; import { - deleteRun, - listRuns, - startWriting, - type Run, -} from "@/lib/runs-client"; -import { runToDoc } from "@/lib/run-doc"; + ALL, + SORTS, + hrefFor, + useContentList, + type FilterKey, + type SortKey, +} from "@/lib/use-content-list"; import { CONTENT_TABS } from "@/components/views/content-tabs"; - -/** Where a row opens: the run that made it, or the document it is. */ -const hrefFor = (doc: ContentDoc) => - doc.runId ? `/runs/${doc.runId}` : `/content/${doc.slug}`; import { useTopicAdmin } from "@/components/topics/TopicAdmin"; import { font, panel, primary, rise, t, w } from "@/lib/theme"; import { Hov } from "@/components/ui/Hov"; -import { FilterMenu, type FilterOption } from "@/components/ui/FilterMenu"; +import { FilterMenu } from "@/components/ui/FilterMenu"; import type { RailItem } from "@/components/ui"; import { Button, @@ -104,34 +91,6 @@ const GRID = "1fr 168px 132px 76px 96px"; /** The statuses you can pick — "Writing" is derived, so it is not offered. */ const DECISIONS: Decision[] = ["used", "ready", "ignored"]; -/** - * The status switcher: one status at a time, never a set. - * - * This was a checkbox menu, which asked a question nobody was answering. The - * list is one lifecycle — an idea, then the writing of it, then what came out - * — and you read it a stage at a time: what have I not started, what is in - * flight, what is done. Ticking two boxes interleaves two stages into one - * list, and the "0 selected means all" state that a checkbox menu needs made - * the default screen a pile of everything at once. - * - * So it is a switcher, opening on IDEA — the shelf of things not yet made, - * which is where the work starts. - * - * Used and Ignored are not tabs here: they are the end of the line, and a - * permanent tab for a status nothing has yet is a dead segment. They join the - * row the moment a topic carries one — see `statusTabs` — so nothing is ever - * filtered out of reach. - */ -/* - * Writing is not one of them. - * - * A run in flight is not a shelf you browse — it is a thing happening right - * now, and hiding it behind a filter meant the only way to see what the - * machine was doing was to remember to go and look. It has its own strip at - * the top of the page instead, always on, whichever status you are reading. - */ -const STATUS_TABS: UsageStatus[] = ["idea", "ready"]; - /** The status's colour, in the switcher. */ const StatusDot = ({ color }: { color: string }) => ( ( /> ); -type SortKey = "recent" | "topic" | "status"; - -const SORTS: { key: SortKey; label: string }[] = [ - { key: "recent", label: "Most recent" }, - { key: "topic", label: "Topic A–Z" }, - // "Least finished" went with the SECTIONS column: it ordered the list by a - // number that is no longer on screen, so the rows moved and nothing visible - // explained why. - // Content first, ideas last — the split "most recent" does not make. - { key: "status", label: "Finished first" }, -]; - const chipStyle: CSSProperties = { display: "flex", alignItems: "center", @@ -536,7 +483,6 @@ function ActiveChip({ ); } -type FilterKey = "status" | "template" | "series"; export function ContentGroupsView() { const { @@ -545,7 +491,6 @@ export function ContentGroupsView() { deleteTopic, reloadRuns, askConfirm, - seriesList, packs, runTopicNow, } = useStore(); @@ -553,42 +498,38 @@ export function ContentGroupsView() { /** The series strip, the two dialogs, and the state behind them. */ const admin = useTopicAdmin(); - /* - * What has actually been written. - * - * The rows above this are topics and the design's sample documents; these are - * real runs off the server, with real text behind every section. Fetched - * rather than seeded, and merged in below so a pack you ran ten minutes ago - * appears in the list you came here to read. - */ - const [runs, setRuns] = useState([]); - useEffect(() => { - void listRuns() - .then(setRuns) - // Silent: the list is still useful without them, and a failed fetch must - // not blank a page that has plenty else to show. - .catch(() => {}); - }, []); + /** Every row, filter, count and sort — see lib/use-content-list.ts. */ + const { + DOCS, + groups, + shown, + options, + active, + anyFilter, + statusTabs, + writingNow, + retry, + query, + setQuery, + sort, + setSort, + filters, + toggle, + clear, + clearAll, + status, + pickStatus, + seriesTab, + pickSeries, + templateTab, + pickTemplate, + } = useContentList(); - /** - * Start a failed run again. - * - * The server clears the failures and picks up where the drive stopped, so - * this is one press rather than a section-by-section repair. The list is - * re-read straight after: the row has to leave the Failed tab the moment it - * is writing again, or the button looks like it did nothing. - */ - const retry = useCallback(async (runId: string) => { - try { - await startWriting(runId); - } catch { - // The row keeps saying Failed, which is still true. Nothing else to say. - } - await listRuns() - .then(setRuns) - .catch(() => {}); - void reloadRuns(); - }, [reloadRuns]); + const [open, setOpen] = useState(null); + const [statusOpen, setStatusOpen] = useState(null); + + const activeSeries = + admin.seriesList.find((series) => series.id === seriesTab) ?? null; /** * The row that is being started, so its button can say so. @@ -654,323 +595,6 @@ export function ContentGroupsView() { if (doc.topicId) deleteTopic(doc.topicId); }; - // Re-renders this list whenever a status is changed anywhere. - const version = useDecisions(); - - const [query, setQuery] = useState(""); - const [sort, setSort] = useState("recent"); - const [open, setOpen] = useState(null); - const [statusOpen, setStatusOpen] = useState(null); - const [filters, setFilters] = useState>({ - status: ["idea"], - template: [], - series: [], - }); - - const toggle = (key: FilterKey, value: string) => - setFilters((prev) => ({ - ...prev, - [key]: prev[key].includes(value) - ? prev[key].filter((v) => v !== value) - : [...prev[key], value], - })); - - const clear = (key: FilterKey) => - setFilters((prev) => ({ ...prev, [key]: [] })); - - const clearAll = () => { - // The series is navigation now, not a filter — the tab survives a clear. - // Neither does the status: it is a switcher, and a switcher with nothing - // selected is not a state it has. Clearing returns it to Idea. - setFilters((prev) => ({ - status: ["idea"], - template: [], - series: prev.series, - })); - setQuery(""); - }; - - /** The switcher's current status, and how it moves. */ - const status = (filters.status[0] ?? "idea") as UsageStatus; - const pickStatus = (next: UsageStatus) => - setFilters((prev) => ({ ...prev, status: [next] })); - - /** - * The documents as this screen sees them: the data underneath, with the - * renames applied and the removed ones dropped. The documents themselves are - * left alone, so /content/ still opens what it always did. - */ - const DOCS = useMemo(() => { - /* - * Every topic in this workspace, plus what has actually been written. - * - * The sample documents are gone. They put twenty-four invented topics on - * this list under a template that does not exist, each opening a page of - * text nobody wrote — which made the screen look full and made it - * impossible to see what was really there. - * - * A topic with no run gets a row with no sections, which `statusOf` reads - * as "idea": the first step of the same lifecycle that ends in used or - * ignored. Real runs go in front, newest first, because the thing you just - * made is the thing you came to look at. - */ - const shelfOf = new Map( - seriesList.flatMap((series) => - series.topics.map((topic) => [topic.id, series.id] as const), - ), - ); - - const produced: ContentDoc[] = runs.map((r) => ({ - ...runToDoc( - r, - packs.find((x) => x.id === r.packSlug), - ), - // A run's shelf is its topic's shelf. `inputs.series` is the name that - // was typed into it, which is a label, not an identity. - seriesId: r.topicId ? shelfOf.get(r.topicId) : undefined, - })); - - const written = new Set(produced.map((d) => d.topic.toLowerCase())); - const rows: ContentDoc[] = []; - - for (const series of seriesList) { - for (const topic of series.topics) { - // A topic whose run is already in `produced` would otherwise appear - // twice: once as the content, once as the idea it started as. - if (written.has(topic.name.toLowerCase())) continue; - rows.push({ - slug: slugify(topic.name), - topicId: topic.id, - seriesId: series.id, - topic: topic.name, - series: series.name, - pack: series.pack || "No template", - // Zero-padded: the tiles are a monospace column, and "8" beside "24" - // reads as a stray digit where "08" reads as a part number. - part: - topic.part !== null - ? partName(series.partLabel, topic.part) - : "", - blurb: "", - decision: topic.decision, - created: topic.activity, - updated: topic.activity, - at: topic.updatedAt, - sections: [], - }); - } - } - - return [...produced, ...rows]; - }, [seriesList, runs, packs]); - - const { groups, shown, options, active } = useMemo(() => { - void version; - const q = query.trim().toLowerCase(); - - const passes = { - search: (d: ContentDoc) => - !q || - `${d.topic} ${d.pack} ${d.blurb} ${d.series}`.toLowerCase().includes(q), - status: (d: ContentDoc) => - !filters.status.length || filters.status.includes(statusOf(d)), - pack: (d: ContentDoc) => - !filters.template.length || filters.template.includes(d.pack), - series: (d: ContentDoc) => - !filters.series.length || filters.series.includes(d.seriesId ?? ""), - }; - - const matched = DOCS.filter( - (d) => - passes.search(d) && - passes.status(d) && - passes.pack(d) && - passes.series(d), - ); - - /** - * Counts for one dimension are taken with that dimension left open, so - * picking "Ignored" still shows how many Used topics there are. Values - * that would match nothing are dropped unless they are already picked. - */ - const facet = ( - pool: ContentDoc[], - pick: (d: ContentDoc) => string, - values: string[], - selected: string[], - label: (v: string) => string, - dot?: (v: string) => string, - ): FilterOption[] => - values - .map((value) => ({ - value, - label: label(value), - count: pool.filter((d) => pick(d) === value).length, - dot: dot?.(value), - })) - .filter((o) => o.count > 0 || selected.includes(o.value)); - - const forStatus = DOCS.filter( - (d) => passes.search(d) && passes.pack(d) && passes.series(d), - ); - const forPack = DOCS.filter( - (d) => passes.search(d) && passes.status(d) && passes.series(d), - ); - const forSeries = DOCS.filter( - (d) => passes.search(d) && passes.status(d) && passes.pack(d), - ); - - const packs = [...new Set(DOCS.map((d) => d.pack))].sort(); - const series = [...new Set(DOCS.map((d) => d.seriesId ?? ""))]; - - /* - * Writing first, then what needs a person: a failed run is the one thing - * on the list that is waiting on you rather than on the model. - */ - const rank: Record = { - writing: 0, - failed: 1, - ready: 2, - used: 3, - idea: 4, - ignored: 5, - }; - - const sorted = [...matched].sort((a, b) => { - switch (sort) { - case "topic": - return a.topic.localeCompare(b.topic); - case "status": - /* - * Status first, then recency inside it. - * - * This is the view that separates finished content from ideas, which - * "most recent" deliberately does not — sorted by time, an idea from - * yesterday belongs between two runs from yesterday. Without the - * second key, rows sharing a status fell back to build order and - * moved for reasons nothing on screen explained. - */ - return ( - rank[statusOf(a)] - rank[statusOf(b)] || b.at.localeCompare(a.at) - ); - default: - /* - * Most recent, actually sorted. - * - * This used to return 0 and lean on the order DOCS builds — runs - * first, then topics shelf by shelf — so a topic you had just added - * appeared at the bottom of its shelf's block with nothing above it - * explaining why. `at` is an ISO instant and sorts as a string, so - * newest first is a plain descending compare. - * - * A tie falls back to the name, so equal timestamps give a stable - * order rather than one that reshuffles on every render. - */ - return b.at.localeCompare(a.at) || a.topic.localeCompare(b.topic); - } - }); - - return { - groups: docsByPack(sorted), - shown: sorted.length, - options: { - status: facet( - forStatus, - (d) => statusOf(d), - USAGE_ORDER, - filters.status, - (v) => USAGE[v as UsageStatus].label, - (v) => USAGE[v as UsageStatus].dot, - ), - template: facet( - forPack, - (d) => d.pack, - packs, - filters.template, - (v) => v, - ), - series: facet( - forSeries, - (d) => d.seriesId ?? "", - series, - filters.series, - // The facet is keyed by id but read by people: anything rendering it - // needs the shelf's name, not `ser_mtbuo7f4e59wg`. - (id) => seriesList.find((x) => x.id === id)?.name ?? "No series", - ), - }, - // Series and status are left out on purpose: both are controls that - // always read their own state — the rail says which shelf, the switcher - // says which status — and a chip that removes one would leave it with - // nothing selected, which is not a state either of them has. - active: filters.template.map((value) => ({ - key: "template" as FilterKey, - value, - label: value, - dot: undefined as string | undefined, - })), - }; - }, [DOCS, query, filters, sort, version, seriesList]); - - /** - * The switcher's segments: the three lifecycle stages, plus any end state a - * topic has actually reached. Mark one Used and a USED segment appears — - * which is the only way back to it, so it has to. - */ - const statusTabs = useMemo(() => { - const present = new Set(options.status.map((o) => o.value)); - return [ - ...STATUS_TABS, - ...USAGE_ORDER.filter( - (s) => - !STATUS_TABS.includes(s) && - present.has(s) && - // Writing has the strip; a segment for it would be a second place - // saying the same thing, and the worse of the two. It comes back - // only if it is the segment you are standing on, because otherwise - // there would be no way off it. - (s !== "writing" || status === "writing"), - ), - ]; - }, [options.status, status]); - - /** - * What the machine is doing right now. - * - * Off DOCS rather than off the filtered list on purpose: a run in flight is - * news whatever you happen to be reading, and a strip that empties because - * you switched to Ready would be a status light you cannot trust. - */ - const writingNow = useMemo( - () => - DOCS.filter((d) => statusOf(d) === "writing").map((d) => ({ - slug: d.slug, - topic: d.topic, - pack: d.pack, - // Where this row opens. Carried rather than rebuilt from the slug: a - // row that came from a run has the RUN's id as its slug, and - // `/content/run_…` is a 404 that reads as "your work is gone". - href: hrefFor(d), - written: d.sections.filter((x) => x.state === "written").length, - total: d.sections.length, - })), - [DOCS], - ); - - const anyFilter = active.length > 0 || query.trim().length > 0; - - /* - * The tabs run off the series filter rather than a second piece of state, so - * picking one narrows the list the same way the menu used to and the counts - * on the other filters stay honest. - */ - const ALL = ""; - const seriesTab = filters.series[0] ?? ALL; - const activeSeries = - admin.seriesList.find((series) => series.id === seriesTab) ?? null; - - const pickSeries = (id: string) => - setFilters((prev) => ({ ...prev, series: id === ALL ? [] : [id] })); /** * Counts come from the facet, so they already answer "how many are left in @@ -1058,13 +682,6 @@ export function ContentGroupsView() { ]; })(); - const templateTab = filters.template[0] ?? ALL; - const pickTemplate = (value: string) => - setFilters((prev) => ({ - ...prev, - template: value === ALL ? [] : [value], - })); - const railSeries: RailItem[] = [ { id: ALL, diff --git a/components/views/ContentResearcherView.tsx b/components/views/ContentResearcherView.tsx index bb42a32..37d7d1b 100644 --- a/components/views/ContentResearcherView.tsx +++ b/components/views/ContentResearcherView.tsx @@ -24,11 +24,11 @@ import { ghostHover, primary, rise, - spring, t, w, } from "@/lib/theme"; import { Hov } from "@/components/ui/Hov"; +import { FramePicker, clock } from "@/components/tools/FramePicker"; import { Button, Chip, @@ -39,12 +39,7 @@ import { TextInput, } from "@/components/ui"; import { BackGlyph, ClockGlyph } from "@/components/ui/DocIcons"; -import { - AlertIcon, - CheckIcon, - PlayIcon, - TrashIcon, -} from "@/components/ui/Icons"; +import { AlertIcon, PlayIcon, TrashIcon } from "@/components/ui/Icons"; /** * The researcher. @@ -78,12 +73,6 @@ function parseAt(text: string) { return seconds >= 0 ? seconds : null; } -const clock = (seconds: number) => { - const m = Math.floor(seconds / 60); - const s = Math.floor(seconds % 60); - return `${m}:${String(s).padStart(2, "0")}`; -}; - /** * The video this browser had open, remembered across reloads. * @@ -117,7 +106,8 @@ const nameOf = (row: Source) => row.title.trim() || row.filename.trim() || row.url.replace(/^https?:\/\//, ""); export function ContentResearcherView() { - const { go, project, seriesList, reloadSeries, askConfirm } = useStore(); + const { go, project, projectsLoaded, seriesList, reloadSeries, askConfirm } = + useStore(); const tool = findTool("content-researcher"); const [url, setUrl] = useState(""); @@ -238,8 +228,20 @@ export function ContentResearcherView() { }, }); + /* + * The same rule the run sheet keeps: nothing goes out against a workspace + * the server has not confirmed. Before the first request answers, `project` + * is a sample with an empty id, and an upload filed under "" is a + * foreign-key error wearing a generic message. + */ + const workspaceReady = projectsLoaded && Boolean(project?.id); + const fetchUrl = async () => { if (!url.trim() || fetching) return; + if (!workspaceReady) { + setError("Still loading the workspace — try again in a second."); + return; + } setFetching(true); setError(""); try { @@ -252,6 +254,10 @@ export function ContentResearcherView() { }; const upload = async (file: File) => { + if (!workspaceReady) { + setError("Still loading the workspace — try again in a second."); + return; + } setFetching(true); setError(""); try { @@ -488,283 +494,15 @@ export function ContentResearcherView() {
STEP 2 · WHAT IT LOOKS AT
-

- Pick the moments worth reading — the address bar, the result on - screen. Every picked frame is sent as a picture, so the right four - beat all eight. -

- - {/* - The strip, and the toolbar that acts on it. - - The count comes first, because "how many am I sending" is the - question the price of this run turns on. All and None sit beside it - rather than under the grid: picking eight things one at a time is - the work this screen exists to save. - */} -
- - {chosen.length} OF {frames.length} PICKED - - - - - - {/* - Adding a moment belongs here, not under the grid: it is the same - job as picking one — deciding what gets looked at — and it was - two rows away from the thing it adds to. - */} - - AT - setAt(e.target.value)} - onKeyDown={(e) => { - if (e.key === "Enter") void cutFrame(); - }} - placeholder="1:12" - aria-label="Cut a frame at this time" - style={{ - width: 54, - height: 24, - border: "none", - outline: "none", - background: "transparent", - fontFamily: font.mono, - fontSize: 12, - color: "#f0f0f4", - }} - /> - - -
- - {/* - The video as a line, with a node per frame. - - Eight thumbnails say what was captured; they do not say WHEN, and - "the bit where the address bar is up" is a question about time. The - track is the video, each node sits where it was taken, and clicking - one picks it — the same act as clicking its thumbnail, approached - from the other side. - */} - {frames.length && source.duration ? ( -
- - {frames.map((frame) => { - const on = picked.includes(frame.file); - const left = Math.min( - 100, - Math.max(0, (frame.at / (source.duration || 1)) * 100), - ); - return ( - - setPicked((list) => - on - ? list.filter((f) => f !== frame.file) - : [...list, frame.file], - ) - } - style={{ - position: "absolute", - left: left + "%", - top: on ? 5 : 7, - width: on ? 13 : 9, - height: on ? 13 : 9, - marginLeft: on ? -6.5 : -4.5, - borderRadius: "50%", - cursor: "pointer", - background: on ? "#0057fc" : w(0.22), - boxShadow: on ? "0 0 10px rgba(0,87,252,0.55)" : "none", - transition: "all 180ms " + spring, - }} - hover={{ background: on ? "#3b7bff" : w(0.4) }} - /> - ); - })} -
- ) : null} - - {frames.length ? ( -
- {frames.map((frame) => { - const on = picked.includes(frame.file); - return ( - - setPicked((list) => - on - ? list.filter((f) => f !== frame.file) - : [...list, frame.file], - ) - } - style={{ - position: "relative", - aspectRatio: "16 / 10", - borderRadius: 13, - overflow: "hidden", - cursor: "pointer", - background: "#0b0d12", - border: "1px solid " + (on ? "transparent" : w(0.08)), - /* - * A ring rather than a fat border: a 2px border on a - * 148px card reflows the picture inside it every time one - * is picked, and the whole grid twitches under the cursor. - */ - boxShadow: on - ? "0 0 0 2px #0057fc, 0 10px 24px -12px rgba(0,87,252,0.8)" - : "0 1px 2px rgba(0,0,0,0.35)", - transition: - "transform 180ms " + spring + ", box-shadow 180ms " + spring, - }} - hover={{ transform: "translateY(-2px)" }} - > - {/* eslint-disable-next-line @next/next/no-img-element */} - {"Frame - - - - - {clock(frame.at)} - - - - {on ? : null} - - - ); - })} -
- ) : ( -

- No frames were cut — the video itself was not downloaded, or - ffmpeg is off in Integrations. It can still read the transcript. -

- )} + void cutFrame()} + /> {notice ? (
diff --git a/components/views/DocumentView.tsx b/components/views/DocumentView.tsx index 702333c..8743437 100644 --- a/components/views/DocumentView.tsx +++ b/components/views/DocumentView.tsx @@ -20,18 +20,11 @@ import { type SectionState, } from "@/lib/content-docs"; import { useStore } from "@/lib/store"; -import { latestRunFor, runToDoc, topicSlug } from "@/lib/run-doc"; -import { getPack, type ApiPack } from "@/lib/packs-client"; +import { latestRunFor, topicSlug } from "@/lib/run-doc"; import { packForSeries } from "@/lib/packs"; -import { - editSection, - getRun, - isWriting, - startWriting, - type Run, - writeSection, -} from "@/lib/runs-client"; -import { frameUrl, getSource, type Source } from "@/lib/sources-client"; +import { editSection, startWriting, writeSection } from "@/lib/runs-client"; +import { useRunDocument } from "@/lib/use-run-document"; +import { frameUrl, type Source } from "@/lib/sources-client"; import { font, panel, primary, rise, t, w } from "@/lib/theme"; import { Hov } from "@/components/ui/Hov"; import { Button, Rail, TextArea } from "@/components/ui"; @@ -217,124 +210,26 @@ export function DocumentView({ slug?: string; runId?: string; }) { - const { - go, - seriesList, - runs, - packs, - reloadRuns, - settings, - runTopicNow, - } = useStore(); - - /* - * The run this page is about. - * - * Fetched directly when the URL names one, because a run started seconds ago - * is not in the store's list yet and waiting for a reload to notice it is - * the difference between watching your run and watching an empty page. - */ - const [fetched, setFetched] = useState(null); - - useEffect(() => { - if (!runId) return; - let cancelled = false; - void getRun(runId) - .then((r) => { - if (!cancelled) setFetched(r); - }) - .catch(() => {}); - return () => { - cancelled = true; - }; - }, [runId]); - - const run = useMemo(() => { - /* - * The polled copy wins here too. - * - * This read the store's list first, and that list is loaded once and - * reloaded on navigation — never on a timer. So /runs/ rendered a - * snapshot taken when the page was opened, the poll below kept a fresh - * copy in `fetched` that nothing looked at, and the only way to see any - * progress was to reload the page. Which is exactly what it looked like: - * live updates that only arrive on a refresh. - */ - if (runId) { - return fetched?.id === runId - ? fetched - : (runs.find((r) => r.id === runId) ?? fetched); - } - const topic = seriesList - .flatMap((series) => series.topics) - .find((t) => topicSlug(t.name) === slug); - const latest = topic ? latestRunFor(runs, topic.id) : null; - /* - * The polled copy wins, when it is the same run. - * - * /content/ reads the store's list, which is reloaded on navigation - * and not on a timer — so a run started from this page wrote twelve - * sections while the page it was started from showed twelve queued ones. - * The poll below keeps `fetched` current for whichever run is on screen; - * this is where that gets used. - */ - return latest && fetched?.id === latest.id ? fetched : latest; - }, [runId, fetched, runs, seriesList, slug]); + const { go, seriesList, runs, packs, reloadRuns, settings, runTopicNow } = + useStore(); - /* - * The template as the engine runs it. - * - * The store's copy is the builder's shape and carries no dependency arrows, - * and those are what decide which section may go next. Fetched by slug so a - * template written in the builder works here too. + /** + * The run, its template, its topic, the document and the reel — resolved + * from whichever address this page was opened by. See + * lib/use-run-document.ts, which is also where the polled copy is made to + * win over the store's list. */ - const [runtime, setRuntime] = useState(null); - - useEffect(() => { - const packSlug = run?.packSlug; - if (!packSlug) return; - let cancelled = false; - void getPack(packSlug) - .then((p) => { - if (!cancelled) setRuntime(p); - }) - .catch(() => {}); - return () => { - cancelled = true; - }; - }, [run?.packSlug]); - - /** The topic behind it, for the rail and for the empty states. */ - const topic = useMemo( - () => - seriesList - .flatMap((series) => series.topics.map((t) => ({ ...t, series }))) - .find((t) => (runId ? t.id === run?.topicId : topicSlug(t.name) === slug)), - [seriesList, slug, runId, run], - ); - - const doc = useMemo( - () => - run ? runToDoc(run, packs.find((p) => p.id === run.packSlug)) : null, - [run, packs], - ); - - /** The reel this run was given, when it was given one. */ - const [source, setSource] = useState(null); - - useEffect(() => { - const sid = run?.sourceId; - if (!sid) return; - let cancelled = false; - void getSource(sid) - .then((x) => { - if (!cancelled) setSource(x); - }) - .catch(() => {}); - return () => { - cancelled = true; - }; - }, [run?.sourceId]); + const { + run, + topic, + doc, + source, + pending, + unwritten, + setFetched, + serverWriting, + setServerWriting, + } = useRunDocument({ slug, runId }); const [openSections, setOpenSections] = useState>( new Set(["03"]), @@ -368,36 +263,6 @@ export function DocumentView({ const groups = useMemo(() => (doc ? buildGroups(doc) : []), [doc]); const [reading, setReading] = useState(false); - /* - * Sections that have not been written yet, in the template's own order. - * - * A dependency is satisfied when the section it names is done, so this is - * recomputed from the run every time rather than held as a queue: a section - * rewritten by hand changes what is ready next, and a queue built once would - * not notice. - */ - const pending = useMemo(() => { - if (!run || !runtime) return []; - const done = new Set( - run.sections.filter((x) => x.state === "done").map((x) => x.id), - ); - return runtime.sections - .filter((def) => { - const row = run.sections.find((x) => x.id === def.id); - return ( - row && row.state !== "done" && def.dependsOn.every((d) => done.has(d)) - ); - }) - .map((def) => def.id); - }, [run, runtime]); - - const unwritten = run - ? run.sections.filter((x) => x.state !== "done").length - : 0; - - /** Set while the server is writing this run — see the polling effect. */ - const [serverWriting, setServerWriting] = useState(false); - /** * Is it writing, waiting, or stopped? * @@ -513,7 +378,7 @@ export function DocumentView({ }); } await reloadRuns(); - }, [run, doc, runId, reloadRuns]); + }, [run, doc, runId, reloadRuns, setFetched]); // The local driver, for "Write next" and for the auto-approve preference. // The whole-run case is the server's job now — see `serverWriting` below. @@ -524,55 +389,6 @@ export function DocumentView({ // eslint-disable-next-line react-hooks/exhaustive-deps }, [auto, run, pending, busy.size]); - /** - * Whether the server is writing this run, and following it while it does. - * - * The page used to BE the driver: a loop in the tab asking for one section - * at a time. A run therefore stopped when the tab did — on a navigation, a - * hot reload, or a closed window — mid-way, with no sign of why. The server - * drives now, so this only watches: poll the run while anything is moving, - * stop when it settles. - * - * Whichever way the page was addressed. It watched only /runs/, so a - * topic opened by name — which is how the list opens one — sat perfectly - * still while its run was being written, and only a refresh showed any of - * it. The run is the run either way. - */ - const watchId = runId ?? run?.id ?? null; - useEffect(() => { - if (!watchId) return; - let stop = false; - - const tick = async () => { - try { - const [state, fresh] = await Promise.all([ - isWriting(watchId), - getRun(watchId), - ]); - if (stop) return; - setServerWriting(state.running); - if (fresh) setFetched(fresh); - // Slower once nothing is in flight: the answer stops changing, and a - // page left open overnight should not be asking twice a second. - return state.running ? 1500 : 6000; - } catch { - return 6000; - } - }; - - let timer: ReturnType; - const loop = async () => { - const wait = (await tick()) ?? 6000; - if (!stop) timer = setTimeout(() => void loop(), wait); - }; - void loop(); - - return () => { - stop = true; - clearTimeout(timer); - }; - }, [watchId]); - /** Write the lot, on the server, and start watching straight away. */ const writeEverything = useCallback(async () => { if (!run) return; @@ -582,7 +398,7 @@ export function DocumentView({ } catch { setServerWriting(false); } - }, [run]); + }, [run, setServerWriting]); /* * Two ways to have nothing to show, and they are different problems. diff --git a/components/views/SettingsView.tsx b/components/views/SettingsView.tsx index 67d9c0e..3ff00c5 100644 --- a/components/views/SettingsView.tsx +++ b/components/views/SettingsView.tsx @@ -1,5 +1,6 @@ "use client"; +import { apiFetch } from "@/lib/api-base"; import { useEffect, useState, type ReactNode } from "react"; import { useRouter } from "next/navigation"; @@ -397,11 +398,11 @@ function Account({ const [error, setError] = useState(""); const refresh = () => { - void fetch("/api/auth/me", { cache: "no-store" }) + void apiFetch("/api/auth/me", { cache: "no-store" }) .then((r) => r.json()) .then((b: { user?: typeof me }) => setMe(b.user ?? null)) .catch(() => {}); - void fetch("/api/auth/sessions", { cache: "no-store" }) + void apiFetch("/api/auth/sessions", { cache: "no-store" }) .then((r) => (r.ok ? r.json() : [])) .then(setSessions) .catch(() => {}); @@ -409,13 +410,13 @@ function Account({ useEffect(() => { let cancelled = false; - void fetch("/api/auth/me", { cache: "no-store" }) + void apiFetch("/api/auth/me", { cache: "no-store" }) .then((r) => r.json()) .then((b: { user?: typeof me }) => { if (!cancelled) setMe(b.user ?? null); }) .catch(() => {}); - void fetch("/api/auth/sessions", { cache: "no-store" }) + void apiFetch("/api/auth/sessions", { cache: "no-store" }) .then((r) => (r.ok ? r.json() : [])) .then((rows: Session[]) => { if (!cancelled) setSessions(rows); @@ -429,7 +430,7 @@ function Account({ async function changePassword() { setError(""); setMessage(""); - const res = await fetch("/api/auth/password", { + const res = await apiFetch("/api/auth/password", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ current, next }), @@ -459,7 +460,7 @@ function Account({ >