mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 13:59:16 +01:00
Clean up more ActivityPub code, refactoring
This commit is contained in:
parent
d05b077df1
commit
80a3e4c92d
26 changed files with 317 additions and 170 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { errorResponse, jsonResponse } from "@response";
|
||||
import { MatchedRoute } from "bun";
|
||||
import { User } from "~database/entities/User";
|
||||
import { User, userRelations } from "~database/entities/User";
|
||||
import { getConfig, getHost } from "@config";
|
||||
import { applyConfig } from "@api";
|
||||
|
||||
|
|
@ -34,7 +34,10 @@ export default async (
|
|||
return errorResponse("User is a remote user", 404);
|
||||
}
|
||||
|
||||
const user = await User.findOneBy({ username: requestedUser.split("@")[0] });
|
||||
const user = await User.findOne({
|
||||
where: { username: requestedUser.split("@")[0] },
|
||||
relations: userRelations
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
return errorResponse("User not found", 404);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { errorResponse, jsonResponse } from "@response";
|
||||
import { MatchedRoute } from "bun";
|
||||
import { Relationship } from "~database/entities/Relationship";
|
||||
import { User } from "~database/entities/User";
|
||||
import { User, userRelations } from "~database/entities/User";
|
||||
import { applyConfig } from "@api";
|
||||
|
||||
export const meta = applyConfig({
|
||||
|
|
@ -29,8 +29,11 @@ export default async (
|
|||
|
||||
if (!self) return errorResponse("Unauthorized", 401);
|
||||
|
||||
const user = await User.findOneBy({
|
||||
id,
|
||||
const user = await User.findOne({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
relations: userRelations,
|
||||
});
|
||||
|
||||
if (!user) return errorResponse("User not found", 404);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { parseRequest } from "@request";
|
|||
import { errorResponse, jsonResponse } from "@response";
|
||||
import { MatchedRoute } from "bun";
|
||||
import { Relationship } from "~database/entities/Relationship";
|
||||
import { User } from "~database/entities/User";
|
||||
import { User, userRelations } from "~database/entities/User";
|
||||
import { applyConfig } from "@api";
|
||||
|
||||
export const meta = applyConfig({
|
||||
|
|
@ -36,8 +36,11 @@ export default async (
|
|||
languages?: string[];
|
||||
}>(req);
|
||||
|
||||
const user = await User.findOneBy({
|
||||
id,
|
||||
const user = await User.findOne({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
relations: userRelations,
|
||||
});
|
||||
|
||||
if (!user) return errorResponse("User not found", 404);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { errorResponse, jsonResponse } from "@response";
|
||||
import { MatchedRoute } from "bun";
|
||||
import { User } from "~database/entities/User";
|
||||
import { User, userRelations } from "~database/entities/User";
|
||||
import { applyConfig } from "@api";
|
||||
|
||||
export const meta = applyConfig({
|
||||
|
|
@ -28,8 +28,11 @@ export default async (
|
|||
|
||||
let foundUser: User | null;
|
||||
try {
|
||||
foundUser = await User.findOneBy({
|
||||
id,
|
||||
foundUser = await User.findOne({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
relations: userRelations,
|
||||
});
|
||||
} catch (e) {
|
||||
return errorResponse("Invalid ID", 404);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { parseRequest } from "@request";
|
|||
import { errorResponse, jsonResponse } from "@response";
|
||||
import { MatchedRoute } from "bun";
|
||||
import { Relationship } from "~database/entities/Relationship";
|
||||
import { User } from "~database/entities/User";
|
||||
import { User, userRelations } from "~database/entities/User";
|
||||
import { applyConfig } from "@api";
|
||||
|
||||
export const meta = applyConfig({
|
||||
|
|
@ -36,8 +36,11 @@ export default async (
|
|||
duration: number;
|
||||
}>(req);
|
||||
|
||||
const user = await User.findOneBy({
|
||||
id,
|
||||
const user = await User.findOne({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
relations: userRelations,
|
||||
});
|
||||
|
||||
if (!user) return errorResponse("User not found", 404);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { parseRequest } from "@request";
|
|||
import { errorResponse, jsonResponse } from "@response";
|
||||
import { MatchedRoute } from "bun";
|
||||
import { Relationship } from "~database/entities/Relationship";
|
||||
import { User } from "~database/entities/User";
|
||||
import { User, userRelations } from "~database/entities/User";
|
||||
import { applyConfig } from "@api";
|
||||
|
||||
export const meta = applyConfig({
|
||||
|
|
@ -34,8 +34,11 @@ export default async (
|
|||
comment: string;
|
||||
}>(req);
|
||||
|
||||
const user = await User.findOneBy({
|
||||
id,
|
||||
const user = await User.findOne({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
relations: userRelations,
|
||||
});
|
||||
|
||||
if (!user) return errorResponse("User not found", 404);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { errorResponse, jsonResponse } from "@response";
|
||||
import { MatchedRoute } from "bun";
|
||||
import { Relationship } from "~database/entities/Relationship";
|
||||
import { User } from "~database/entities/User";
|
||||
import { User, userRelations } from "~database/entities/User";
|
||||
import { applyConfig } from "@api";
|
||||
|
||||
export const meta = applyConfig({
|
||||
|
|
@ -29,8 +29,11 @@ export default async (
|
|||
|
||||
if (!self) return errorResponse("Unauthorized", 401);
|
||||
|
||||
const user = await User.findOneBy({
|
||||
id,
|
||||
const user = await User.findOne({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
relations: userRelations,
|
||||
});
|
||||
|
||||
if (!user) return errorResponse("User not found", 404);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { errorResponse, jsonResponse } from "@response";
|
||||
import { MatchedRoute } from "bun";
|
||||
import { Relationship } from "~database/entities/Relationship";
|
||||
import { User } from "~database/entities/User";
|
||||
import { User, userRelations } from "~database/entities/User";
|
||||
import { applyConfig } from "@api";
|
||||
|
||||
export const meta = applyConfig({
|
||||
|
|
@ -29,8 +29,11 @@ export default async (
|
|||
|
||||
if (!self) return errorResponse("Unauthorized", 401);
|
||||
|
||||
const user = await User.findOneBy({
|
||||
id,
|
||||
const user = await User.findOne({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
relations: userRelations,
|
||||
});
|
||||
|
||||
if (!user) return errorResponse("User not found", 404);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { errorResponse, jsonResponse } from "@response";
|
||||
import { MatchedRoute } from "bun";
|
||||
import { Status, statusRelations } from "~database/entities/Status";
|
||||
import { User } from "~database/entities/User";
|
||||
import { Status, statusAndUserRelations } from "~database/entities/Status";
|
||||
import { User, userRelations } from "~database/entities/User";
|
||||
import { applyConfig } from "@api";
|
||||
|
||||
export const meta = applyConfig({
|
||||
|
|
@ -42,8 +42,11 @@ export default async (
|
|||
tagged?: string;
|
||||
} = matchedRoute.query;
|
||||
|
||||
const user = await User.findOneBy({
|
||||
id,
|
||||
const user = await User.findOne({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
relations: userRelations,
|
||||
});
|
||||
|
||||
if (!user) return errorResponse("User not found", 404);
|
||||
|
|
@ -60,7 +63,7 @@ export default async (
|
|||
},
|
||||
isReblog: exclude_reblogs ? true : undefined,
|
||||
},
|
||||
relations: statusRelations,
|
||||
relations: statusAndUserRelations,
|
||||
order: {
|
||||
created_at: "DESC",
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { errorResponse, jsonResponse } from "@response";
|
||||
import { MatchedRoute } from "bun";
|
||||
import { Relationship } from "~database/entities/Relationship";
|
||||
import { User } from "~database/entities/User";
|
||||
import { User, userRelations } from "~database/entities/User";
|
||||
import { applyConfig } from "@api";
|
||||
|
||||
export const meta = applyConfig({
|
||||
|
|
@ -29,8 +29,11 @@ export default async (
|
|||
|
||||
if (!self) return errorResponse("Unauthorized", 401);
|
||||
|
||||
const user = await User.findOneBy({
|
||||
id,
|
||||
const user = await User.findOne({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
relations: userRelations,
|
||||
});
|
||||
|
||||
if (!user) return errorResponse("User not found", 404);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { errorResponse, jsonResponse } from "@response";
|
||||
import { MatchedRoute } from "bun";
|
||||
import { Relationship } from "~database/entities/Relationship";
|
||||
import { User } from "~database/entities/User";
|
||||
import { User, userRelations } from "~database/entities/User";
|
||||
import { applyConfig } from "@api";
|
||||
|
||||
export const meta = applyConfig({
|
||||
|
|
@ -29,8 +29,11 @@ export default async (
|
|||
|
||||
if (!self) return errorResponse("Unauthorized", 401);
|
||||
|
||||
const user = await User.findOneBy({
|
||||
id,
|
||||
const user = await User.findOne({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
relations: userRelations,
|
||||
});
|
||||
|
||||
if (!user) return errorResponse("User not found", 404);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { errorResponse, jsonResponse } from "@response";
|
||||
import { MatchedRoute } from "bun";
|
||||
import { Relationship } from "~database/entities/Relationship";
|
||||
import { User } from "~database/entities/User";
|
||||
import { User, userRelations } from "~database/entities/User";
|
||||
import { applyConfig } from "@api";
|
||||
|
||||
export const meta = applyConfig({
|
||||
|
|
@ -29,8 +29,11 @@ export default async (
|
|||
|
||||
if (!self) return errorResponse("Unauthorized", 401);
|
||||
|
||||
const user = await User.findOneBy({
|
||||
id,
|
||||
const user = await User.findOne({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
relations: userRelations,
|
||||
});
|
||||
|
||||
if (!user) return errorResponse("User not found", 404);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { errorResponse, jsonResponse } from "@response";
|
||||
import { MatchedRoute } from "bun";
|
||||
import { Relationship } from "~database/entities/Relationship";
|
||||
import { User } from "~database/entities/User";
|
||||
import { User, userRelations } from "~database/entities/User";
|
||||
import { applyConfig } from "@api";
|
||||
|
||||
export const meta = applyConfig({
|
||||
|
|
@ -29,8 +29,11 @@ export default async (
|
|||
|
||||
if (!self) return errorResponse("Unauthorized", 401);
|
||||
|
||||
const user = await User.findOneBy({
|
||||
id,
|
||||
const user = await User.findOne({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
relations: userRelations,
|
||||
});
|
||||
|
||||
if (!user) return errorResponse("User not found", 404);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { applyConfig } from "@api";
|
||||
import { errorResponse, jsonResponse } from "@response";
|
||||
import { MatchedRoute } from "bun";
|
||||
import { Status, statusRelations } from "~database/entities/Status";
|
||||
import { Status, statusAndUserRelations } from "~database/entities/Status";
|
||||
import { User } from "~database/entities/User";
|
||||
import { APIRouteMeta } from "~types/api";
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ export default async (
|
|||
where: {
|
||||
id,
|
||||
},
|
||||
relations: statusRelations,
|
||||
relations: statusAndUserRelations,
|
||||
});
|
||||
} catch (e) {
|
||||
return errorResponse("Invalid ID", 404);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { applyConfig } from "@api";
|
|||
import { parseRequest } from "@request";
|
||||
import { errorResponse, jsonResponse } from "@response";
|
||||
import { FindManyOptions } from "typeorm";
|
||||
import { Status, statusRelations } from "~database/entities/Status";
|
||||
import { Status, statusAndUserRelations } from "~database/entities/Status";
|
||||
import { User } from "~database/entities/User";
|
||||
import { APIRouteMeta } from "~types/api";
|
||||
|
||||
|
|
@ -60,7 +60,7 @@ export default async (req: Request): Promise<Response> => {
|
|||
created_at: "DESC",
|
||||
},
|
||||
take: limit,
|
||||
relations: statusRelations,
|
||||
relations: statusAndUserRelations,
|
||||
};
|
||||
|
||||
if (max_id) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { applyConfig } from "@api";
|
|||
import { parseRequest } from "@request";
|
||||
import { errorResponse, jsonResponse } from "@response";
|
||||
import { FindManyOptions, IsNull, Not } from "typeorm";
|
||||
import { Status, statusRelations } from "~database/entities/Status";
|
||||
import { Status, statusAndUserRelations } from "~database/entities/Status";
|
||||
import { APIRouteMeta } from "~types/api";
|
||||
|
||||
export const meta: APIRouteMeta = applyConfig({
|
||||
|
|
@ -56,7 +56,7 @@ export default async (req: Request): Promise<Response> => {
|
|||
created_at: "DESC",
|
||||
},
|
||||
take: limit,
|
||||
relations: statusRelations,
|
||||
relations: statusAndUserRelations,
|
||||
};
|
||||
|
||||
if (max_id) {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { MatchedRoute } from "bun";
|
|||
import { randomBytes } from "crypto";
|
||||
import { Application } from "~database/entities/Application";
|
||||
import { Token } from "~database/entities/Token";
|
||||
import { User } from "~database/entities/User";
|
||||
import { User, userRelations } from "~database/entities/User";
|
||||
import { APIRouteMeta } from "~types/api";
|
||||
|
||||
export const meta: APIRouteMeta = applyConfig({
|
||||
|
|
@ -45,8 +45,11 @@ export default async (
|
|||
return errorResponse("Missing username or password", 400);
|
||||
|
||||
// Get user
|
||||
const user = await User.findOneBy({
|
||||
email,
|
||||
const user = await User.findOne({
|
||||
where: {
|
||||
email,
|
||||
},
|
||||
relations: userRelations,
|
||||
});
|
||||
|
||||
if (!user || !(await Bun.password.verify(password, user.password || "")))
|
||||
|
|
@ -70,5 +73,5 @@ export default async (
|
|||
await token.save();
|
||||
|
||||
// Redirect back to application
|
||||
return Response.redirect(`${redirect_uri}?code=${token.code}`);
|
||||
return Response.redirect(`${redirect_uri}?code=${token.code}`, 302);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { errorResponse, jsonLdResponse } from "@response";
|
||||
import { MatchedRoute } from "bun";
|
||||
import { User } from "~database/entities/User";
|
||||
import { User, userRelations } from "~database/entities/User";
|
||||
import { getConfig, getHost } from "@config";
|
||||
import { applyConfig } from "@api";
|
||||
|
||||
|
|
@ -34,7 +34,10 @@ export default async (
|
|||
|
||||
const username = matchedRoute.params.username;
|
||||
|
||||
const user = await User.findOneBy({ username });
|
||||
const user = await User.findOne({
|
||||
where: { username },
|
||||
relations: userRelations,
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
return errorResponse("User not found", 404);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { errorResponse, jsonLdResponse } from "@response";
|
||||
import { MatchedRoute } from "bun";
|
||||
import { User } from "~database/entities/User";
|
||||
import { User, userRelations } from "~database/entities/User";
|
||||
import { getHost } from "@config";
|
||||
import { NodeObject, compact } from "jsonld";
|
||||
import { RawActivity } from "~database/entities/RawActivity";
|
||||
|
|
@ -30,7 +30,10 @@ export default async (
|
|||
const min_id = matchedRoute.query.min_id || false;
|
||||
const max_id = matchedRoute.query.max_id || false;
|
||||
|
||||
const user = await User.findOneBy({ username });
|
||||
const user = await User.findOne({
|
||||
where: { username },
|
||||
relations: userRelations,
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
return errorResponse("User not found", 404);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue