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, () => {