Compare commits

..

2 Commits

Author SHA1 Message Date
Moon Man d8911be6ea rm redundant check, use object build function 2024-01-01 08:10:45 -05:00
Moon Man 677e8c9b27 smarter delete activity id 2024-01-01 08:04:09 -05:00
1 changed files with 4 additions and 27 deletions

View File

@ -161,7 +161,7 @@ export const deleteArticleActivity = (article: Article, user: User) => {
const canonicalUrl = `https://${process.env.blog_host}/${article.slug}.html`; const canonicalUrl = `https://${process.env.blog_host}/${article.slug}.html`;
const activity: Record<string, any> = { const activity: Record<string, any> = {
id: fillRoute("activity", article.id + 1_000_000_000), id: fillRoute("activity", article.id) + "/delete",
"@context": CONTEXT, "@context": CONTEXT,
summary: `${user.nickname} deleted article ${canonicalUrl}`, summary: `${user.nickname} deleted article ${canonicalUrl}`,
type: "Delete", type: "Delete",
@ -177,8 +177,7 @@ export const deleteArticleActivity = (article: Article, user: User) => {
export const createArticleActivity = (article: Article, user: User) => { export const createArticleActivity = (article: Article, user: User) => {
const actor = fillRoute("actor", user.nickname); const actor = fillRoute("actor", user.nickname);
const published = typeof article.created_at === "number" ? new Date(article.created_at) : article.created_at; const published = article.created_at;
const canonicalUrl = `https://${process.env.blog_host}/${article.slug}.html`;
const context = fillRoute("context", article.id); const context = fillRoute("context", article.id);
const followers = fillRoute("followers", user.nickname); const followers = fillRoute("followers", user.nickname);
const activity: Record<string, any> = { const activity: Record<string, any> = {
@ -192,29 +191,7 @@ export const createArticleActivity = (article: Article, user: User) => {
published published
}; };
const objectId = fillRoute("object", article.id); activity.object = createArticleObject(article, user.nickname);
const content = readFileSync(article.file as string, "utf-8") + `
[Read on site](${canonicalUrl})
`;
activity.object = {
id: objectId,
actor,
attributedTo: actor,
type: "Note",
context,
content: md.render(content),
to: [PUBLIC],
cc: [followers],
url: canonicalUrl,
mediaType: "text/html",
source: {
mediaType: "text/markdown",
content
},
published
};
return activity; return activity;
}; };
@ -230,7 +207,7 @@ export const createArticleObject = (article: Article, nickname: string) => {
[Read on site](${canonicalUrl}) [Read on site](${canonicalUrl})
`; `;
const published = typeof article.created_at === "number" ? new Date(article.created_at) : article.created_at; const published = article.created_at;
const followers = fillRoute("followers", nickname); const followers = fillRoute("followers", nickname);