Loading backend/src/lib/api_admin.ts +32 −0 Original line number Diff line number Diff line import { Router } from "express"; import { prisma } from "./prisma.js"; import { AuthSession } from "../controllers/AuthSession.js"; import { APub } from "./apub/utils.js"; const app = Router(); Loading @@ -15,6 +17,36 @@ app.use((req, res, next) => { next(); }); /** * Create AuthSession for specified handle and send verification code to user * The created session is returned as a response * Used for live testing DMs */ app.post("/create_auth_for", async (req, res) => { if ( !req.query.handle || typeof req.query.handle !== "string" || req.query.handle.indexOf("@") <= 0 ) { res.status(400).send("?handle is not valid (localpart@instance.domain)"); return; } const [localpart, instance] = req.query.handle.split("@"); const session = await AuthSession.create(`${localpart}@${instance}`); try { await APub.sendDM(session); } catch (e) { console.error("/create_auth_for failed for " + req.query.handle, e); await prisma.authSession.delete({ where: { id: session.id } }); res.status(500).send("Failed to send DM: " + e); } res.status(201).json({ success: true, session }); }); app.get("/status", async (req, res) => { const completed = await prisma.fediverseUser.count({ where: { Loading Loading
backend/src/lib/api_admin.ts +32 −0 Original line number Diff line number Diff line import { Router } from "express"; import { prisma } from "./prisma.js"; import { AuthSession } from "../controllers/AuthSession.js"; import { APub } from "./apub/utils.js"; const app = Router(); Loading @@ -15,6 +17,36 @@ app.use((req, res, next) => { next(); }); /** * Create AuthSession for specified handle and send verification code to user * The created session is returned as a response * Used for live testing DMs */ app.post("/create_auth_for", async (req, res) => { if ( !req.query.handle || typeof req.query.handle !== "string" || req.query.handle.indexOf("@") <= 0 ) { res.status(400).send("?handle is not valid (localpart@instance.domain)"); return; } const [localpart, instance] = req.query.handle.split("@"); const session = await AuthSession.create(`${localpart}@${instance}`); try { await APub.sendDM(session); } catch (e) { console.error("/create_auth_for failed for " + req.query.handle, e); await prisma.authSession.delete({ where: { id: session.id } }); res.status(500).send("Failed to send DM: " + e); } res.status(201).json({ success: true, session }); }); app.get("/status", async (req, res) => { const completed = await prisma.fediverseUser.count({ where: { Loading