* 启动异步任务 * @param path API 路径 * @param bodyData 请求体数据 * @param ignoreError 是否忽略错误 * @returns 返回 jobid 或 undefined
(
path: string,
bodyData: object = {},
ignoreError?: boolean
)
| 217 | * @returns 返回 jobid 或 undefined |
| 218 | */ |
| 219 | async function rclone_api_post_async( |
| 220 | path: string, |
| 221 | bodyData: object = {}, |
| 222 | ignoreError?: boolean |
| 223 | ): Promise<number | undefined> { |
| 224 | const fullPath = buildApiUrl(path) |
| 225 | |
| 226 | try { |
| 227 | const res = await fetch(fullPath, { |
| 228 | method: 'POST', |
| 229 | headers: getRcloneApiHeaders(), |
| 230 | body: JSON.stringify({ ...bodyData, _async: true }), |
| 231 | }) |
| 232 | |
| 233 | const data = await handleApiResponse(res, fullPath, 'POST') |
| 234 | return (data as AsyncJobResponse)?.jobid |
| 235 | } catch (error) { |
| 236 | if (!ignoreError) { |
| 237 | await printError(error as Error | Response) |
| 238 | } |
| 239 | return undefined |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | /** |
| 244 | * 查询任务状态 |
no test coverage detected