refactor(api): ♻️ Move to Hono for HTTP

This commit is contained in:
Jesse Wierzbinski 2024-05-06 07:16:33 +00:00
parent 2237be3689
commit 826a260e90
No known key found for this signature in database
155 changed files with 7226 additions and 6077 deletions

View file

@ -3,10 +3,12 @@ import {
type InferInsertModel,
type SQL,
and,
count,
desc,
eq,
inArray,
isNotNull,
sql,
} from "drizzle-orm";
import { htmlToText } from "html-to-text";
import type * as Lysand from "lysand-types";
@ -161,6 +163,19 @@ export class Note {
return new User(this.status.author);
}
static async getCount() {
return (
await db
.select({
count: count(),
})
.from(Notes)
.where(
sql`EXISTS (SELECT 1 FROM "Users" WHERE "Users"."id" = ${Notes.authorId} AND "Users"."instanceId" IS NULL)`,
)
)[0].count;
}
async getReplyChildren() {
return await Note.manyFromSql(eq(Notes.replyId, this.status.id));
}

View file

@ -2,7 +2,17 @@ import { idValidator } from "@api";
import { getBestContentType, urlToContentFormat } from "@content_types";
import { addUserToMeilisearch } from "@meilisearch";
import { proxyUrl } from "@response";
import { type SQL, and, desc, eq, inArray } from "drizzle-orm";
import {
type SQL,
and,
count,
countDistinct,
desc,
eq,
gte,
inArray,
isNull,
} from "drizzle-orm";
import { htmlToText } from "html-to-text";
import type * as Lysand from "lysand-types";
import {
@ -20,6 +30,7 @@ import { db } from "~drizzle/db";
import {
EmojiToUser,
NoteToMentions,
Notes,
UserToPinnedNotes,
Users,
} from "~drizzle/schema";
@ -102,6 +113,37 @@ export class User {
return uri || new URL(`/users/${id}`, baseUrl).toString();
}
static async getCount() {
return (
await db
.select({
count: count(),
})
.from(Users)
.where(isNull(Users.instanceId))
)[0].count;
}
static async getActiveInPeriod(milliseconds: number) {
return (
await db
.select({
count: countDistinct(Users),
})
.from(Users)
.leftJoin(Notes, eq(Users.id, Notes.authorId))
.where(
and(
isNull(Users.instanceId),
gte(
Notes.createdAt,
new Date(Date.now() - milliseconds).toISOString(),
),
),
)
)[0].count;
}
async pin(note: Note) {
return (
await db