Queue executable speed and peer-to-peer sharing plans with tested patches and harnesses
This commit is contained in:
29
plans/harness/intake-server.js
Normal file
29
plans/harness/intake-server.js
Normal file
@@ -0,0 +1,29 @@
|
||||
// Plan 016 harness: routes + intake with real validateMedia (needs ffmpeg).
|
||||
// Run from server/: bun ../plans/harness/intake-server.js
|
||||
const { Hono } = await import(process.cwd() + '/node_modules/hono/dist/index.js');
|
||||
import { mkdtempSync, readFileSync } from 'node:fs';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
const root = mkdtempSync(join(tmpdir(), 'ytp-h16-'));
|
||||
process.env.DB_PATH = join(root, 'h.db');
|
||||
const dbmod = await import(process.cwd() + '/db.js');
|
||||
const p2pDb = await import(process.cwd() + '/p2p-db.js');
|
||||
const { registerP2pRoutes } = await import(process.cwd() + '/p2p-routes.js');
|
||||
const { registerIntakeRoutes } = await import(process.cwd() + '/p2p-intake.js');
|
||||
const { admitFile } = await import(process.cwd() + '/p2p-admit.js');
|
||||
const { validateMedia } = await import(process.cwd() + '/media-cache.js');
|
||||
const FE = process.env.FE_DIR || new URL('../../frontend', import.meta.url).pathname;
|
||||
await dbmod.initDb(); await p2pDb.initP2pSchema();
|
||||
const fx = join(root, 'fx.mp4');
|
||||
spawnSync('ffmpeg', ['-v', 'error', '-y', '-f', 'lavfi', '-i', 'testsrc=size=320x180:rate=25:duration=4', '-f', 'lavfi', '-i', 'sine=frequency=440:duration=4',
|
||||
'-c:v', 'libx264', '-preset', 'ultrafast', '-pix_fmt', 'yuv420p', '-c:a', 'aac', '-shortest', '-movflags', '+faststart', fx]);
|
||||
const cfg = { enabled: true, malwareScan: false, scanCmd: 'true', staleDays: 7, intakeDir: join(root, 'intake'), intakeMaxBytes: 50e6 };
|
||||
const app = new Hono();
|
||||
const p2p = registerP2pRoutes(app, { cfg, p2pDb, fileForCid: async () => null, sha256Range: async () => '' });
|
||||
registerIntakeRoutes(app, { cfg, p2pDb, gate: p2p.gate, requireDevice: p2p.requireDevice, validateMedia, admitFile });
|
||||
app.get('/fixture.mp4', () => new Response(readFileSync(fx)));
|
||||
app.get('/', (c) => c.html('<!doctype html><script src="/opfs.js"></script><script src="/sha256.js"></script><script src="/device-db.js"></script><script src="/p2p-client.js"></script>'));
|
||||
app.get('/:f', (c) => new Response(Bun.file(FE + '/' + c.req.param('f')), { headers: { 'Content-Type': 'text/javascript' } }));
|
||||
Bun.serve({ port: 8769, fetch: app.fetch });
|
||||
console.log('ready');
|
||||
Reference in New Issue
Block a user