firefish/packages/backend/src/misc/post.ts

22 lines
480 B
TypeScript
Raw Normal View History

2023-03-28 21:29:47 +00:00
export type Post = {
text: string | undefined;
2023-03-28 21:29:47 +00:00
cw: string | null;
localOnly: boolean;
createdAt: Date;
visibility: string;
2023-03-28 21:29:47 +00:00
};
export function parse(acct: any): Post {
2023-03-31 02:10:03 +00:00
return {
text: acct.text || undefined,
2023-03-31 02:10:03 +00:00
cw: acct.cw,
localOnly: acct.localOnly,
createdAt: new Date(acct.createdAt),
visibility: `hidden${acct.visibility || ""}`,
2023-03-31 02:10:03 +00:00
};
2023-03-28 21:29:47 +00:00
}
export function toJson(acct: Post): string {
return { text: acct.text, cw: acct.cw, localOnly: acct.localOnly }.toString();
}