add like share almost works

This commit is contained in:
Moon Man 2023-12-31 20:39:05 +00:00
parent 22b30655d1
commit 05591df126
3 changed files with 12 additions and 4 deletions

View File

@ -45,15 +45,20 @@ export const handleInboxPost = async (req: Request, res: Response) => {
return;
}
else if (activity.type === "Like") {
const articleId = reverseRoute("object", req.path);
const articleId = reverseRoute("object", activity.object);
console.log("article id", articleId);
if (articleId) {
const article = await getArticleById(parseInt(articleId));
if (article) {
console.log("found article");
const user = await getUserById(article.users_id);
if (user) {
console.log("found article author");
const init: SignedInit = {
keyId: getKeyId(user.nickname),
privateKey: user.private_key
@ -62,6 +67,7 @@ export const handleInboxPost = async (req: Request, res: Response) => {
const liker = await getActor(activity.actor, init);
if (liker) {
console.log("successfully queried liker");
await addLikeOrShare(article.id, liker, 1);
res.status(201).end();
@ -73,7 +79,9 @@ export const handleInboxPost = async (req: Request, res: Response) => {
}
}
console.error("could not do like");
res.status(403).end();
return;
}
else if (activity.type === "Follow") {
console.log(JSON.stringify(activity, null, 4));

View File

@ -77,5 +77,5 @@ export const addLikeOrShare = async (articleId: number, person: Actor, likeOrSha
.onConflict().ignore()
;
console.log("Follower added");
console.log("Like/Share added");
};

View File

@ -19,7 +19,7 @@ export const fillRoute = (route: Route, value: number | string) =>
;
export const reverseRoute = (route: Route, path: string) => {
const r = new RegExp("^" + Routes[route].replace(/:(id|actor)/, "(.+)") + "$");
const r = new RegExp(Routes[route].replace(/:(id|actor)/, "(.+)") + "$");
const match = path.match(r)
return !!match ? match[1] : null;
};