mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
nnya
This commit is contained in:
parent
8e7f08678b
commit
d30bbe56a7
|
|
@ -1,4 +1,4 @@
|
||||||
import { errorResponse, jsonResponse } from "@response";
|
import { errorResponse, jsonLdResponse } from "@response";
|
||||||
import { MatchedRoute } from "bun";
|
import { MatchedRoute } from "bun";
|
||||||
import { User } from "~database/entities/User";
|
import { User } from "~database/entities/User";
|
||||||
import { getHost } from "@config";
|
import { getHost } from "@config";
|
||||||
|
|
@ -19,7 +19,7 @@ export default async (
|
||||||
return errorResponse("User not found", 404);
|
return errorResponse("User not found", 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
return jsonResponse(
|
return jsonLdResponse(
|
||||||
await compact({
|
await compact({
|
||||||
"@context": [
|
"@context": [
|
||||||
"https://www.w3.org/ns/activitystreams",
|
"https://www.w3.org/ns/activitystreams",
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { errorResponse, jsonResponse } from "@response";
|
import { errorResponse, jsonLdResponse } from "@response";
|
||||||
import { MatchedRoute } from "bun";
|
import { MatchedRoute } from "bun";
|
||||||
import { User } from "~database/entities/User";
|
import { User } from "~database/entities/User";
|
||||||
import { getHost } from "@config";
|
import { getHost } from "@config";
|
||||||
|
|
@ -57,7 +57,7 @@ export default async (
|
||||||
}))[0];
|
}))[0];
|
||||||
|
|
||||||
if (!page)
|
if (!page)
|
||||||
return jsonResponse(
|
return jsonLdResponse(
|
||||||
await compact({
|
await compact({
|
||||||
"@context": [
|
"@context": [
|
||||||
"https://www.w3.org/ns/activitystreams",
|
"https://www.w3.org/ns/activitystreams",
|
||||||
|
|
@ -67,9 +67,9 @@ export default async (
|
||||||
type: "OrderedCollection",
|
type: "OrderedCollection",
|
||||||
totalItems: count,
|
totalItems: count,
|
||||||
first: `${getHost()}/@${user.username}/outbox?page=true`,
|
first: `${getHost()}/@${user.username}/outbox?page=true`,
|
||||||
last: `${getHost()}/@${
|
last: `${getHost()}/@${user.username}/outbox?min_id=${
|
||||||
user.username
|
lastPost.id
|
||||||
}/outbox?min_id=${lastPost.id}&page=true`,
|
}&page=true`,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
else {
|
else {
|
||||||
|
|
@ -109,7 +109,7 @@ export default async (
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return jsonResponse(
|
return jsonLdResponse(
|
||||||
await compact({
|
await compact({
|
||||||
"@context": [
|
"@context": [
|
||||||
"https://www.w3.org/ns/activitystreams",
|
"https://www.w3.org/ns/activitystreams",
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { errorResponse, jsonResponse } from "@response";
|
import { errorResponse, jsonLdResponse } from "@response";
|
||||||
import { MatchedRoute } from "bun";
|
import { MatchedRoute } from "bun";
|
||||||
import { RawObject } from "~database/entities/RawObject";
|
import { RawObject } from "~database/entities/RawObject";
|
||||||
|
|
||||||
|
|
@ -15,5 +15,5 @@ export default async (
|
||||||
|
|
||||||
if (!object) return errorResponse("Object not found", 404)
|
if (!object) return errorResponse("Object not found", 404)
|
||||||
|
|
||||||
return jsonResponse(object);
|
return jsonLdResponse(object);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
import { APObject } from "activitypub-types";
|
||||||
|
import { NodeObject } from "jsonld";
|
||||||
|
|
||||||
export const jsonResponse = (data: object, status = 200) => {
|
export const jsonResponse = (data: object, status = 200) => {
|
||||||
return new Response(JSON.stringify(data), {
|
return new Response(JSON.stringify(data), {
|
||||||
headers: {
|
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) => {
|
export const errorResponse = (error: string, status = 500) => {
|
||||||
return jsonResponse({
|
return jsonResponse({
|
||||||
error: error
|
error: error
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue