fix(web): retire session archive UI and API, restore archived rows
Remove archive/restore from the session menu and drop archived=1 listing. PATCH still accepts archived_at from old bundles then ignores it. A forward migration clears archived_at without bumping updated_at. Delete stays unchanged.
This commit is contained in:
@@ -20,6 +20,10 @@ function payloadHasMessages(payload: unknown): payload is { messages: unknown }
|
||||
return Boolean(payload && typeof payload === "object" && !Array.isArray(payload) && "messages" in payload);
|
||||
}
|
||||
|
||||
function payloadHasIgnoredArchive(payload: unknown): boolean {
|
||||
return Boolean(payload && typeof payload === "object" && !Array.isArray(payload) && "archived_at" in payload);
|
||||
}
|
||||
|
||||
function ignoredMessageCount(payload: { messages: unknown }) {
|
||||
return Array.isArray(payload.messages) ? payload.messages.length : 0;
|
||||
}
|
||||
@@ -81,7 +85,7 @@ export async function PATCH(request: Request, context: RouteContext) {
|
||||
if (!values && modelPatch.success) {
|
||||
values = { ...modelPatch.data };
|
||||
}
|
||||
if (!values && payloadHasMessages(payload)) {
|
||||
if (!values && (payloadHasMessages(payload) || payloadHasIgnoredArchive(payload))) {
|
||||
return NextResponse.json({ ok: true });
|
||||
}
|
||||
if (!values) {
|
||||
|
||||
@@ -11,12 +11,11 @@ import { isSupabaseConfigurationError } from "@/lib/supabase/config";
|
||||
import { createServerSupabaseClient } from "@/lib/supabase/server";
|
||||
import {
|
||||
clampSessionLimit,
|
||||
isArchivedSessionQuery,
|
||||
nextSessionCursor,
|
||||
parseSessionCursor,
|
||||
sessionCursorFilter,
|
||||
} from "@/lib/session-cursor";
|
||||
import { applyArchiveFilter, excludeEmptyConsultations } from "@/lib/session-list-filter";
|
||||
import { excludeEmptyConsultations } from "@/lib/session-list-filter";
|
||||
|
||||
const SESSION_LIST_COLUMNS = "id,title,theme,model_id,session_type,rectification_case_id,chart_profile_id,chart_profile_name,chart_profile_role,updated_at,pinned,archived_at";
|
||||
|
||||
@@ -24,7 +23,6 @@ export async function GET(request: Request) {
|
||||
try {
|
||||
const url = new URL(request.url);
|
||||
const limit = clampSessionLimit(url.searchParams.get("limit"));
|
||||
const archived = isArchivedSessionQuery(url.searchParams.get("archived"));
|
||||
const beforeRaw = url.searchParams.get("before");
|
||||
const cursor = parseSessionCursor(beforeRaw);
|
||||
if (beforeRaw && !cursor) {
|
||||
@@ -35,14 +33,12 @@ export async function GET(request: Request) {
|
||||
if (authError || !user) return NextResponse.json({ error: "请先登录" }, { status: 401 });
|
||||
|
||||
let pageQuery = excludeEmptyConsultations(
|
||||
applyArchiveFilter(
|
||||
supabase
|
||||
.from("chat_sessions")
|
||||
.select(SESSION_LIST_COLUMNS)
|
||||
.eq("user_id", user.id)
|
||||
.eq("pinned", false),
|
||||
archived,
|
||||
),
|
||||
supabase
|
||||
.from("chat_sessions")
|
||||
.select(SESSION_LIST_COLUMNS)
|
||||
.eq("user_id", user.id)
|
||||
.eq("pinned", false)
|
||||
.is("archived_at", null),
|
||||
)
|
||||
.order("updated_at", { ascending: false })
|
||||
.order("id", { ascending: false })
|
||||
@@ -56,14 +52,12 @@ export async function GET(request: Request) {
|
||||
let pinnedRows: typeof pageRows = [];
|
||||
if (!cursor) {
|
||||
const { data: pinnedData, error: pinnedError } = await excludeEmptyConsultations(
|
||||
applyArchiveFilter(
|
||||
supabase
|
||||
.from("chat_sessions")
|
||||
.select(SESSION_LIST_COLUMNS)
|
||||
.eq("user_id", user.id)
|
||||
.eq("pinned", true),
|
||||
archived,
|
||||
),
|
||||
supabase
|
||||
.from("chat_sessions")
|
||||
.select(SESSION_LIST_COLUMNS)
|
||||
.eq("user_id", user.id)
|
||||
.eq("pinned", true)
|
||||
.is("archived_at", null),
|
||||
)
|
||||
.order("updated_at", { ascending: false })
|
||||
.order("id", { ascending: false });
|
||||
|
||||
Reference in New Issue
Block a user