server/utils/content_types.ts
2024-04-06 19:30:49 -10:00

22 lines
868 B
TypeScript

import type { ContentFormat } from "~types/lysand/Object";
export const getBestContentType = (contents: ContentFormat[]) => {
// Find the best content and content type
if (contents.find((c) => c.content_type === "text/x.misskeymarkdown")) {
return (
contents.find((c) => c.content_type === "text/x.misskeymarkdown") ||
null
);
}
if (contents.find((c) => c.content_type === "text/html")) {
return contents.find((c) => c.content_type === "text/html") || null;
}
if (contents.find((c) => c.content_type === "text/markdown")) {
return contents.find((c) => c.content_type === "text/markdown") || null;
}
if (contents.find((c) => c.content_type === "text/plain")) {
return contents.find((c) => c.content_type === "text/plain") || null;
}
return contents[0] || null;
};