feat(api): Add media attachments to RSS and Atom feeds
Some checks failed
CodeQL Scan / Analyze (javascript-typescript) (push) Failing after 0s
Build Docker Images / lint (push) Failing after 8s
Build Docker Images / check (push) Failing after 6s
Build Docker Images / tests (push) Failing after 7s
Deploy Docs to GitHub Pages / build (push) Failing after 0s
Build Docker Images / build (server, Dockerfile, ${{ github.repository_owner }}/server) (push) Has been skipped
Build Docker Images / build (worker, Worker.Dockerfile, ${{ github.repository_owner }}/worker) (push) Has been skipped
Deploy Docs to GitHub Pages / Deploy (push) Has been skipped
Mirror to Codeberg / Mirror (push) Failing after 0s
Nix Build / check (push) Failing after 0s

This commit is contained in:
Jesse Wierzbinski 2025-05-01 22:47:29 +02:00
parent 3832328aaf
commit ec69fc2ac0
No known key found for this signature in database

View file

@ -1,5 +1,6 @@
import { and, eq, inArray } from "drizzle-orm"; import { and, eq, inArray } from "drizzle-orm";
import { Feed } from "feed"; import { Feed } from "feed";
import { Media } from "~/classes/database/media";
import { Note } from "~/classes/database/note"; import { Note } from "~/classes/database/note";
import type { User } from "~/classes/database/user"; import type { User } from "~/classes/database/user";
import { config } from "~/config"; import { config } from "~/config";
@ -48,6 +49,11 @@ export const getFeed = async (user: User, page = 0): Promise<Feed> => {
}); });
for (const note of notes) { for (const note of notes) {
const attachments = note.data.attachments.map((a) => new Media(a));
const image = attachments.find((a) => a.getMastodonType() === "image");
const video = attachments.find((a) => a.getMastodonType() === "video");
const audio = attachments.find((a) => a.getMastodonType() === "audio");
feed.addItem({ feed.addItem({
link: new URL( link: new URL(
`/@${user.data.username}/${note.id}`, `/@${user.data.username}/${note.id}`,
@ -61,6 +67,48 @@ export const getFeed = async (user: User, page = 0): Promise<Feed> => {
).href, ).href,
published: new Date(note.data.createdAt), published: new Date(note.data.createdAt),
title: "", title: "",
image: image
? {
url: image.getUrl().href,
title:
image.data.content[image.getPreferredMimeType()]
.description ?? undefined,
type: image.getPreferredMimeType(),
length:
image.data.content[image.getPreferredMimeType()]
.size ?? undefined,
}
: undefined,
video: video
? {
url: video.getUrl().href,
title:
video.data.content[video.getPreferredMimeType()]
.description ?? undefined,
type: video.getPreferredMimeType(),
duration:
video.data.content[video.getPreferredMimeType()]
.duration ?? undefined,
length:
video.data.content[video.getPreferredMimeType()]
.size ?? undefined,
}
: undefined,
audio: audio
? {
url: audio.getUrl().href,
title:
audio.data.content[audio.getPreferredMimeType()]
.description ?? undefined,
type: audio.getPreferredMimeType(),
duration:
audio.data.content[audio.getPreferredMimeType()]
.duration ?? undefined,
length:
audio.data.content[audio.getPreferredMimeType()]
.size ?? undefined,
}
: undefined,
}); });
} }