From a1779cbbda6fe87d2e6831217018a8eb16f39ba7 Mon Sep 17 00:00:00 2001 From: Xe Iaso Date: Mon, 24 Apr 2023 19:35:10 -0400 Subject: [PATCH] extract out post URLs Signed-off-by: Xe Iaso --- src/index.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 92a4c04..8af7b17 100644 --- a/src/index.ts +++ b/src/index.ts @@ -31,7 +31,7 @@ app.get("/", async (_req, resp) => { resp.send("Yasomi online."); }); -app.post("/create", express.json(), async (req, resp) => { +app.post("/create", express.json(), async (req, resp, next) => { if (!valid.CreatePostRequest(req.body)) { resp.status(400); resp.json({ @@ -58,9 +58,17 @@ app.post("/create", express.json(), async (req, resp) => { facets: rt.facets, createdAt: new Date().toISOString(), }; - const postData = await agent.post(postRecord); - resp.json({ atProto: postData }); + try { + const postData = await agent.post(postRecord); + const [_, did, __, postID] = postData.uri.split( + /^at:\/\/(.+)\/(.+)\/(.+)$/ + ); + const url = `https://staging.bsky.app/profile/${did}/post/${postID}`; + resp.json({ atProto: postData, input: cpr, url }); + } catch (error) { + next(error); + } }); app.listen(port, () => {