mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
Implement federation of statuses
This commit is contained in:
parent
8563c97403
commit
a58c81c8e9
11 changed files with 788 additions and 411 deletions
|
|
@ -1,21 +1,42 @@
|
|||
import type { ContentFormat } from "~types/lysand/Object";
|
||||
import type * as Lysand from "lysand-types";
|
||||
import { lookup } from "mime-types";
|
||||
|
||||
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
|
||||
);
|
||||
export const getBestContentType = (content?: Lysand.ContentFormat) => {
|
||||
if (!content) return { content: "", format: "text/plain" };
|
||||
|
||||
const bestFormatsRanked = [
|
||||
"text/x.misskeymarkdown",
|
||||
"text/html",
|
||||
"text/markdown",
|
||||
"text/plain",
|
||||
];
|
||||
|
||||
for (const format of bestFormatsRanked) {
|
||||
if (content[format])
|
||||
return { content: content[format].content, format };
|
||||
}
|
||||
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;
|
||||
|
||||
return { content: "", format: "text/plain" };
|
||||
};
|
||||
|
||||
export const urlToContentFormat = (
|
||||
url: string,
|
||||
): Lysand.ContentFormat | null => {
|
||||
if (!url) return null;
|
||||
if (url.startsWith("https://api.dicebear.com/")) {
|
||||
return {
|
||||
"image/svg+xml": {
|
||||
content: url,
|
||||
},
|
||||
};
|
||||
}
|
||||
const mimeType =
|
||||
lookup(url.replace(new URL(url).search, "")) ||
|
||||
"application/octet-stream";
|
||||
|
||||
return {
|
||||
[mimeType]: {
|
||||
content: url,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue