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",
|
"homepage": "https://tulpa.dev/cadey/yasomi",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^18.15.11",
|
"@types/express": "^4.17.17",
|
||||||
|
"@types/node": "^18.16.0",
|
||||||
"husky": "^8.0.3",
|
"husky": "^8.0.3",
|
||||||
"lint-staged": "^13.2.1",
|
"lint-staged": "^13.2.1",
|
||||||
"mocha": "^10.2.0",
|
"mocha": "^10.2.0",
|
||||||
"prettier": "2.8.7",
|
"prettier": "2.8.7",
|
||||||
"typescript": "^4.9.5"
|
"typescript": "^4.9.5",
|
||||||
|
"typescript-json-schema": "^0.56.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@atproto/api": "^0.2.8",
|
"@atproto/api": "^0.2.8",
|
||||||
|
"ajv": "^8.12.0",
|
||||||
"commander": "^10.0.0",
|
"commander": "^10.0.0",
|
||||||
"dotenv": "^16.0.3",
|
"dotenv": "^16.0.3",
|
||||||
"execa": "^7.1.1",
|
"execa": "^7.1.1",
|
||||||
|
"express": "^4.18.2",
|
||||||
"read-pkg": "^8.0.0"
|
"read-pkg": "^8.0.0"
|
||||||
},
|
},
|
||||||
"lint-staged": {
|
"lint-staged": {
|
||||||
|
|
62
src/index.ts
62
src/index.ts
|
@ -1,8 +1,19 @@
|
||||||
import * as dotenv from "dotenv";
|
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";
|
import bsky from "@atproto/api";
|
||||||
const { BskyAgent, RichText } = bsky;
|
const { BskyAgent, RichText } = bsky;
|
||||||
|
|
||||||
|
const ajv = new Ajv({ allErrors: true });
|
||||||
|
|
||||||
|
const valid = {
|
||||||
|
CreatePostRequest: ajv.compile(CreatePostRequestSchema),
|
||||||
|
};
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
const agent = new BskyAgent({
|
const agent = new BskyAgent({
|
||||||
|
@ -13,12 +24,45 @@ await agent.login({
|
||||||
password: process.env.BLUESKY_PASSWORD as string,
|
password: process.env.BLUESKY_PASSWORD as string,
|
||||||
});
|
});
|
||||||
|
|
||||||
const rt = new RichText({ text: "Hello Bluesky!" });
|
const app: express.Application = express();
|
||||||
await rt.detectFacets(agent);
|
const port: number = 3000;
|
||||||
const postRecord = {
|
|
||||||
$type: "app.bsky.feed.post",
|
app.get("/", async (_req, resp) => {
|
||||||
text: rt.text,
|
resp.send("Yasomi online.");
|
||||||
facets: rt.facets,
|
});
|
||||||
createdAt: new Date().toISOString(),
|
|
||||||
};
|
app.post("/create", express.json(), async (req, resp) => {
|
||||||
await agent.post(postRecord);
|
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,
|
"preserveConstEnums": true,
|
||||||
"moduleResolution": "node16",
|
"moduleResolution": "node16",
|
||||||
"strict": true,
|
"strict": true,
|
||||||
|
"resolveJsonModule": true,
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"target": "esnext",
|
"target": "esnext",
|
||||||
"types": ["node"],
|
"types": ["node"],
|
||||||
|
|
Loading…
Reference in New Issue