| 13 | } |
| 14 | |
| 15 | async read(type?: "string" | "blob"): Promise<string | Blob> { |
| 16 | // 查询文件信息获取dlink |
| 17 | const data = await this.fs.request( |
| 18 | `https://pan.baidu.com/rest/2.0/xpan/multimedia?method=filemetas&access_token=${ |
| 19 | this.fs.accessToken |
| 20 | }&fsids=[${this.file.fsid!}]&dlink=1` |
| 21 | ); |
| 22 | if (!data.list.length) { |
| 23 | throw new Error("file not found"); |
| 24 | } |
| 25 | const resp = await fetch(`${data.list[0].dlink}&access_token=${this.fs.accessToken}`); |
| 26 | switch (type) { |
| 27 | case "string": |
| 28 | return await resp.text(); |
| 29 | default: { |
| 30 | return await resp.blob(); |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | export class BaiduFileWriter implements FileWriter { |