SPB Git forge

spb/immbot-ai

Public
1commits 1branches 0releases
1.5 MBsize
maindefault branch
20 days agolast push
TypeScript 98.3% CSS 0.9% Shell 0.7%
1.3 KB · 34 lines typescript
Raw Blame History
1import { NextResponse } from "next/server";2import { apiError } from "@/lib/api.ts";3import { requireUser } from "@/lib/auth/session.ts";4import { all } from "@/lib/db/index.ts";56export async function GET(req: Request) {7  try {8    const user = await requireUser();9    const url = new URL(req.url);10    const q = url.searchParams.get("q")?.trim();11    const archived = url.searchParams.get("archived") === "1" ? 1 : 0;12    let rows;13    if (q) {14      rows = all(15        `SELECT DISTINCT c.id, c.title, c.folder, c.pinned, c.archived, c.course_code, c.mode, c.knowledge_mode, c.model, c.updated_at16         FROM conversations c LEFT JOIN messages m ON m.conversation_id = c.id17         WHERE c.user_id = ? AND c.archived = ? AND (c.title LIKE ? OR m.content LIKE ?)18         ORDER BY c.pinned DESC, c.updated_at DESC LIMIT 100`,19        user.id, archived, `%${q}%`, `%${q}%`20      );21    } else {22      rows = all(23        `SELECT id, title, folder, pinned, archived, course_code, mode, knowledge_mode, model, updated_at24         FROM conversations WHERE user_id = ? AND archived = ?25         ORDER BY pinned DESC, updated_at DESC LIMIT 200`,26        user.id, archived27      );28    }29    return NextResponse.json({ conversations: rows });30  } catch (e) {31    return apiError(e);32  }33}34