MCPcopy Index your code
hub / github.com/scriptscat/scriptcat / createDir

Method createDir

packages/filesystem/onedrive/onedrive.ts:39–73  ·  view source on GitHub ↗
(dir: string, _opts?: FileCreateOptions)

Source from the content-addressed store, hash-verified

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) {

Callers

nothing calls this directly

Calls 5

requestMethod · 0.95
joinPathFunction · 0.90
appendMethod · 0.80
sliceMethod · 0.45

Tested by

no test coverage detected