mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 13:59:16 +01:00
Add new API endpoint (accounts/verify_credentials)
This commit is contained in:
parent
e25b745e25
commit
ce2ed0754e
11 changed files with 234 additions and 181 deletions
|
|
@ -89,7 +89,7 @@ export default async (
|
|||
Hashtag: "as:Hashtag",
|
||||
},
|
||||
],
|
||||
id: `${config.http.base_url}:${config.http.port}/@${user.username}`,
|
||||
id: `${config.http.base_url}/@${user.username}`,
|
||||
type: "Person",
|
||||
preferredUsername: user.username, // TODO: Add user display name
|
||||
name: user.username,
|
||||
|
|
@ -104,21 +104,21 @@ export default async (
|
|||
url: user.header,
|
||||
mediaType: "image/png", // TODO: Set user header mimetype
|
||||
},
|
||||
inbox: `${config.http.base_url}:${config.http.port}/@${user.username}/inbox`,
|
||||
outbox: `${config.http.base_url}:${config.http.port}/@${user.username}/outbox`,
|
||||
followers: `${config.http.base_url}:${config.http.port}/@${user.username}/followers`,
|
||||
following: `${config.http.base_url}:${config.http.port}/@${user.username}/following`,
|
||||
liked: `${config.http.base_url}:${config.http.port}/@${user.username}/liked`,
|
||||
inbox: `${config.http.base_url}/@${user.username}/inbox`,
|
||||
outbox: `${config.http.base_url}/@${user.username}/outbox`,
|
||||
followers: `${config.http.base_url}/@${user.username}/followers`,
|
||||
following: `${config.http.base_url}/@${user.username}/following`,
|
||||
liked: `${config.http.base_url}/@${user.username}/liked`,
|
||||
discoverable: true,
|
||||
alsoKnownAs: [
|
||||
// TODO: Add accounts from which the user migrated
|
||||
],
|
||||
manuallyApprovesFollowers: false, // TODO: Change
|
||||
publicKey: {
|
||||
id: `${getHost()}${config.http.base_url}:${config.http.port}/@${
|
||||
id: `${getHost()}${config.http.base_url}/@${
|
||||
user.username
|
||||
}/actor#main-key`,
|
||||
owner: `${config.http.base_url}:${config.http.port}/@${user.username}`,
|
||||
owner: `${config.http.base_url}/@${user.username}`,
|
||||
// Split the public key into PEM format
|
||||
publicKeyPem: `-----BEGIN PUBLIC KEY-----\n${user.public_key
|
||||
.match(/.{1,64}/g)
|
||||
|
|
@ -131,7 +131,7 @@ export default async (
|
|||
// TODO: Add user attachments (I.E. profile metadata)
|
||||
],
|
||||
endpoints: {
|
||||
sharedInbox: `${config.http.base_url}:${config.http.port}/inbox`,
|
||||
sharedInbox: `${config.http.base_url}/inbox`,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
|
|
|||
35
server/api/api/v1/accounts/verify_credentials/index.ts
Normal file
35
server/api/api/v1/accounts/verify_credentials/index.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import { getUserByToken } from "@auth";
|
||||
import { errorResponse, jsonResponse } from "@response";
|
||||
|
||||
/**
|
||||
* Patches a user
|
||||
*/
|
||||
export default async (req: Request): Promise<Response> => {
|
||||
// Check if request is a PATCH request
|
||||
if (req.method !== "GET")
|
||||
return errorResponse("This method requires a GET request", 405);
|
||||
|
||||
// Check auth token
|
||||
const token = req.headers.get("Authorization")?.split(" ")[1] || null;
|
||||
|
||||
if (!token)
|
||||
return errorResponse("This method requires an authenticated user", 422);
|
||||
|
||||
const user = await getUserByToken(token);
|
||||
|
||||
if (!user) return errorResponse("Unauthorized", 401);
|
||||
|
||||
// TODO: Add Source fields
|
||||
return jsonResponse({
|
||||
...(await user.toAPI()),
|
||||
source: user.source,
|
||||
// TODO: Add role support
|
||||
role: {
|
||||
id: 0,
|
||||
name: "",
|
||||
permissions: "",
|
||||
color: "",
|
||||
highlighted: false,
|
||||
},
|
||||
});
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue