extract out post URLs

Signed-off-by: Xe Iaso <me@xeiaso.net>
This commit is contained in:
Cadey Ratio 2023-04-24 19:35:10 -04:00
parent f950a2e0ff
commit a1779cbbda
1 changed files with 11 additions and 3 deletions

View File

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