This commit is contained in:
Jesse Wierzbinski 2023-09-12 13:08:46 -10:00
parent 8e7f08678b
commit d30bbe56a7
No known key found for this signature in database
GPG key ID: F9A1E418934E40B0
4 changed files with 22 additions and 10 deletions

View file

@ -1,4 +1,4 @@
import { errorResponse, jsonResponse } from "@response";
import { errorResponse, jsonLdResponse } from "@response";
import { MatchedRoute } from "bun";
import { User } from "~database/entities/User";
import { getHost } from "@config";
@ -19,7 +19,7 @@ export default async (
return errorResponse("User not found", 404);
}
return jsonResponse(
return jsonLdResponse(
await compact({
"@context": [
"https://www.w3.org/ns/activitystreams",

View file

@ -1,4 +1,4 @@
import { errorResponse, jsonResponse } from "@response";
import { errorResponse, jsonLdResponse } from "@response";
import { MatchedRoute } from "bun";
import { User } from "~database/entities/User";
import { getHost } from "@config";
@ -57,7 +57,7 @@ export default async (
}))[0];
if (!page)
return jsonResponse(
return jsonLdResponse(
await compact({
"@context": [
"https://www.w3.org/ns/activitystreams",
@ -67,9 +67,9 @@ export default async (
type: "OrderedCollection",
totalItems: count,
first: `${getHost()}/@${user.username}/outbox?page=true`,
last: `${getHost()}/@${
user.username
}/outbox?min_id=${lastPost.id}&page=true`,
last: `${getHost()}/@${user.username}/outbox?min_id=${
lastPost.id
}&page=true`,
})
);
else {
@ -109,7 +109,7 @@ export default async (
return jsonResponse(
return jsonLdResponse(
await compact({
"@context": [
"https://www.w3.org/ns/activitystreams",

View file

@ -1,4 +1,4 @@
import { errorResponse, jsonResponse } from "@response";
import { errorResponse, jsonLdResponse } from "@response";
import { MatchedRoute } from "bun";
import { RawObject } from "~database/entities/RawObject";
@ -15,5 +15,5 @@ export default async (
if (!object) return errorResponse("Object not found", 404)
return jsonResponse(object);
return jsonLdResponse(object);
};

View file

@ -1,3 +1,6 @@
import { APObject } from "activitypub-types";
import { NodeObject } from "jsonld";
export const jsonResponse = (data: object, status = 200) => {
return new Response(JSON.stringify(data), {
headers: {
@ -7,6 +10,15 @@ export const jsonResponse = (data: object, status = 200) => {
});
}
export const jsonLdResponse = (data: NodeObject | APObject, status = 200) => {
return new Response(JSON.stringify(data), {
headers: {
"Content-Type": "application/activity+json",
},
status,
});
};
export const errorResponse = (error: string, status = 500) => {
return jsonResponse({
error: error