I think I fixed it
Signed-off-by: Xe Iaso <me@xeiaso.net>
This commit is contained in:
parent
473b33ff59
commit
f950a2e0ff
File diff suppressed because it is too large
Load Diff
|
@ -21,18 +21,22 @@
|
|||
},
|
||||
"homepage": "https://tulpa.dev/cadey/yasomi",
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.15.11",
|
||||
"@types/express": "^4.17.17",
|
||||
"@types/node": "^18.16.0",
|
||||
"husky": "^8.0.3",
|
||||
"lint-staged": "^13.2.1",
|
||||
"mocha": "^10.2.0",
|
||||
"prettier": "2.8.7",
|
||||
"typescript": "^4.9.5"
|
||||
"typescript": "^4.9.5",
|
||||
"typescript-json-schema": "^0.56.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@atproto/api": "^0.2.8",
|
||||
"ajv": "^8.12.0",
|
||||
"commander": "^10.0.0",
|
||||
"dotenv": "^16.0.3",
|
||||
"execa": "^7.1.1",
|
||||
"express": "^4.18.2",
|
||||
"read-pkg": "^8.0.0"
|
||||
},
|
||||
"lint-staged": {
|
||||
|
|
62
src/index.ts
62
src/index.ts
|
@ -1,8 +1,19 @@
|
|||
import * as dotenv from "dotenv";
|
||||
import express from "express";
|
||||
import _Ajv from "ajv";
|
||||
const Ajv = _Ajv as unknown as typeof _Ajv.default;
|
||||
|
||||
import { CreatePostRequest, CreatePostRequestSchema } from "./types.js";
|
||||
|
||||
import bsky from "@atproto/api";
|
||||
const { BskyAgent, RichText } = bsky;
|
||||
|
||||
const ajv = new Ajv({ allErrors: true });
|
||||
|
||||
const valid = {
|
||||
CreatePostRequest: ajv.compile(CreatePostRequestSchema),
|
||||
};
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const agent = new BskyAgent({
|
||||
|
@ -13,12 +24,45 @@ await agent.login({
|
|||
password: process.env.BLUESKY_PASSWORD as string,
|
||||
});
|
||||
|
||||
const rt = new RichText({ text: "Hello Bluesky!" });
|
||||
await rt.detectFacets(agent);
|
||||
const postRecord = {
|
||||
$type: "app.bsky.feed.post",
|
||||
text: rt.text,
|
||||
facets: rt.facets,
|
||||
createdAt: new Date().toISOString(),
|
||||
};
|
||||
await agent.post(postRecord);
|
||||
const app: express.Application = express();
|
||||
const port: number = 3000;
|
||||
|
||||
app.get("/", async (_req, resp) => {
|
||||
resp.send("Yasomi online.");
|
||||
});
|
||||
|
||||
app.post("/create", express.json(), async (req, resp) => {
|
||||
if (!valid.CreatePostRequest(req.body)) {
|
||||
resp.status(400);
|
||||
resp.json({
|
||||
errors: valid.CreatePostRequest.errors,
|
||||
});
|
||||
return;
|
||||
}
|
||||
const cpr = req.body as unknown as CreatePostRequest;
|
||||
|
||||
const rt = new RichText({ text: cpr.body });
|
||||
await rt.detectFacets(agent);
|
||||
|
||||
if (rt.graphemeLength > 300) {
|
||||
resp.status(400);
|
||||
resp.json({
|
||||
errors: ["message must be less than 300 characters"],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const postRecord = {
|
||||
$type: "app.bsky.feed.post",
|
||||
text: rt.text,
|
||||
facets: rt.facets,
|
||||
createdAt: new Date().toISOString(),
|
||||
};
|
||||
const postData = await agent.post(postRecord);
|
||||
|
||||
resp.json({ atProto: postData });
|
||||
});
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log("http://pneuma:3000");
|
||||
});
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
export interface CreatePostRequest {
|
||||
body: string;
|
||||
}
|
||||
|
||||
import CreatePostRequestSchema from "./types/CreatePostRequest.json" assert { type: "json" };
|
||||
export { CreatePostRequestSchema };
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"properties": {
|
||||
"body": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["body"],
|
||||
"type": "object"
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
"preserveConstEnums": true,
|
||||
"moduleResolution": "node16",
|
||||
"strict": true,
|
||||
"resolveJsonModule": true,
|
||||
"sourceMap": true,
|
||||
"target": "esnext",
|
||||
"types": ["node"],
|
||||
|
|
Loading…
Reference in New Issue