|
| 1 | +import { apiGet, apiPost } from "./client"; |
| 2 | +import type { PageResponse, PageVersionResponse } from "./types"; |
| 3 | + |
| 4 | +export async function listPages( |
| 5 | + repoId: string, |
| 6 | + opts?: { page_type?: string; sort_by?: string; order?: string; limit?: number; offset?: number }, |
| 7 | +): Promise<PageResponse[]> { |
| 8 | + return apiGet<PageResponse[]>("/api/pages", { repo_id: repoId, ...opts }); |
| 9 | +} |
| 10 | + |
| 11 | +/** Fetch all pages for a repo, auto-paginating through the 500-item backend limit. */ |
| 12 | +export async function listAllPages( |
| 13 | + repoId: string, |
| 14 | + opts?: { page_type?: string; sort_by?: string; order?: string }, |
| 15 | +): Promise<PageResponse[]> { |
| 16 | + const PAGE_SIZE = 500; |
| 17 | + const all: PageResponse[] = []; |
| 18 | + let offset = 0; |
| 19 | + |
| 20 | + while (true) { |
| 21 | + const batch = await listPages(repoId, { ...opts, limit: PAGE_SIZE, offset }); |
| 22 | + all.push(...batch); |
| 23 | + if (batch.length < PAGE_SIZE) break; |
| 24 | + offset += PAGE_SIZE; |
| 25 | + } |
| 26 | + |
| 27 | + return all; |
| 28 | +} |
| 29 | + |
| 30 | +/** Get page by its ID using the query-param endpoint (avoids path conflicts) */ |
| 31 | +export async function getPageById(pageId: string): Promise<PageResponse> { |
| 32 | + return apiGet<PageResponse>("/api/pages/lookup", { page_id: pageId }); |
| 33 | +} |
| 34 | + |
| 35 | +/** Get page versions by ID */ |
| 36 | +export async function getPageVersions( |
| 37 | + pageId: string, |
| 38 | + limit = 50, |
| 39 | +): Promise<PageVersionResponse[]> { |
| 40 | + return apiGet<PageVersionResponse[]>("/api/pages/lookup/versions", { |
| 41 | + page_id: pageId, |
| 42 | + limit, |
| 43 | + }); |
| 44 | +} |
| 45 | + |
| 46 | +/** Force-regenerate a page by ID */ |
| 47 | +export async function regeneratePage(pageId: string): Promise<{ job_id: string }> { |
| 48 | + return apiPost<{ job_id: string }>(`/api/pages/lookup/regenerate?page_id=${encodeURIComponent(pageId)}`); |
| 49 | +} |
0 commit comments