Queue executable speed and peer-to-peer sharing plans with tested patches and harnesses
This commit is contained in:
17
plans/harness/device-db-server.js
Normal file
17
plans/harness/device-db-server.js
Normal file
@@ -0,0 +1,17 @@
|
||||
// Plan 012 harness: serves ../../frontend plus fake /api/download/<id> responses
|
||||
// (good hash / wrong hash / no hash). Run: bun device-db-server.js
|
||||
import { createHash } from 'node:crypto';
|
||||
const FE = new URL('../../frontend/', import.meta.url).pathname;
|
||||
const body = new Uint8Array(3 * 1024 * 1024 + 123).map((_, i) => (i * 7) % 256);
|
||||
const sha = createHash('sha256').update(body).digest('hex');
|
||||
Bun.serve({ port: 8766, fetch(req) {
|
||||
const u = new URL(req.url);
|
||||
if (u.pathname === '/api/download/good') return new Response(body, { headers: { 'Content-Type': 'video/mp4', 'Content-Length': String(body.length), 'X-Content-SHA256': sha } });
|
||||
if (u.pathname === '/api/download/bad') return new Response(body, { headers: { 'Content-Type': 'video/mp4', 'Content-Length': String(body.length), 'X-Content-SHA256': 'f'.repeat(64) } });
|
||||
if (u.pathname === '/api/download/nohash') return new Response(body, { headers: { 'Content-Type': 'video/mp4', 'Content-Length': String(body.length) } });
|
||||
if (u.pathname === '/sha') return new Response(sha);
|
||||
if (u.pathname === '/') return new Response('<!doctype html><script src="/opfs.js"></script><script src="/sha256.js"></script><script src="/device-db.js"></script>', { headers: { 'Content-Type': 'text/html' } });
|
||||
const f = Bun.file(FE + u.pathname.slice(1));
|
||||
return new Response(f, { headers: { 'Content-Type': 'text/javascript' } });
|
||||
} });
|
||||
console.log('ready');
|
||||
Reference in New Issue
Block a user