mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 16:38:19 +01:00
20 lines
792 B
TypeScript
20 lines
792 B
TypeScript
import { 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
|
|
);
|
|
} else if (contents.find(c => c.content_type === "text/html")) {
|
|
return contents.find(c => c.content_type === "text/html") || null;
|
|
} else if (contents.find(c => c.content_type === "text/markdown")) {
|
|
return contents.find(c => c.content_type === "text/markdown") || null;
|
|
} else if (contents.find(c => c.content_type === "text/plain")) {
|
|
return contents.find(c => c.content_type === "text/plain") || null;
|
|
} else {
|
|
return contents[0] || null;
|
|
}
|
|
};
|