More Lysand protocol work, refactor keys, small refactoring overall

This commit is contained in:
Jesse Wierzbinski 2023-11-04 13:59:55 -10:00
parent 77a675afe6
commit a1c0164e9d
No known key found for this signature in database
GPG key ID: F9A1E418934E40B0
11 changed files with 304 additions and 89 deletions

19
utils/content_types.ts Normal file
View file

@ -0,0 +1,19 @@
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;
}
};