2023-11-23 05:10:37 +01:00
|
|
|
import type { ContentFormat } from "~types/lysand/Object";
|
2023-11-05 00:59:55 +01:00
|
|
|
|
|
|
|
|
export const getBestContentType = (contents: ContentFormat[]) => {
|
2024-04-07 07:30:49 +02:00
|
|
|
// 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;
|
2023-11-05 00:59:55 +01:00
|
|
|
};
|