mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-05-05 15:30:40 +00:00
brought all the APIs back
This commit is contained in:
parent
ed9f15ec6e
commit
c12ecfc431
27 changed files with 430 additions and 98 deletions
47
apps/web/app/api/getCount/route.ts
Normal file
47
apps/web/app/api/getCount/route.ts
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import { db } from "@/app/helpers/server/db";
|
||||
import { and, eq, ne, sql } from "drizzle-orm";
|
||||
import { sessions, storedContent, users } from "@/app/helpers/server/db/schema";
|
||||
import { type NextRequest, NextResponse } from "next/server";
|
||||
import { ensureAuth } from "../ensureAuth";
|
||||
|
||||
export const runtime = "edge";
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const session = await ensureAuth(req);
|
||||
|
||||
if (!session) {
|
||||
return new Response("Unauthorized", { status: 401 });
|
||||
}
|
||||
|
||||
const tweetsCount = await db
|
||||
.select({
|
||||
count: sql<number>`count(*)`.mapWith(Number),
|
||||
})
|
||||
.from(storedContent)
|
||||
.where(
|
||||
and(
|
||||
eq(storedContent.user, session.user.id),
|
||||
eq(storedContent.type, "twitter-bookmark"),
|
||||
),
|
||||
);
|
||||
|
||||
const pageCount = await db
|
||||
.select({
|
||||
count: sql<number>`count(*)`.mapWith(Number),
|
||||
})
|
||||
.from(storedContent)
|
||||
.where(
|
||||
and(
|
||||
eq(storedContent.user, session.user.id),
|
||||
ne(storedContent.type, "twitter-bookmark"),
|
||||
),
|
||||
);
|
||||
|
||||
return NextResponse.json({
|
||||
tweetsCount: tweetsCount[0]!.count,
|
||||
tweetsLimit: 1000,
|
||||
pageCount: pageCount[0]!.count,
|
||||
pageLimit: 100,
|
||||
user: session.user.email,
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue