(dir: string, _opts?: FileCreateOptions)
| 37 | } |
| 38 | |
| 39 | async createDir(dir: string, _opts?: FileCreateOptions): Promise<void> { |
| 40 | if (dir && dir.startsWith("ScriptCat")) { |
| 41 | dir = dir.substring(9); |
| 42 | if (dir.startsWith("/")) { |
| 43 | dir = dir.substring(1); |
| 44 | } |
| 45 | } |
| 46 | if (!dir) { |
| 47 | return; |
| 48 | } |
| 49 | const dirs = joinPath(this.path, dir).split("/").filter(Boolean); |
| 50 | const myHeaders = new Headers(); |
| 51 | myHeaders.append("Content-Type", "application/json"); |
| 52 | |
| 53 | for (let i = 0; i < dirs.length; i++) { |
| 54 | const parentPath = dirs.slice(0, i).join("/"); |
| 55 | const parent = parentPath ? `:/${parentPath}:` : ""; |
| 56 | try { |
| 57 | await this.request(`https://graph.microsoft.com/v1.0/me/drive/special/approot${parent}/children`, { |
| 58 | method: "POST", |
| 59 | headers: myHeaders, |
| 60 | body: JSON.stringify({ |
| 61 | name: dirs[i], |
| 62 | folder: {}, |
| 63 | "@microsoft.graph.conflictBehavior": "fail", |
| 64 | }), |
| 65 | }); |
| 66 | } catch (error) { |
| 67 | if (this.isDirectoryAlreadyExistsError(error)) { |
| 68 | continue; |
| 69 | } |
| 70 | throw error; |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | private isDirectoryAlreadyExistsError(error: unknown): boolean { |
| 76 | if (error instanceof FileSystemError && error.conflict) { |
nothing calls this directly
no test coverage detected