Merge branch 'fix/feed' into 'develop'
fix: notes in rss feed do not display HTML Co-authored-by: Lhcfl <Lhcfl@outlook.com> See merge request firefish/firefish!10744
This commit is contained in:
commit
0cb2e94d99
|
@ -2,7 +2,16 @@ import { Feed } from "feed";
|
||||||
import { In, IsNull } from "typeorm";
|
import { In, IsNull } from "typeorm";
|
||||||
import config from "@/config/index.js";
|
import config from "@/config/index.js";
|
||||||
import type { User } from "@/models/entities/user.js";
|
import type { User } from "@/models/entities/user.js";
|
||||||
|
import type { Note } from "@/models/entities/note.js";
|
||||||
import { Notes, DriveFiles, UserProfiles, Users } from "@/models/index.js";
|
import { Notes, DriveFiles, UserProfiles, Users } from "@/models/index.js";
|
||||||
|
import getNoteHtml from "@/remote/activitypub/misc/get-note-html.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If there is this part in the note, it will cause CDATA to be terminated early.
|
||||||
|
*/
|
||||||
|
function escapeCDATA(str: string) {
|
||||||
|
return str.replaceAll("]]>", "]]]]><![CDATA[>");
|
||||||
|
}
|
||||||
|
|
||||||
export default async function (
|
export default async function (
|
||||||
user: User,
|
user: User,
|
||||||
|
@ -15,7 +24,7 @@ export default async function (
|
||||||
const author = {
|
const author = {
|
||||||
link: `${config.url}/@${user.username}`,
|
link: `${config.url}/@${user.username}`,
|
||||||
email: `${user.username}@${config.host}`,
|
email: `${user.username}@${config.host}`,
|
||||||
name: user.name || user.username,
|
name: escapeCDATA(user.name || user.username),
|
||||||
};
|
};
|
||||||
|
|
||||||
const profile = await UserProfiles.findOneByOrFail({ userId: user.id });
|
const profile = await UserProfiles.findOneByOrFail({ userId: user.id });
|
||||||
|
@ -44,11 +53,13 @@ export default async function (
|
||||||
title: `${author.name} (@${user.username}@${config.host})`,
|
title: `${author.name} (@${user.username}@${config.host})`,
|
||||||
updated: notes[0].createdAt,
|
updated: notes[0].createdAt,
|
||||||
generator: "Firefish",
|
generator: "Firefish",
|
||||||
description: `${user.notesCount} Notes, ${
|
description: escapeCDATA(
|
||||||
profile.ffVisibility === "public" ? user.followingCount : "?"
|
`${user.notesCount} Notes, ${
|
||||||
} Following, ${
|
profile.ffVisibility === "public" ? user.followingCount : "?"
|
||||||
profile.ffVisibility === "public" ? user.followersCount : "?"
|
} Following, ${
|
||||||
} Followers${profile.description ? ` · ${profile.description}` : ""}`,
|
profile.ffVisibility === "public" ? user.followersCount : "?"
|
||||||
|
} Followers${profile.description ? ` · ${profile.description}` : ""}`,
|
||||||
|
),
|
||||||
link: author.link,
|
link: author.link,
|
||||||
image: await Users.getAvatarUrl(user),
|
image: await Users.getAvatarUrl(user),
|
||||||
feedLinks: {
|
feedLinks: {
|
||||||
|
@ -88,19 +99,23 @@ export default async function (
|
||||||
}
|
}
|
||||||
|
|
||||||
feed.addItem({
|
feed.addItem({
|
||||||
title: title
|
title: escapeCDATA(
|
||||||
.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, "")
|
title
|
||||||
.substring(0, 100),
|
.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, "")
|
||||||
|
.substring(0, 100),
|
||||||
|
),
|
||||||
link: `${config.url}/notes/${note.id}`,
|
link: `${config.url}/notes/${note.id}`,
|
||||||
date: note.createdAt,
|
date: note.createdAt,
|
||||||
description: note.cw
|
description: note.cw
|
||||||
? note.cw.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, "")
|
? escapeCDATA(note.cw.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, ""))
|
||||||
: undefined,
|
: undefined,
|
||||||
content: contentStr.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, ""),
|
content: escapeCDATA(
|
||||||
|
contentStr.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, ""),
|
||||||
|
),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function noteToString(note, isTheNote = false) {
|
async function noteToString(note: Note, isTheNote = false) {
|
||||||
const author = isTheNote
|
const author = isTheNote
|
||||||
? null
|
? null
|
||||||
: await Users.findOneBy({ id: note.userId });
|
: await Users.findOneBy({ id: note.userId });
|
||||||
|
@ -135,7 +150,10 @@ export default async function (
|
||||||
}">${file.name}</a>`;
|
}">${file.name}</a>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
outstr += `${note.cw ? note.cw + "<br>" : ""}${note.text || ""}${fileEle}`;
|
|
||||||
|
outstr += `${note.cw ? note.cw + "<br>" : ""}${
|
||||||
|
getNoteHtml(note) || ""
|
||||||
|
}${fileEle}`;
|
||||||
if (isTheNote) {
|
if (isTheNote) {
|
||||||
outstr += ` <span class="${
|
outstr += ` <span class="${
|
||||||
note.renoteId ? "renote_note" : note.replyId ? "reply_note" : "new_note"
|
note.renoteId ? "renote_note" : note.replyId ? "reply_note" : "new_note"
|
||||||
|
|
Loading…
Reference in New Issue