| 34 | } |
| 35 | |
| 36 | async createDir(dir: string, _opts?: FileCreateOptions): Promise<void> { |
| 37 | dir = joinPath(this.path, dir); |
| 38 | const urlencoded = new URLSearchParams(); |
| 39 | urlencoded.append("path", dir); |
| 40 | urlencoded.append("size", "0"); |
| 41 | urlencoded.append("isdir", "1"); |
| 42 | urlencoded.append("rtype", "3"); |
| 43 | const myHeaders = new Headers(); |
| 44 | myHeaders.append("Content-Type", "application/x-www-form-urlencoded"); |
| 45 | const data = await this.request( |
| 46 | `https://pan.baidu.com/rest/2.0/xpan/file?method=create&access_token=${this.accessToken}`, |
| 47 | { |
| 48 | method: "POST", |
| 49 | headers: myHeaders, |
| 50 | body: urlencoded, |
| 51 | redirect: "follow", |
| 52 | } |
| 53 | ); |
| 54 | if (data.errno) { |
| 55 | throw new Error(JSON.stringify(data)); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | async request(url: string, config?: RequestInit) { |
| 60 | config = config || {}; |