mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
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
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:
parent
3832328aaf
commit
ec69fc2ac0
48
utils/rss.ts
48
utils/rss.ts
|
|
@ -1,5 +1,6 @@
|
|||
import { and, eq, inArray } from "drizzle-orm";
|
||||
import { Feed } from "feed";
|
||||
import { Media } from "~/classes/database/media";
|
||||
import { Note } from "~/classes/database/note";
|
||||
import type { User } from "~/classes/database/user";
|
||||
import { config } from "~/config";
|
||||
|
|
@ -48,6 +49,11 @@ export const getFeed = async (user: User, page = 0): Promise<Feed> => {
|
|||
});
|
||||
|
||||
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({
|
||||
link: new URL(
|
||||
`/@${user.data.username}/${note.id}`,
|
||||
|
|
@ -61,6 +67,48 @@ export const getFeed = async (user: User, page = 0): Promise<Feed> => {
|
|||
).href,
|
||||
published: new Date(note.data.createdAt),
|
||||
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,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue