mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
refactor(api): ♻️ Move to Hono for HTTP
This commit is contained in:
parent
2237be3689
commit
826a260e90
155 changed files with 7226 additions and 6077 deletions
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue