All files / src/lib/api/admin search.ts

75% Statements 3/4
100% Branches 2/2
50% Functions 1/2
75% Lines 3/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36                                          95x   3x 3x                      
import { request } from "../base";
 
export interface SearchRebuildStats {
	rebuilt: Record<
		string,
		{ documents: number; size: string }
	>;
	timestamp: string;
}
 
export interface SearchIndexStatus {
	indexes: Record<
		"pro" | "project" | "room" | "blog",
		{
			exists: boolean;
			sizeBytes: number | null;
			lastModified: string | null;
		}
	>;
}
 
export const adminSearchApi = {
	rebuildIndex(type?: string) {
		const params = type ? `?type=${type}` : "";
		return request<SearchRebuildStats>(
			`/api/admin/search/rebuild${params}`,
			{ method: "POST" },
		);
	},
	// #358: surfaces real R2 index state so the admin page can show a
	// meaningful status without forcing a rebuild first.
	getStatus() {
		return request<SearchIndexStatus>(`/api/admin/search/status`);
	},
};