| 4 | import type OneDriveFileSystem from "./onedrive"; |
| 5 | |
| 6 | export class OneDriveFileReader implements FileReader { |
| 7 | file: FileInfo; |
| 8 | |
| 9 | fs: OneDriveFileSystem; |
| 10 | |
| 11 | constructor(fs: OneDriveFileSystem, file: FileInfo) { |
| 12 | this.fs = fs; |
| 13 | this.file = file; |
| 14 | } |
| 15 | |
| 16 | async read(type?: "string" | "blob"): Promise<string | Blob> { |
| 17 | const data = await this.fs.request( |
| 18 | `https://graph.microsoft.com/v1.0/me/drive/special/approot:${joinPath(this.file.path, this.file.name)}:/content`, |
| 19 | {}, |
| 20 | true |
| 21 | ); |
| 22 | if (data.status !== 200) { |
| 23 | throw new Error(await data.text()); |
| 24 | } |
| 25 | switch (type) { |
| 26 | case "string": |
| 27 | return data.text(); |
| 28 | default: { |
| 29 | return data.blob(); |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | export class OneDriveFileWriter implements FileWriter { |
| 36 | path: string; |
nothing calls this directly
no outgoing calls
no test coverage detected