| 57 | } |
| 58 | |
| 59 | async request(url: string, config?: RequestInit) { |
| 60 | config = config || {}; |
| 61 | const headers = <Headers>config.headers || new Headers(); |
| 62 | config.headers = headers; |
| 63 | // 对百度网盘请求显式禁用 cookie,避免依赖全局 DNR 规则造成并发竞态 |
| 64 | config.credentials = "omit"; |
| 65 | return fetch(url, config) |
| 66 | .then((data) => data.json()) |
| 67 | .then(async (data) => { |
| 68 | if (data.errno === 111 || data.errno === -6) { |
| 69 | const token = await AuthVerify("baidu", true); |
| 70 | this.accessToken = token; |
| 71 | url = url.replace(/access_token=[^&]+/, `access_token=${token}`); |
| 72 | return fetch(url, config) |
| 73 | .then((data2) => data2.json()) |
| 74 | .then((data2) => { |
| 75 | if (data2.errno === 111 || data2.errno === -6) { |
| 76 | throw new Error(JSON.stringify(data2)); |
| 77 | } |
| 78 | return data2; |
| 79 | }); |
| 80 | } |
| 81 | return data; |
| 82 | }); |
| 83 | } |
| 84 | |
| 85 | delete(path: string): Promise<void> { |
| 86 | const filelist = [joinPath(this.path, path)]; |