Something went wrong. Try again.
Paper Mario mod hosting site - AT Protocol appview starhaven.dev
appview
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100#!/usr/bin/env nodeimport { randomBytes } from "node:crypto";import fs from "node:fs/promises";import path from "node:path";
import { TestNetworkNoAppView } from "@atproto/dev-env";
const plcPort = Number(process.env.PLC_PORT ?? 2582);const pdsPort = Number(process.env.PDS_PORT ?? 2583);
// If DEV_PDS_STATE names a directory, the PDS's accounts and the PLC// directory's DIDs persist there across restarts, so the default account// keeps its DID. Without it, as in tests, both start empty every time.const stateDir = process.env.DEV_PDS_STATE;const pds = { port: pdsPort, hostname: "localhost" };if (stateDir) { await fs.mkdir(path.join(stateDir, "pds"), { recursive: true }); Object.assign(pds, { dataDirectory: path.join(stateDir, "pds"), blobstoreDiskLocation: path.join(stateDir, "blobs"), // Signs every later change to its accounts' DIDs, so it has to be // the same key that signed their creation. plcRotationKeyK256PrivateKeyHex: await readOrCreate( path.join(stateDir, "plc-rotation-key"), () => randomBytes(32).toString("hex"), ), });}
const network = await TestNetworkNoAppView.create({ plc: { port: plcPort }, pds,});
if (stateDir) await persistPlc(network.plc.server.ctx.db, path.join(stateDir, "plc-ops.jsonl"));
console.log(`dev-pds: PLC directory at ${network.plc.url}`);console.log(`dev-pds: PDS at ${network.pds.url}`);
// Tranquil PDS, which pds.starhaven.dev runs, answers whether an email// address has an account, for sign-up. This PDS doesn't, so it's added here,// in front of every other route.const server = network.pds.server.server;const [app] = server.listeners("request");server.removeAllListeners("request");server.on("request", async (req, res) => { if (req.method !== "POST" || !req.url.startsWith("/xrpc/_account.checkEmailInUse")) { return app(req, res); } let body = ""; for await (const chunk of req) body += chunk; const { email } = JSON.parse(body); const account = await network.pds.ctx.accountManager.getAccountByEmail( email.trim().toLowerCase(), ); res.setHeader("content-type", "application/json"); res.end(JSON.stringify({ inUse: account !== null }));});
const email = "alice@dev.test";const existing = await network.pds.ctx.accountManager.getAccountByEmail(email);const account = existing ?? (await network.getSeedClient().createAccount("alice", { handle: "alice.test", email, password: "hunter2", }));console.log(`dev-pds: default account ${account.handle} (${account.did}), password "hunter2"`);
const shutdown = () => network.close().then(() => process.exit(0));process.on("SIGINT", shutdown);process.on("SIGTERM", shutdown);
// Reads `file`, first writing `create()`'s result to it if it doesn't exist.async function readOrCreate(file, create) { try { return (await fs.readFile(file, "utf8")).trim(); } catch { const value = create(); await fs.writeFile(file, value, { mode: 0o600 }); return value; }}
// Replays the operations saved in `file` into `db`, the PLC directory's// in-memory database, and saves each new one there too.async function persistPlc(db, file) { const saved = await fs.readFile(file, "utf8").catch(() => ""); for (const line of saved.split("\n").filter(Boolean)) { const { did, operation } = JSON.parse(line); await db.validateAndAddOp(did, operation); } const validateAndAddOp = db.validateAndAddOp.bind(db); db.validateAndAddOp = async (did, operation) => { await validateAndAddOp(did, operation); await fs.appendFile(file, `${JSON.stringify({ did, operation })}\n`); };}