26 lines
573 B
TypeScript
26 lines
573 B
TypeScript
import { noteVisibilities } from "@/types.js";
|
|
|
|
export type Post = {
|
|
text: string | undefined;
|
|
cw: string | null;
|
|
localOnly: boolean;
|
|
createdAt: Date;
|
|
visibility: string;
|
|
};
|
|
|
|
export function parse(acct: any): Post {
|
|
return {
|
|
text: acct.text || undefined,
|
|
cw: acct.cw,
|
|
localOnly: acct.localOnly,
|
|
createdAt: new Date(acct.createdAt),
|
|
visibility: noteVisibilities.includes(acct.visibility)
|
|
? acct.visibility
|
|
: "public",
|
|
};
|
|
}
|
|
|
|
export function toJson(acct: Post): string {
|
|
return { text: acct.text, cw: acct.cw, localOnly: acct.localOnly }.toString();
|
|
}
|