mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
Fixes to editing of profiles
This commit is contained in:
parent
22ebf72b6b
commit
c8ffca37b1
|
|
@ -14,6 +14,7 @@ import ISO6391 from "iso-639-1";
|
|||
import { parseEmojis } from "~database/entities/Emoji";
|
||||
import { client } from "~database/datasource";
|
||||
import type { APISource } from "~types/entities/source";
|
||||
import { convertTextToHtml } from "@formatting";
|
||||
|
||||
export const meta = applyConfig({
|
||||
allowedMethods: ["PATCH"],
|
||||
|
|
@ -122,11 +123,9 @@ export default async (req: Request): Promise<Response> => {
|
|||
return errorResponse("Bio contains blocked words", 422);
|
||||
}
|
||||
|
||||
// Remove emojis
|
||||
user.emojis = [];
|
||||
|
||||
(user.source as unknown as APISource).note = sanitizedNote;
|
||||
user.note = sanitizedNote;
|
||||
// TODO: Convert note to HTML
|
||||
user.note = await convertTextToHtml(sanitizedNote);
|
||||
}
|
||||
|
||||
if (source_privacy && user.source) {
|
||||
|
|
|
|||
29
utils/formatting.ts
Normal file
29
utils/formatting.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import { sanitizeHtml } from "@sanitization";
|
||||
import linkifyHtml from "linkify-html";
|
||||
import linkifyStr from "linkify-string";
|
||||
import { parse } from "marked";
|
||||
|
||||
/**
|
||||
* Converts plaintext, MFM or Markdown to HTML
|
||||
* @param text Text to convert
|
||||
* @param content_type Content type of the text (optional, defaults to plaintext)
|
||||
* @returns HTML
|
||||
*/
|
||||
export const convertTextToHtml = async (
|
||||
text: string,
|
||||
content_type?: string
|
||||
) => {
|
||||
if (content_type === "text/markdown") {
|
||||
return linkifyHtml(await sanitizeHtml(parse(text)));
|
||||
} else if (content_type === "text/x.misskeymarkdown") {
|
||||
// Parse as MFM
|
||||
// TODO: Implement MFM
|
||||
return text;
|
||||
} else {
|
||||
// Parse as plaintext
|
||||
return linkifyStr(text)
|
||||
.split("\n")
|
||||
.map(line => `<p>${line}</p>`)
|
||||
.join("\n");
|
||||
}
|
||||
};
|
||||
Loading…
Reference in a new issue