(method, url, options = {})
| 2926 | } |
| 2927 | |
| 2928 | async function icloudRequest(method, url, options = {}) { |
| 2929 | const { data } = options; |
| 2930 | let response; |
| 2931 | try { |
| 2932 | response = await fetch(url, { |
| 2933 | method, |
| 2934 | credentials: 'include', |
| 2935 | headers: data !== undefined ? { 'Content-Type': 'application/json' } : undefined, |
| 2936 | body: data !== undefined ? JSON.stringify(data) : undefined, |
| 2937 | }); |
| 2938 | } catch (err) { |
| 2939 | throw new Error(`iCloud 请求失败:${method} ${url},${err.message}`); |
| 2940 | } |
| 2941 | |
| 2942 | if (!response.ok) { |
| 2943 | throw new Error(`iCloud 请求失败:${method} ${url},status ${response.status}`); |
| 2944 | } |
| 2945 | |
| 2946 | try { |
| 2947 | return await response.json(); |
| 2948 | } catch (err) { |
| 2949 | throw new Error(`iCloud 返回的 JSON 无法解析:${method} ${url},${err.message}`); |
| 2950 | } |
| 2951 | } |
| 2952 | |
| 2953 | async function validateIcloudSession(setupUrl) { |
| 2954 | const data = await icloudRequest('POST', `${setupUrl}/validate`); |
no outgoing calls
no test coverage detected