Enable verbatim module syntax + more API routes

This commit is contained in:
Jesse Wierzbinski 2023-11-22 18:10:37 -10:00
parent 991a2cba84
commit be9b2e3376
No known key found for this signature in database
84 changed files with 438 additions and 192 deletions

View file

@ -1,5 +1,5 @@
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import type { MatchedRoute } from "bun";
import {
createNewRelationship,
relationshipToAPI,

View file

@ -1,6 +1,6 @@
import { parseRequest } from "@request";
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import type { MatchedRoute } from "bun";
import {
createNewRelationship,
relationshipToAPI,

View file

@ -1,7 +1,7 @@
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import type { MatchedRoute } from "bun";
import type { UserWithRelations } from "~database/entities/User";
import {
UserWithRelations,
getFromRequest,
userRelations,
userToAPI,

View file

@ -1,6 +1,6 @@
import { parseRequest } from "@request";
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import type { MatchedRoute } from "bun";
import {
createNewRelationship,
relationshipToAPI,

View file

@ -1,6 +1,6 @@
import { parseRequest } from "@request";
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import type { MatchedRoute } from "bun";
import {
createNewRelationship,
relationshipToAPI,

View file

@ -1,5 +1,5 @@
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import type { MatchedRoute } from "bun";
import {
createNewRelationship,
relationshipToAPI,

View file

@ -1,5 +1,5 @@
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import type { MatchedRoute } from "bun";
import {
createNewRelationship,
relationshipToAPI,

View file

@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import type { MatchedRoute } from "bun";
import { statusAndUserRelations, statusToAPI } from "~database/entities/Status";
import { userRelations } from "~database/entities/User";
import { applyConfig } from "@api";

View file

@ -1,5 +1,5 @@
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import type { MatchedRoute } from "bun";
import {
createNewRelationship,
relationshipToAPI,

View file

@ -1,5 +1,5 @@
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import type { MatchedRoute } from "bun";
import {
createNewRelationship,
relationshipToAPI,

View file

@ -1,5 +1,5 @@
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import type { MatchedRoute } from "bun";
import {
createNewRelationship,
relationshipToAPI,

View file

@ -1,5 +1,5 @@
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import type { MatchedRoute } from "bun";
import {
createNewRelationship,
relationshipToAPI,

View file

@ -0,0 +1,40 @@
import { errorResponse, jsonResponse } from "@response";
import {
getFromRequest,
userRelations,
userToAPI,
} from "~database/entities/User";
import { applyConfig } from "@api";
import { client } from "~database/datasource";
export const meta = applyConfig({
allowedMethods: ["GET"],
route: "/api/v1/blocks",
ratelimits: {
max: 100,
duration: 60,
},
auth: {
required: true,
},
});
export default async (req: Request): Promise<Response> => {
const { user } = await getFromRequest(req);
if (!user) return errorResponse("Unauthorized", 401);
const blocks = await client.user.findMany({
where: {
relationshipSubjects: {
every: {
ownerId: user.id,
blocking: true,
},
},
},
include: userRelations,
});
return jsonResponse(blocks.map(u => userToAPI(u)));
};

View file

@ -2,11 +2,11 @@ import { applyConfig } from "@api";
import { errorResponse, jsonResponse } from "@response";
import { client } from "~database/datasource";
import { getFromRequest } from "~database/entities/User";
import { APIRouteMeta } from "~types/api";
import type { APIRouteMeta } from "~types/api";
import { uploadFile } from "~classes/media";
import { getConfig } from "@config";
import { attachmentToAPI, getUrl } from "~database/entities/Attachment";
import { MatchedRoute } from "bun";
import type { MatchedRoute } from "bun";
import { parseRequest } from "@request";
export const meta: APIRouteMeta = applyConfig({

View file

@ -0,0 +1,40 @@
import { errorResponse, jsonResponse } from "@response";
import {
getFromRequest,
userRelations,
userToAPI,
} from "~database/entities/User";
import { applyConfig } from "@api";
import { client } from "~database/datasource";
export const meta = applyConfig({
allowedMethods: ["GET"],
route: "/api/v1/mutes",
ratelimits: {
max: 100,
duration: 60,
},
auth: {
required: true,
},
});
export default async (req: Request): Promise<Response> => {
const { user } = await getFromRequest(req);
if (!user) return errorResponse("Unauthorized", 401);
const blocks = await client.user.findMany({
where: {
relationshipSubjects: {
every: {
ownerId: user.id,
muting: true,
},
},
},
include: userRelations,
});
return jsonResponse(blocks.map(u => userToAPI(u)));
};

View file

@ -0,0 +1,83 @@
import { errorResponse, jsonResponse } from "@response";
import { getFromRequest, userRelations } from "~database/entities/User";
import { applyConfig } from "@api";
import { client } from "~database/datasource";
import { statusAndUserRelations } from "~database/entities/Status";
import { parseRequest } from "@request";
import { notificationToAPI } from "~database/entities/Notification";
export const meta = applyConfig({
allowedMethods: ["GET"],
route: "/api/v1/notifications",
ratelimits: {
max: 100,
duration: 60,
},
auth: {
required: true,
},
});
export default async (req: Request): Promise<Response> => {
const { user } = await getFromRequest(req);
if (!user) return errorResponse("Unauthorized", 401);
const {
account_id,
exclude_types,
limit = 15,
max_id,
min_id,
since_id,
types,
} = await parseRequest<{
max_id?: string;
since_id?: string;
min_id?: string;
limit?: number;
exclude_types?: string[];
types?: string[];
account_id?: string;
}>(req);
if (limit > 30) return errorResponse("Limit too high", 400);
if (limit <= 0) return errorResponse("Limit too low", 400);
if (types && exclude_types) {
return errorResponse("Can't use both types and exclude_types", 400);
}
const notifications = await client.notification.findMany({
where: {
notifiedId: user.id,
id: {
lt: max_id,
gt: min_id,
gte: since_id,
},
type: {
in: types,
notIn: exclude_types,
},
accountId: account_id,
},
include: {
account: {
include: userRelations,
},
status: {
include: statusAndUserRelations,
},
},
orderBy: {
id: "asc",
},
take: limit,
});
return jsonResponse(
await Promise.all(notifications.map(n => notificationToAPI(n)))
);
};

View file

@ -6,7 +6,7 @@ import {
userRelations,
userToAPI,
} from "~database/entities/User";
import { APIRouteMeta } from "~types/api";
import type { APIRouteMeta } from "~types/api";
export const meta: APIRouteMeta = applyConfig({
allowedMethods: ["DELETE"],

View file

@ -6,7 +6,7 @@ import {
userRelations,
userToAPI,
} from "~database/entities/User";
import { APIRouteMeta } from "~types/api";
import type { APIRouteMeta } from "~types/api";
export const meta: APIRouteMeta = applyConfig({
allowedMethods: ["DELETE"],

View file

@ -1,6 +1,6 @@
import { applyConfig } from "@api";
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import type { MatchedRoute } from "bun";
import { client } from "~database/datasource";
import {
getAncestors,
@ -9,7 +9,7 @@ import {
statusToAPI,
} from "~database/entities/Status";
import { getFromRequest } from "~database/entities/User";
import { APIRouteMeta } from "~types/api";
import type { APIRouteMeta } from "~types/api";
export const meta: APIRouteMeta = applyConfig({
allowedMethods: ["GET"],

View file

@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import { applyConfig } from "@api";
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import type { MatchedRoute } from "bun";
import { client } from "~database/datasource";
import {
isViewableByUser,
@ -9,8 +9,8 @@ import {
statusToAPI,
} from "~database/entities/Status";
import { getFromRequest } from "~database/entities/User";
import { APIRouteMeta } from "~types/api";
import { APIStatus } from "~types/entities/status";
import type { APIRouteMeta } from "~types/api";
import type { APIStatus } from "~types/entities/status";
export const meta: APIRouteMeta = applyConfig({
allowedMethods: ["POST"],

View file

@ -2,7 +2,7 @@
import { applyConfig } from "@api";
import { parseRequest } from "@request";
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import type { MatchedRoute } from "bun";
import { client } from "~database/datasource";
import {
isViewableByUser,
@ -13,7 +13,7 @@ import {
userRelations,
userToAPI,
} from "~database/entities/User";
import { APIRouteMeta } from "~types/api";
import type { APIRouteMeta } from "~types/api";
export const meta: APIRouteMeta = applyConfig({
allowedMethods: ["GET"],

View file

@ -1,6 +1,6 @@
import { applyConfig } from "@api";
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import type { MatchedRoute } from "bun";
import { client } from "~database/datasource";
import {
isViewableByUser,
@ -8,7 +8,7 @@ import {
statusToAPI,
} from "~database/entities/Status";
import { getFromRequest } from "~database/entities/User";
import { APIRouteMeta } from "~types/api";
import type { APIRouteMeta } from "~types/api";
export const meta: APIRouteMeta = applyConfig({
allowedMethods: ["GET", "DELETE"],

View file

@ -3,7 +3,7 @@ import { applyConfig } from "@api";
import { getConfig } from "@config";
import { parseRequest } from "@request";
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import type { MatchedRoute } from "bun";
import { client } from "~database/datasource";
import {
isViewableByUser,
@ -11,7 +11,7 @@ import {
statusToAPI,
} from "~database/entities/Status";
import { getFromRequest } from "~database/entities/User";
import { APIRouteMeta } from "~types/api";
import type { APIRouteMeta } from "~types/api";
export const meta: APIRouteMeta = applyConfig({
allowedMethods: ["POST"],

View file

@ -2,7 +2,7 @@
import { applyConfig } from "@api";
import { parseRequest } from "@request";
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import type { MatchedRoute } from "bun";
import { client } from "~database/datasource";
import {
isViewableByUser,
@ -13,7 +13,7 @@ import {
userRelations,
userToAPI,
} from "~database/entities/User";
import { APIRouteMeta } from "~types/api";
import type { APIRouteMeta } from "~types/api";
export const meta: APIRouteMeta = applyConfig({
allowedMethods: ["GET"],

View file

@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import { applyConfig } from "@api";
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import type { MatchedRoute } from "bun";
import { client } from "~database/datasource";
import {
isViewableByUser,
@ -9,8 +9,8 @@ import {
statusToAPI,
} from "~database/entities/Status";
import { getFromRequest } from "~database/entities/User";
import { APIRouteMeta } from "~types/api";
import { APIStatus } from "~types/entities/status";
import type { APIRouteMeta } from "~types/api";
import type { APIStatus } from "~types/entities/status";
export const meta: APIRouteMeta = applyConfig({
allowedMethods: ["POST"],

View file

@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import { applyConfig } from "@api";
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import type { MatchedRoute } from "bun";
import { client } from "~database/datasource";
import {
isViewableByUser,
@ -9,8 +9,8 @@ import {
statusToAPI,
} from "~database/entities/Status";
import { getFromRequest } from "~database/entities/User";
import { APIRouteMeta } from "~types/api";
import { APIStatus } from "~types/entities/status";
import type { APIRouteMeta } from "~types/api";
import type { APIStatus } from "~types/entities/status";
export const meta: APIRouteMeta = applyConfig({
allowedMethods: ["POST"],

View file

@ -6,18 +6,18 @@ import { getConfig } from "@config";
import { parseRequest } from "@request";
import { errorResponse, jsonResponse } from "@response";
import { sanitizeHtml } from "@sanitization";
import { MatchedRoute } from "bun";
import type { MatchedRoute } from "bun";
import { parse } from "marked";
import { client } from "~database/datasource";
import { getFromToken } from "~database/entities/Application";
import type { StatusWithRelations } from "~database/entities/Status";
import {
StatusWithRelations,
createNewStatus,
statusAndUserRelations,
statusToAPI,
} from "~database/entities/Status";
import { AuthData, UserWithRelations } from "~database/entities/User";
import { APIRouteMeta } from "~types/api";
import type { AuthData, UserWithRelations } from "~database/entities/User";
import type { APIRouteMeta } from "~types/api";
export const meta: APIRouteMeta = applyConfig({
allowedMethods: ["POST"],

View file

@ -5,7 +5,7 @@ import { errorResponse, jsonResponse } from "@response";
import { client } from "~database/datasource";
import { statusAndUserRelations, statusToAPI } from "~database/entities/Status";
import { getFromRequest } from "~database/entities/User";
import { APIRouteMeta } from "~types/api";
import type { APIRouteMeta } from "~types/api";
export const meta: APIRouteMeta = applyConfig({
allowedMethods: ["GET"],

View file

@ -3,7 +3,7 @@ import { parseRequest } from "@request";
import { errorResponse, jsonResponse } from "@response";
import { client } from "~database/datasource";
import { statusAndUserRelations, statusToAPI } from "~database/entities/Status";
import { APIRouteMeta } from "~types/api";
import type { APIRouteMeta } from "~types/api";
export const meta: APIRouteMeta = applyConfig({
allowedMethods: ["GET"],

View file

@ -3,7 +3,7 @@ import { errorResponse, jsonResponse } from "@response";
import { client } from "~database/datasource";
import { encode } from "blurhash";
import { getFromRequest } from "~database/entities/User";
import { APIRouteMeta } from "~types/api";
import type { APIRouteMeta } from "~types/api";
import sharp from "sharp";
import { uploadFile } from "~classes/media";
import { getConfig } from "@config";

View file

@ -1,11 +1,11 @@
import { applyConfig } from "@api";
import { errorResponse } from "@response";
import { MatchedRoute } from "bun";
import type { MatchedRoute } from "bun";
import { randomBytes } from "crypto";
import { client } from "~database/datasource";
import { TokenType } from "~database/entities/Token";
import { userRelations } from "~database/entities/User";
import { APIRouteMeta } from "~types/api";
import type { APIRouteMeta } from "~types/api";
export const meta: APIRouteMeta = applyConfig({
allowedMethods: ["POST"],

View file

@ -1,5 +1,5 @@
import { applyConfig } from "@api";
import { MatchedRoute } from "bun";
import type { MatchedRoute } from "bun";
export const meta = applyConfig({
allowedMethods: ["GET"],

View file

@ -2,7 +2,7 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { applyConfig } from "@api";
import { jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import type { MatchedRoute } from "bun";
export const meta = applyConfig({
allowedMethods: ["GET"],

View file

@ -4,7 +4,7 @@ import { applyConfig } from "@api";
import { getConfig } from "@config";
import { getBestContentType } from "@content_types";
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import type { MatchedRoute } from "bun";
import { client } from "~database/datasource";
import { parseEmojis } from "~database/entities/Emoji";
import { createFromObject } from "~database/entities/Object";
@ -14,7 +14,11 @@ import {
statusAndUserRelations,
} from "~database/entities/Status";
import { parseMentionsUris, userRelations } from "~database/entities/User";
import { LysandAction, LysandPublication, Patch } from "~types/lysand/Object";
import type {
LysandAction,
LysandPublication,
Patch,
} from "~types/lysand/Object";
export const meta = applyConfig({
allowedMethods: ["POST"],

View file

@ -3,7 +3,7 @@
import { applyConfig } from "@api";
import { getConfig } from "@config";
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import type { MatchedRoute } from "bun";
import { client } from "~database/datasource";
import { userRelations, userToLysand } from "~database/entities/User";

View file

@ -1,5 +1,5 @@
import { jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import type { MatchedRoute } from "bun";
import { getConfig, getHost } from "@config";
import { applyConfig } from "@api";
import {