HUGE rewrite to use Prisma instead of TypeORM (not finished yet)

This commit is contained in:
Jesse Wierzbinski 2023-11-10 16:36:06 -10:00
parent a1c0164e9d
commit 5eed8374cd
No known key found for this signature in database
GPG key ID: F9A1E418934E40B0
53 changed files with 1452 additions and 1967 deletions

View file

@ -1,8 +1,8 @@
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import { User, userRelations } from "~database/entities/User";
import { getConfig, getHost } from "@config";
import { applyConfig } from "@api";
import { client } from "~database/datasource";
export const meta = applyConfig({
allowedMethods: ["GET"],
@ -34,9 +34,8 @@ export default async (
return errorResponse("User is a remote user", 404);
}
const user = await User.findOne({
const user = await client.user.findUnique({
where: { username: requestedUser.split("@")[0] },
relations: userRelations
});
if (!user) {

View file

@ -1,7 +1,7 @@
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import { Relationship } from "~database/entities/Relationship";
import { User, userRelations } from "~database/entities/User";
import { UserAction, userRelations } from "~database/entities/User";
import { applyConfig } from "@api";
export const meta = applyConfig({
@ -25,11 +25,11 @@ export default async (
): Promise<Response> => {
const id = matchedRoute.params.id;
const { user: self } = await User.getFromRequest(req);
const { user: self } = await UserAction.getFromRequest(req);
if (!self) return errorResponse("Unauthorized", 401);
const user = await User.findOne({
const user = await UserAction.findOne({
where: {
id,
},

View file

@ -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, userRelations } from "~database/entities/User";
import { UserAction, userRelations } from "~database/entities/User";
import { applyConfig } from "@api";
export const meta = applyConfig({
@ -26,7 +26,7 @@ export default async (
): Promise<Response> => {
const id = matchedRoute.params.id;
const { user: self } = await User.getFromRequest(req);
const { user: self } = await UserAction.getFromRequest(req);
if (!self) return errorResponse("Unauthorized", 401);
@ -36,7 +36,7 @@ export default async (
languages?: string[];
}>(req);
const user = await User.findOne({
const user = await UserAction.findOne({
where: {
id,
},

View file

@ -1,6 +1,6 @@
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import { User, userRelations } from "~database/entities/User";
import { UserAction, userRelations } from "~database/entities/User";
import { applyConfig } from "@api";
export const meta = applyConfig({
@ -24,11 +24,11 @@ export default async (
): Promise<Response> => {
const id = matchedRoute.params.id;
const { user } = await User.getFromRequest(req);
const { user } = await UserAction.getFromRequest(req);
let foundUser: User | null;
let foundUser: UserAction | null;
try {
foundUser = await User.findOne({
foundUser = await UserAction.findOne({
where: {
id,
},

View file

@ -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, userRelations } from "~database/entities/User";
import { UserAction, userRelations } from "~database/entities/User";
import { applyConfig } from "@api";
export const meta = applyConfig({
@ -26,7 +26,7 @@ export default async (
): Promise<Response> => {
const id = matchedRoute.params.id;
const { user: self } = await User.getFromRequest(req);
const { user: self } = await UserAction.getFromRequest(req);
if (!self) return errorResponse("Unauthorized", 401);
@ -36,7 +36,7 @@ export default async (
duration: number;
}>(req);
const user = await User.findOne({
const user = await UserAction.findOne({
where: {
id,
},

View file

@ -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, userRelations } from "~database/entities/User";
import { UserAction, userRelations } from "~database/entities/User";
import { applyConfig } from "@api";
export const meta = applyConfig({
@ -26,7 +26,7 @@ export default async (
): Promise<Response> => {
const id = matchedRoute.params.id;
const { user: self } = await User.getFromRequest(req);
const { user: self } = await UserAction.getFromRequest(req);
if (!self) return errorResponse("Unauthorized", 401);
@ -34,7 +34,7 @@ export default async (
comment: string;
}>(req);
const user = await User.findOne({
const user = await UserAction.findOne({
where: {
id,
},

View file

@ -1,7 +1,7 @@
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import { Relationship } from "~database/entities/Relationship";
import { User, userRelations } from "~database/entities/User";
import { UserAction, userRelations } from "~database/entities/User";
import { applyConfig } from "@api";
export const meta = applyConfig({
@ -25,11 +25,11 @@ export default async (
): Promise<Response> => {
const id = matchedRoute.params.id;
const { user: self } = await User.getFromRequest(req);
const { user: self } = await UserAction.getFromRequest(req);
if (!self) return errorResponse("Unauthorized", 401);
const user = await User.findOne({
const user = await UserAction.findOne({
where: {
id,
},

View file

@ -1,7 +1,7 @@
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import { Relationship } from "~database/entities/Relationship";
import { User, userRelations } from "~database/entities/User";
import { UserAction, userRelations } from "~database/entities/User";
import { applyConfig } from "@api";
export const meta = applyConfig({
@ -25,11 +25,11 @@ export default async (
): Promise<Response> => {
const id = matchedRoute.params.id;
const { user: self } = await User.getFromRequest(req);
const { user: self } = await UserAction.getFromRequest(req);
if (!self) return errorResponse("Unauthorized", 401);
const user = await User.findOne({
const user = await UserAction.findOne({
where: {
id,
},

View file

@ -2,7 +2,7 @@
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import { Status, statusAndUserRelations } from "~database/entities/Status";
import { User, userRelations } from "~database/entities/User";
import { UserAction, userRelations } from "~database/entities/User";
import { applyConfig } from "@api";
import { FindManyOptions } from "typeorm";
@ -47,7 +47,7 @@ export default async (
tagged?: string;
} = matchedRoute.query;
const user = await User.findOne({
const user = await UserAction.findOne({
where: {
id,
},

View file

@ -1,7 +1,7 @@
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import { Relationship } from "~database/entities/Relationship";
import { User, userRelations } from "~database/entities/User";
import { UserAction, userRelations } from "~database/entities/User";
import { applyConfig } from "@api";
export const meta = applyConfig({
@ -25,11 +25,11 @@ export default async (
): Promise<Response> => {
const id = matchedRoute.params.id;
const { user: self } = await User.getFromRequest(req);
const { user: self } = await UserAction.getFromRequest(req);
if (!self) return errorResponse("Unauthorized", 401);
const user = await User.findOne({
const user = await UserAction.findOne({
where: {
id,
},

View file

@ -1,7 +1,7 @@
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import { Relationship } from "~database/entities/Relationship";
import { User, userRelations } from "~database/entities/User";
import { UserAction, userRelations } from "~database/entities/User";
import { applyConfig } from "@api";
export const meta = applyConfig({
@ -25,11 +25,11 @@ export default async (
): Promise<Response> => {
const id = matchedRoute.params.id;
const { user: self } = await User.getFromRequest(req);
const { user: self } = await UserAction.getFromRequest(req);
if (!self) return errorResponse("Unauthorized", 401);
const user = await User.findOne({
const user = await UserAction.findOne({
where: {
id,
},

View file

@ -1,7 +1,7 @@
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import { Relationship } from "~database/entities/Relationship";
import { User, userRelations } from "~database/entities/User";
import { UserAction, userRelations } from "~database/entities/User";
import { applyConfig } from "@api";
export const meta = applyConfig({
@ -25,11 +25,11 @@ export default async (
): Promise<Response> => {
const id = matchedRoute.params.id;
const { user: self } = await User.getFromRequest(req);
const { user: self } = await UserAction.getFromRequest(req);
if (!self) return errorResponse("Unauthorized", 401);
const user = await User.findOne({
const user = await UserAction.findOne({
where: {
id,
},

View file

@ -1,7 +1,7 @@
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import { Relationship } from "~database/entities/Relationship";
import { User, userRelations } from "~database/entities/User";
import { UserAction, userRelations } from "~database/entities/User";
import { applyConfig } from "@api";
export const meta = applyConfig({
@ -25,11 +25,11 @@ export default async (
): Promise<Response> => {
const id = matchedRoute.params.id;
const { user: self } = await User.getFromRequest(req);
const { user: self } = await UserAction.getFromRequest(req);
if (!self) return errorResponse("Unauthorized", 401);
const user = await User.findOne({
const user = await UserAction.findOne({
where: {
id,
},

View file

@ -1,6 +1,6 @@
import { parseRequest } from "@request";
import { errorResponse, jsonResponse } from "@response";
import { User } from "~database/entities/User";
import { UserAction } from "~database/entities/User";
import { APIAccount } from "~types/entities/account";
import { applyConfig } from "@api";
@ -20,7 +20,7 @@ export const meta = applyConfig({
* Find familiar followers (followers of a user that you also follow)
*/
export default async (req: Request): Promise<Response> => {
const { user: self } = await User.getFromRequest(req);
const { user: self } = await UserAction.getFromRequest(req);
if (!self) return errorResponse("Unauthorized", 401);
@ -39,7 +39,7 @@ export default async (req: Request): Promise<Response> => {
// Find followers of user that you also follow
// Get user
const user = await User.findOne({
const user = await UserAction.findOne({
where: { id },
relations: {
relationships: {

View file

@ -2,7 +2,7 @@ import { getConfig } from "@config";
import { parseRequest } from "@request";
import { jsonResponse } from "@response";
import { tempmailDomains } from "@tempmail";
import { User } from "~database/entities/User";
import { UserAction } from "~database/entities/User";
import { applyConfig } from "@api";
export const meta = applyConfig({
@ -115,7 +115,7 @@ export default async (req: Request): Promise<Response> => {
});
// Check if username is taken
if (await User.findOne({ where: { username: body.username } }))
if (await UserAction.findOne({ where: { username: body.username } }))
errors.details.username.push({
error: "ERR_TAKEN",
description: `is already taken`,
@ -170,7 +170,7 @@ export default async (req: Request): Promise<Response> => {
// TODO: Check if locale is valid
await User.createNewLocal({
await UserAction.createNewLocal({
username: body.username ?? "",
password: body.password ?? "",
email: body.email ?? "",

View file

@ -1,7 +1,7 @@
import { parseRequest } from "@request";
import { errorResponse, jsonResponse } from "@response";
import { Relationship } from "~database/entities/Relationship";
import { User } from "~database/entities/User";
import { UserAction } from "~database/entities/User";
import { applyConfig } from "@api";
export const meta = applyConfig({
@ -20,7 +20,7 @@ export const meta = applyConfig({
* Find relationships
*/
export default async (req: Request): Promise<Response> => {
const { user: self } = await User.getFromRequest(req);
const { user: self } = await UserAction.getFromRequest(req);
if (!self) return errorResponse("Unauthorized", 401);
@ -38,7 +38,7 @@ export default async (req: Request): Promise<Response> => {
const relationships = (
await Promise.all(
ids.map(async id => {
const user = await User.findOneBy({ id });
const user = await UserAction.findOneBy({ id });
if (!user) return null;
let relationship = await self.getRelationshipToOtherUser(user);

View file

@ -1,12 +1,12 @@
import { getConfig } from "@config";
import { parseRequest } from "@request";
import { errorResponse, jsonResponse } from "@response";
import { User } from "~database/entities/User";
import { UserAction } from "~database/entities/User";
import { applyConfig } from "@api";
import { sanitize } from "isomorphic-dompurify";
import { sanitizeHtml } from "@sanitization";
import { uploadFile } from "~classes/media";
import { Emoji } from "~database/entities/Emoji";
import { EmojiAction } from "~database/entities/Emoji";
export const meta = applyConfig({
allowedMethods: ["PATCH"],
@ -24,7 +24,7 @@ export const meta = applyConfig({
* Patches a user
*/
export default async (req: Request): Promise<Response> => {
const { user } = await User.getFromRequest(req);
const { user } = await UserAction.getFromRequest(req);
if (!user) return errorResponse("Unauthorized", 401);
@ -202,8 +202,8 @@ export default async (req: Request): Promise<Response> => {
// Parse emojis
const displaynameEmojis = await Emoji.parseEmojis(sanitizedDisplayName);
const noteEmojis = await Emoji.parseEmojis(sanitizedNote);
const displaynameEmojis = await EmojiAction.parseEmojis(sanitizedDisplayName);
const noteEmojis = await EmojiAction.parseEmojis(sanitizedNote);
user.emojis = [...displaynameEmojis, ...noteEmojis];

View file

@ -1,5 +1,5 @@
import { errorResponse, jsonResponse } from "@response";
import { User } from "~database/entities/User";
import { UserAction } from "~database/entities/User";
import { applyConfig } from "@api";
export const meta = applyConfig({
@ -17,7 +17,7 @@ export const meta = applyConfig({
export default async (req: Request): Promise<Response> => {
// TODO: Add checks for disabled or not email verified accounts
const { user } = await User.getFromRequest(req);
const { user } = await UserAction.getFromRequest(req);
if (!user) return errorResponse("Unauthorized", 401);

View file

@ -2,7 +2,7 @@ import { applyConfig } from "@api";
import { parseRequest } from "@request";
import { errorResponse, jsonResponse } from "@response";
import { randomBytes } from "crypto";
import { Application } from "~database/entities/Application";
import { ApplicationAction } from "~database/entities/Application";
export const meta = applyConfig({
allowedMethods: ["POST"],
@ -27,7 +27,7 @@ export default async (req: Request): Promise<Response> => {
website: string;
}>(req);
const application = new Application();
const application = new ApplicationAction();
application.name = client_name || "";

View file

@ -1,7 +1,7 @@
import { applyConfig } from "@api";
import { errorResponse, jsonResponse } from "@response";
import { Application } from "~database/entities/Application";
import { User } from "~database/entities/User";
import { ApplicationAction } from "~database/entities/Application";
import { UserAction } from "~database/entities/User";
export const meta = applyConfig({
allowedMethods: ["GET"],
@ -19,8 +19,8 @@ export const meta = applyConfig({
* Returns OAuth2 credentials
*/
export default async (req: Request): Promise<Response> => {
const { user, token } = await User.getFromRequest(req);
const application = await Application.getFromToken(token);
const { user, token } = await UserAction.getFromRequest(req);
const application = await ApplicationAction.getFromToken(token);
if (!user) return errorResponse("Unauthorized", 401);
if (!application) return errorResponse("Unauthorized", 401);

View file

@ -1,7 +1,7 @@
import { applyConfig } from "@api";
import { jsonResponse } from "@response";
import { IsNull } from "typeorm";
import { Emoji } from "~database/entities/Emoji";
import { EmojiAction } from "~database/entities/Emoji";
export const meta = applyConfig({
allowedMethods: ["GET"],
@ -20,7 +20,7 @@ export const meta = applyConfig({
*/
// eslint-disable-next-line @typescript-eslint/require-await
export default async (): Promise<Response> => {
const emojis = await Emoji.findBy({
const emojis = await EmojiAction.findBy({
instance: IsNull(),
});

View file

@ -2,7 +2,7 @@ import { applyConfig } from "@api";
import { getConfig } from "@config";
import { jsonResponse } from "@response";
import { Status } from "~database/entities/Status";
import { User } from "~database/entities/User";
import { UserAction } from "~database/entities/User";
export const meta = applyConfig({
allowedMethods: ["GET"],
@ -24,7 +24,7 @@ export default async (): Promise<Response> => {
const config = getConfig();
const statusCount = await Status.count();
const userCount = await User.count();
const userCount = await UserAction.count();
// TODO: fill in more values
return jsonResponse({

View file

@ -2,7 +2,7 @@ import { applyConfig } from "@api";
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import { Status, statusAndUserRelations } from "~database/entities/Status";
import { User } from "~database/entities/User";
import { UserAction } from "~database/entities/User";
import { APIRouteMeta } from "~types/api";
export const meta: APIRouteMeta = applyConfig({
@ -28,7 +28,7 @@ export default async (
// User token + read:statuses for up to 4,096 ancestors, 4,096 descendants, unlimited depth, and private statuses.
const id = matchedRoute.params.id;
const { user } = await User.getFromRequest(req);
const { user } = await UserAction.getFromRequest(req);
let foundStatus: Status | null;
try {

View file

@ -4,7 +4,7 @@ import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import { Like } from "~database/entities/Like";
import { Status, statusAndUserRelations } from "~database/entities/Status";
import { User, userRelations } from "~database/entities/User";
import { UserAction, userRelations } from "~database/entities/User";
import { APIRouteMeta } from "~types/api";
export const meta: APIRouteMeta = applyConfig({
@ -28,7 +28,7 @@ export default async (
): Promise<Response> => {
const id = matchedRoute.params.id;
const { user } = await User.getFromRequest(req);
const { user } = await UserAction.getFromRequest(req);
if (!user) return errorResponse("Unauthorized", 401);

View file

@ -6,7 +6,7 @@ import { MatchedRoute } from "bun";
import { FindManyOptions } from "typeorm";
import { Like } from "~database/entities/Like";
import { Status, statusAndUserRelations } from "~database/entities/Status";
import { User, userRelations } from "~database/entities/User";
import { UserAction, userRelations } from "~database/entities/User";
import { APIRouteMeta } from "~types/api";
export const meta: APIRouteMeta = applyConfig({
@ -30,7 +30,7 @@ export default async (
): Promise<Response> => {
const id = matchedRoute.params.id;
const { user } = await User.getFromRequest(req);
const { user } = await UserAction.getFromRequest(req);
let foundStatus: Status | null;
try {

View file

@ -2,7 +2,7 @@ import { applyConfig } from "@api";
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import { Status, statusAndUserRelations } from "~database/entities/Status";
import { User } from "~database/entities/User";
import { UserAction } from "~database/entities/User";
import { APIRouteMeta } from "~types/api";
export const meta: APIRouteMeta = applyConfig({
@ -27,7 +27,7 @@ export default async (
): Promise<Response> => {
const id = matchedRoute.params.id;
const { user } = await User.getFromRequest(req);
const { user } = await UserAction.getFromRequest(req);
let foundStatus: Status | null;
try {

View file

@ -5,7 +5,7 @@ import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import { FindManyOptions } from "typeorm";
import { Status, statusAndUserRelations } from "~database/entities/Status";
import { User } from "~database/entities/User";
import { UserAction } from "~database/entities/User";
import { APIRouteMeta } from "~types/api";
export const meta: APIRouteMeta = applyConfig({
@ -29,7 +29,7 @@ export default async (
): Promise<Response> => {
const id = matchedRoute.params.id;
const { user } = await User.getFromRequest(req);
const { user } = await UserAction.getFromRequest(req);
let foundStatus: Status | null;
try {

View file

@ -4,7 +4,7 @@ import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import { Like } from "~database/entities/Like";
import { Status, statusAndUserRelations } from "~database/entities/Status";
import { User } from "~database/entities/User";
import { UserAction } from "~database/entities/User";
import { APIRouteMeta } from "~types/api";
export const meta: APIRouteMeta = applyConfig({
@ -28,7 +28,7 @@ export default async (
): Promise<Response> => {
const id = matchedRoute.params.id;
const { user } = await User.getFromRequest(req);
const { user } = await UserAction.getFromRequest(req);
if (!user) return errorResponse("Unauthorized", 401);

View file

@ -6,10 +6,11 @@ import { getConfig } from "@config";
import { parseRequest } from "@request";
import { errorResponse, jsonResponse } from "@response";
import { sanitizeHtml } from "@sanitization";
import { MatchedRoute } from "bun";
import { parse } from "marked";
import { Application } from "~database/entities/Application";
import { ApplicationAction } from "~database/entities/Application";
import { Status, statusRelations } from "~database/entities/Status";
import { User } from "~database/entities/User";
import { AuthData, UserAction } from "~database/entities/User";
import { APIRouteMeta } from "~types/api";
export const meta: APIRouteMeta = applyConfig({
@ -27,9 +28,13 @@ export const meta: APIRouteMeta = applyConfig({
/**
* Post new status
*/
export default async (req: Request): Promise<Response> => {
const { user, token } = await User.getFromRequest(req);
const application = await Application.getFromToken(token);
export default async (
req: Request,
matchedRoute: MatchedRoute,
authData: AuthData
): Promise<Response> => {
const { user, token } = authData;
const application = await ApplicationAction.getFromToken(token);
if (!user) return errorResponse("Unauthorized", 401);
@ -122,7 +127,7 @@ export default async (req: Request): Promise<Response> => {
// Get reply account and status if exists
let replyStatus: Status | null = null;
let replyUser: User | null = null;
let replyUser: UserAction | null = null;
if (in_reply_to_id) {
replyStatus = await Status.findOne({

View file

@ -2,9 +2,10 @@
import { applyConfig } from "@api";
import { parseRequest } from "@request";
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import { FindManyOptions } from "typeorm";
import { Status, statusAndUserRelations } from "~database/entities/Status";
import { User } from "~database/entities/User";
import { AuthData } from "~database/entities/User";
import { APIRouteMeta } from "~types/api";
export const meta: APIRouteMeta = applyConfig({
@ -22,7 +23,11 @@ export const meta: APIRouteMeta = applyConfig({
/**
* Fetch home timeline statuses
*/
export default async (req: Request): Promise<Response> => {
export default async (
req: Request,
matchedRoute: MatchedRoute,
authData: AuthData
): Promise<Response> => {
const {
limit = 20,
max_id,
@ -35,7 +40,7 @@ export default async (req: Request): Promise<Response> => {
limit?: number;
}>(req);
const { user } = await User.getFromRequest(req);
const { user } = authData;
if (limit < 1 || limit > 40) {
return errorResponse("Limit must be between 1 and 40", 400);

View file

@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import { applyConfig } from "@api";
import { parseRequest } from "@request";
import { errorResponse, jsonResponse } from "@response";
@ -18,9 +17,29 @@ export const meta: APIRouteMeta = applyConfig({
},
});
/**
* Fetch public timeline statuses
*/
const updateQuery = async (
id: string | undefined,
operator: string,
query: FindManyOptions<Status>
) => {
if (!id) return query;
const post = await Status.findOneBy({ id });
if (post) {
query = {
...query,
where: {
...query.where,
created_at: {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
...(query.where as any)?.created_at,
[operator]: post.created_at,
},
},
};
}
return query;
};
export default async (req: Request): Promise<Response> => {
const {
local,
@ -59,53 +78,9 @@ export default async (req: Request): Promise<Response> => {
relations: statusAndUserRelations,
};
if (max_id) {
const maxPost = await Status.findOneBy({ id: max_id });
if (maxPost) {
query = {
...query,
where: {
...query.where,
created_at: {
...(query.where as any)?.created_at,
$lt: maxPost.created_at,
},
},
};
}
}
if (min_id) {
const minPost = await Status.findOneBy({ id: min_id });
if (minPost) {
query = {
...query,
where: {
...query.where,
created_at: {
...(query.where as any)?.created_at,
$gt: minPost.created_at,
},
},
};
}
}
if (since_id) {
const sincePost = await Status.findOneBy({ id: since_id });
if (sincePost) {
query = {
...query,
where: {
...query.where,
created_at: {
...(query.where as any)?.created_at,
$gte: sincePost.created_at,
},
},
};
}
}
query = await updateQuery(max_id, "$lt", query);
query = await updateQuery(min_id, "$gt", query);
query = await updateQuery(since_id, "$gte", query);
if (only_media) {
// TODO: add

View file

@ -2,9 +2,9 @@ import { applyConfig } from "@api";
import { errorResponse } from "@response";
import { MatchedRoute } from "bun";
import { randomBytes } from "crypto";
import { Application } from "~database/entities/Application";
import { ApplicationAction } from "~database/entities/Application";
import { Token } from "~database/entities/Token";
import { User, userRelations } from "~database/entities/User";
import { UserAction, userRelations } from "~database/entities/User";
import { APIRouteMeta } from "~types/api";
export const meta: APIRouteMeta = applyConfig({
@ -45,7 +45,7 @@ export default async (
return errorResponse("Missing username or password", 400);
// Get user
const user = await User.findOne({
const user = await UserAction.findOne({
where: {
email,
},
@ -56,7 +56,7 @@ export default async (
return errorResponse("Invalid username or password", 401);
// Get application
const application = await Application.findOneBy({
const application = await ApplicationAction.findOneBy({
client_id,
});

View file

@ -5,10 +5,10 @@ import { getConfig } from "@config";
import { getBestContentType } from "@content_types";
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import { Emoji } from "~database/entities/Emoji";
import { EmojiAction } from "~database/entities/Emoji";
import { LysandObject } from "~database/entities/Object";
import { Status } from "~database/entities/Status";
import { User, userRelations } from "~database/entities/User";
import { UserAction, userRelations } from "~database/entities/User";
import {
ContentFormat,
LysandAction,
@ -61,7 +61,7 @@ export default async (
// Process request body
const body = (await req.json()) as LysandPublication | LysandAction;
const author = await User.findOne({
const author = await UserAction.findOne({
where: {
uri: body.author,
},
@ -145,7 +145,7 @@ export default async (
const content = getBestContentType(body.contents);
const emojis = await Emoji.parseEmojis(content?.content || "");
const emojis = await EmojiAction.parseEmojis(content?.content || "");
const newStatus = await Status.createNew({
account: author,
@ -158,7 +158,7 @@ export default async (
sensitive: body.is_sensitive,
uri: body.uri,
emojis: emojis,
mentions: await User.parseMentions(body.mentions),
mentions: await UserAction.parseMentions(body.mentions),
});
// If there is a reply, fetch all the reply parents and add them to the database
@ -187,7 +187,7 @@ export default async (
const content = getBestContentType(patch.contents);
const emojis = await Emoji.parseEmojis(content?.content || "");
const emojis = await EmojiAction.parseEmojis(content?.content || "");
const status = await Status.findOneBy({
id: patch.patched_id,

View file

@ -4,7 +4,7 @@ import { applyConfig } from "@api";
import { getConfig } from "@config";
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import { User, userRelations } from "~database/entities/User";
import { UserAction, userRelations } from "~database/entities/User";
export const meta = applyConfig({
allowedMethods: ["POST"],
@ -29,7 +29,7 @@ export default async (
const config = getConfig();
const user = await User.findOne({
const user = await UserAction.findOne({
where: {
id: uuid,
},