fix(search): harden authorized results and ordering
This commit is contained in:
@@ -8,6 +8,7 @@ type RequestOptions = {
|
||||
body?: unknown
|
||||
token?: string
|
||||
responseType?: 'json' | 'void'
|
||||
signal?: AbortSignal
|
||||
}
|
||||
|
||||
type ErrorEnvelope = {
|
||||
@@ -59,6 +60,7 @@ export async function apiRequest<T>(path: string, options: RequestOptions = {}):
|
||||
...(options.token ? { Authorization: `Bearer ${options.token}` } : {}),
|
||||
},
|
||||
body: requestBody as BodyInit | undefined,
|
||||
signal: options.signal,
|
||||
})
|
||||
} catch {
|
||||
throw new ApiError(0, 'network_error', '无法连接服务器,请检查地址和网络后重试')
|
||||
|
||||
@@ -14,7 +14,7 @@ export type SearchResponseDTO = {
|
||||
|
||||
const searchPath = '/api/v1/search'
|
||||
|
||||
export async function searchWorkspace(session: ApiSession, query: string) {
|
||||
export async function searchWorkspace(session: ApiSession, query: string, signal?: AbortSignal) {
|
||||
const search = new URLSearchParams({ q: query })
|
||||
return apiRequest<SearchResponseDTO>(`${searchPath}?${search.toString()}`, { token: session.token })
|
||||
return apiRequest<SearchResponseDTO>(`${searchPath}?${search.toString()}`, { token: session.token, signal })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user