mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 16:38:19 +01:00
Add more API route definitions
This commit is contained in:
parent
a8d8b70239
commit
7f2e89ab20
|
|
@ -1,6 +1,20 @@
|
||||||
import { MatchedRoute } from "bun";
|
import { MatchedRoute } from "bun";
|
||||||
import { getHost } from "@config";
|
import { getConfig, getHost } from "@config";
|
||||||
import { xmlResponse } from "@response";
|
import { xmlResponse } from "@response";
|
||||||
|
import { applyConfig } from "@api";
|
||||||
|
|
||||||
|
export const meta = applyConfig({
|
||||||
|
allowedMethods: ["GET"],
|
||||||
|
auth: {
|
||||||
|
required: false,
|
||||||
|
},
|
||||||
|
ratelimits: {
|
||||||
|
duration: 60,
|
||||||
|
max: 60,
|
||||||
|
},
|
||||||
|
route: "/.well-known/host-meta",
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Host meta endpoint
|
* Host meta endpoint
|
||||||
|
|
@ -9,10 +23,11 @@ export default async (
|
||||||
req: Request,
|
req: Request,
|
||||||
matchedRoute: MatchedRoute
|
matchedRoute: MatchedRoute
|
||||||
): Promise<Response> => {
|
): Promise<Response> => {
|
||||||
|
const config = getConfig();
|
||||||
return xmlResponse(`
|
return xmlResponse(`
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
||||||
<Link rel="lrdd" template="https://${getHost()}/.well-known/webfinger?resource={uri}"/>
|
<Link rel="lrdd" template="${config.http.base_url}/.well-known/webfinger?resource={uri}"/>
|
||||||
</XRD>
|
</XRD>
|
||||||
`);
|
`);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,19 @@
|
||||||
import { MatchedRoute } from "bun";
|
import { MatchedRoute } from "bun";
|
||||||
import { getHost } from "@config";
|
import { getConfig, getHost } from "@config";
|
||||||
|
import { applyConfig } from "@api";
|
||||||
|
|
||||||
|
export const meta = applyConfig({
|
||||||
|
allowedMethods: ["GET"],
|
||||||
|
auth: {
|
||||||
|
required: false,
|
||||||
|
},
|
||||||
|
ratelimits: {
|
||||||
|
duration: 60,
|
||||||
|
max: 60,
|
||||||
|
},
|
||||||
|
route: "/.well-known/nodeinfo",
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Redirect to /nodeinfo/2.0
|
* Redirect to /nodeinfo/2.0
|
||||||
|
|
@ -8,10 +22,12 @@ export default async (
|
||||||
req: Request,
|
req: Request,
|
||||||
matchedRoute: MatchedRoute
|
matchedRoute: MatchedRoute
|
||||||
): Promise<Response> => {
|
): Promise<Response> => {
|
||||||
|
const config = getConfig();
|
||||||
|
|
||||||
return new Response("", {
|
return new Response("", {
|
||||||
status: 301,
|
status: 301,
|
||||||
headers: {
|
headers: {
|
||||||
Location: `https://${getHost()}/.well-known/nodeinfo/2.0`,
|
Location: `${config.http.base_url}/.well-known/nodeinfo/2.0`,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,19 @@ import { errorResponse, jsonResponse } from "@response";
|
||||||
import { MatchedRoute } from "bun";
|
import { MatchedRoute } from "bun";
|
||||||
import { User } from "~database/entities/User";
|
import { User } from "~database/entities/User";
|
||||||
import { getConfig, getHost } from "@config";
|
import { getConfig, getHost } from "@config";
|
||||||
|
import { applyConfig } from "@api";
|
||||||
|
|
||||||
|
export const meta = applyConfig({
|
||||||
|
allowedMethods: ["GET"],
|
||||||
|
auth: {
|
||||||
|
required: false,
|
||||||
|
},
|
||||||
|
ratelimits: {
|
||||||
|
duration: 60,
|
||||||
|
max: 60,
|
||||||
|
},
|
||||||
|
route: "/.well-known/webfinger",
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActivityPub WebFinger endpoint
|
* ActivityPub WebFinger endpoint
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,18 @@
|
||||||
|
import { applyConfig } from "@api";
|
||||||
import { jsonResponse } from "@response";
|
import { jsonResponse } from "@response";
|
||||||
|
|
||||||
|
export const meta = applyConfig({
|
||||||
|
allowedMethods: ["GET"],
|
||||||
|
auth: {
|
||||||
|
required: false,
|
||||||
|
},
|
||||||
|
ratelimits: {
|
||||||
|
duration: 60,
|
||||||
|
max: 500,
|
||||||
|
},
|
||||||
|
route: "/nodeinfo/2.0",
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActivityPub nodeinfo 2.0 endpoint
|
* ActivityPub nodeinfo 2.0 endpoint
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,18 @@
|
||||||
|
import { applyConfig } from "@api";
|
||||||
import { MatchedRoute } from "bun";
|
import { MatchedRoute } from "bun";
|
||||||
|
|
||||||
|
export const meta = applyConfig({
|
||||||
|
allowedMethods: ["GET"],
|
||||||
|
auth: {
|
||||||
|
required: false,
|
||||||
|
},
|
||||||
|
ratelimits: {
|
||||||
|
duration: 60,
|
||||||
|
max: 20,
|
||||||
|
},
|
||||||
|
route: "/oauth/authorize",
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an HTML login form
|
* Returns an HTML login form
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,20 @@
|
||||||
|
import { applyConfig } from "@api";
|
||||||
import { parseRequest } from "@request";
|
import { parseRequest } from "@request";
|
||||||
import { errorResponse, jsonResponse } from "@response";
|
import { errorResponse, jsonResponse } from "@response";
|
||||||
import { Token } from "~database/entities/Token";
|
import { Token } from "~database/entities/Token";
|
||||||
|
|
||||||
|
export const meta = applyConfig({
|
||||||
|
allowedMethods: ["POST"],
|
||||||
|
auth: {
|
||||||
|
required: false,
|
||||||
|
},
|
||||||
|
ratelimits: {
|
||||||
|
duration: 60,
|
||||||
|
max: 10,
|
||||||
|
},
|
||||||
|
route: "/oauth/token",
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows getting token from OAuth code
|
* Allows getting token from OAuth code
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,20 @@
|
||||||
|
import { applyConfig } from "@api";
|
||||||
import { errorResponse, jsonLdResponse } from "@response";
|
import { errorResponse, jsonLdResponse } from "@response";
|
||||||
import { MatchedRoute } from "bun";
|
import { MatchedRoute } from "bun";
|
||||||
import { RawActivity } from "~database/entities/RawActivity";
|
import { RawActivity } from "~database/entities/RawActivity";
|
||||||
|
|
||||||
|
export const meta = applyConfig({
|
||||||
|
allowedMethods: ["GET"],
|
||||||
|
auth: {
|
||||||
|
required: false,
|
||||||
|
},
|
||||||
|
ratelimits: {
|
||||||
|
duration: 60,
|
||||||
|
max: 500,
|
||||||
|
},
|
||||||
|
route: "/object/:id",
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch a user
|
* Fetch a user
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,19 @@ 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 { getConfig, getHost } from "@config";
|
import { getConfig, getHost } from "@config";
|
||||||
|
import { applyConfig } from "@api";
|
||||||
|
|
||||||
|
export const meta = applyConfig({
|
||||||
|
allowedMethods: ["GET"],
|
||||||
|
auth: {
|
||||||
|
required: false,
|
||||||
|
},
|
||||||
|
ratelimits: {
|
||||||
|
duration: 60,
|
||||||
|
max: 500,
|
||||||
|
},
|
||||||
|
route: "/users/:username/actor",
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActivityPub user actor endpoinmt
|
* ActivityPub user actor endpoinmt
|
||||||
|
|
@ -19,7 +32,7 @@ export default async (
|
||||||
|
|
||||||
const config = getConfig();
|
const config = getConfig();
|
||||||
|
|
||||||
const username = matchedRoute.params.username.replace("@", "");
|
const username = matchedRoute.params.username;
|
||||||
|
|
||||||
const user = await User.findOneBy({ username });
|
const user = await User.findOneBy({ username });
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||||
|
import { applyConfig } from "@api";
|
||||||
import { getConfig } from "@config";
|
import { getConfig } from "@config";
|
||||||
import { errorResponse, jsonResponse } from "@response";
|
import { errorResponse, jsonResponse } from "@response";
|
||||||
import {
|
import {
|
||||||
|
|
@ -19,6 +20,18 @@ import { RawActivity } from "~database/entities/RawActivity";
|
||||||
import { RawActor } from "~database/entities/RawActor";
|
import { RawActor } from "~database/entities/RawActor";
|
||||||
import { User } from "~database/entities/User";
|
import { User } from "~database/entities/User";
|
||||||
|
|
||||||
|
export const meta = applyConfig({
|
||||||
|
allowedMethods: ["POST"],
|
||||||
|
auth: {
|
||||||
|
required: false,
|
||||||
|
},
|
||||||
|
ratelimits: {
|
||||||
|
duration: 60,
|
||||||
|
max: 500,
|
||||||
|
},
|
||||||
|
route: "/users/:username/inbox",
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActivityPub user inbox endpoint
|
* ActivityPub user inbox endpoint
|
||||||
*/
|
*/
|
||||||
|
|
@ -26,11 +39,6 @@ export default async (
|
||||||
req: Request,
|
req: Request,
|
||||||
matchedRoute: MatchedRoute
|
matchedRoute: MatchedRoute
|
||||||
): Promise<Response> => {
|
): Promise<Response> => {
|
||||||
// Check if POST request
|
|
||||||
if (req.method !== "POST") {
|
|
||||||
return errorResponse("Method not allowed", 405);
|
|
||||||
}
|
|
||||||
|
|
||||||
const username = matchedRoute.params.username;
|
const username = matchedRoute.params.username;
|
||||||
|
|
||||||
const config = getConfig();
|
const config = getConfig();
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,19 @@ import { User } from "~database/entities/User";
|
||||||
import { getHost } from "@config";
|
import { getHost } from "@config";
|
||||||
import { NodeObject, compact } from "jsonld";
|
import { NodeObject, compact } from "jsonld";
|
||||||
import { RawActivity } from "~database/entities/RawActivity";
|
import { RawActivity } from "~database/entities/RawActivity";
|
||||||
|
import { applyConfig } from "@api";
|
||||||
|
|
||||||
|
export const meta = applyConfig({
|
||||||
|
allowedMethods: ["GET"],
|
||||||
|
auth: {
|
||||||
|
required: false,
|
||||||
|
},
|
||||||
|
ratelimits: {
|
||||||
|
duration: 60,
|
||||||
|
max: 500,
|
||||||
|
},
|
||||||
|
route: "/users/:username/outbox",
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActivityPub user outbox endpoint
|
* ActivityPub user outbox endpoint
|
||||||
Loading…
Reference in a new issue