- The messages' YouTube thumbnails are served from the site (/api/thumbnails/<id>.jpg): the backend fetches a message's thumbnail once and keeps it in uploads/.thumbnails (only the site's own videos, only a JPEG), so visitors ask nothing of YouTube before pressing play. The messages page preloads the first one (its LCP: Heritage 89 -> 95). - Calendar events' dates read "Sun · November", not "Sun (month: November)". - e2e: no request to YouTube or Spotify before play; the variant screenshots round section heights to whole pixels (a one-pixel flake); the e2e thumbnail is one of the demo's illustrations. - crosscode script: a Website's export leaves out uploads/.thumbnails. - docs: release checks on 1.0.1, VERSIONS, handover. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
/**
|
|
* Everything a request handler or job needs, passed in rather than imported, so tests can run the
|
|
* whole app against an in-memory database and a stand-in Accounts (tests/support/).
|
|
*/
|
|
import type { PrismaClient } from './generated/prisma/client.js';
|
|
import type { Config } from './lib/config.js';
|
|
import { Secrets } from './lib/crypto.js';
|
|
import { Settings } from './lib/settings.js';
|
|
import { loadAuthClient, type AuthClientModule } from './auth/accounts.js';
|
|
|
|
export type Db = PrismaClient;
|
|
|
|
export type Ctx = {
|
|
config: Config;
|
|
db: Db;
|
|
secrets: Secrets;
|
|
settings: Settings;
|
|
/** `@crosscode/auth-client` (tests give a stand-in). */
|
|
authClient: () => Promise<AuthClientModule>;
|
|
now: () => Date;
|
|
/** Fetches what visitors are shown from outside (YouTube's thumbnails); tests give a stand-in. */
|
|
fetch?: (url: string) => Promise<Response>;
|
|
};
|
|
|
|
export function createCtx(config: Config, db: Db, opts: { now?: () => Date; authClient?: () => Promise<AuthClientModule>; fetch?: (url: string) => Promise<Response> } = {}): Ctx {
|
|
const secrets = new Secrets(config.secret);
|
|
const partial = { config, db, secrets } as Ctx;
|
|
partial.settings = new Settings(partial);
|
|
partial.authClient = opts.authClient ?? loadAuthClient;
|
|
partial.now = opts.now ?? (() => new Date());
|
|
if (opts.fetch) partial.fetch = opts.fetch;
|
|
return partial;
|
|
}
|