XHS / frontend /src /lib /content.ts
Trae Bot
Fix .gitignore excluding frontend/src/lib and add missing TS modules
98277cb
import type { ApiError } from './api'
import { apiGetWrapped } from './api'
export type RawNoteRecord = {
id: number
source_platform: string | null
content: string | null
author: string | null
url: string | null
created_at: string | null
}
export type RawNoteListResponse = {
notes: RawNoteRecord[]
total: number
limit: number
offset: number
query: string | null
}
export type CleanedNoteRecord = {
id: number
raw_note_id: number | null
cleaned_content: string | null
created_at: string | null
raw_author: string | null
raw_url: string | null
}
export type CleanedNoteListResponse = {
notes: CleanedNoteRecord[]
total: number
limit: number
offset: number
query: string | null
}
export type ListContentParams = {
limit: number
offset: number
query?: string
}
function buildSearch(params: ListContentParams) {
const search = new URLSearchParams()
search.set('limit', String(params.limit))
search.set('offset', String(params.offset))
const q = String(params.query || '').trim()
if (q) search.set('query', q)
return search.toString()
}
export async function listRawNotes(params: ListContentParams) {
return apiGetWrapped<RawNoteListResponse>(`content/raw-notes?${buildSearch(params)}`)
}
export async function listCleanedNotes(params: ListContentParams) {
return apiGetWrapped<CleanedNoteListResponse>(`content/cleaned-notes?${buildSearch(params)}`)
}
export function isOrchestratorDbUnavailable(error: ApiError | null | undefined) {
if (!error) return false
if (error.status !== 503) return false
if (typeof error.message === 'string' && error.message.toLowerCase().includes('orchestrator db')) return true
const data = error.data
if (!data || typeof data !== 'object') return false
const obj = data as Record<string, unknown>
return obj.code === 10010 || obj.msg === 'orchestrator db unavailable'
}