UNPKG

@waline/client

Version:

client for waline comment system

34 lines (30 loc) 740 B
import type { BaseAPIOptions } from './utils'; export interface GetCommentCountOptions extends BaseAPIOptions { /** * 待获取评论数的 path * * Path of pages to be fetched */ paths: string[]; /** * 取消请求的信号 * * AbortSignal to cancel request */ signal?: AbortSignal; } export const fetchCommentCount = ({ serverURL, lang, paths, signal, }: GetCommentCountOptions): Promise<number[]> => fetch( `${serverURL}/comment?type=count&url=${encodeURIComponent( paths.join(',') )}&lang=${lang}`, { signal } ) .then((resp) => <Promise<number | number[]>>resp.json()) // TODO: Improve this API .then((counts) => (Array.isArray(counts) ? counts : [counts]));