MCPcopy
hub / github.com/remotely-save/remotely-save / _init

Method _init

pro/src/fsKoofr.ts:327–381  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

325 }
326
327 async _init() {
328 if (this.koofrConfig.refreshToken === "") {
329 throw Error(`You have not auth yet!`);
330 }
331
332 if (this.placeID === undefined || this.placeID === "") {
333 const { data, error } = await this.client.GET("/api/v2.1/places");
334 const primaryPlaceID = data?.places.filter((x) => x.isPrimary)[0].id;
335 this.placeID = primaryPlaceID ?? "";
336
337 if (this.placeID === "") {
338 throw Error(`cannot find primary placeID`);
339 }
340 }
341
342 if (this.vaultFolderExists) {
343 // pass
344 } else {
345 const { data, error } = await this.client.GET(
346 "/api/v2.1/mounts/{mountId}/files/list",
347 {
348 params: {
349 query: {
350 path: "/",
351 },
352 path: {
353 mountId: this.placeID,
354 },
355 },
356 }
357 );
358 const x = data?.files.filter((x) => x.name === this.remoteBaseDir);
359 if ((x?.length ?? 0) > 0) {
360 this.vaultFolderExists = true;
361 } else {
362 const { data, error } = await this.client.POST(
363 "/api/v2.1/mounts/{mountId}/files/folder",
364 {
365 params: {
366 query: { path: "/" },
367 path: { mountId: this.placeID },
368 },
369 body: {
370 name: this.remoteBaseDir,
371 },
372 }
373 );
374 if (data !== undefined) {
375 this.vaultFolderExists = true;
376 } else {
377 throw Error(JSON.stringify(error));
378 }
379 }
380 }
381 }
382
383 async walk(): Promise<Entity[]> {
384 await this._init();

Callers 9

walkMethod · 0.95
walkPartialMethod · 0.95
statMethod · 0.95
mkdirMethod · 0.95
writeFileMethod · 0.95
readFileMethod · 0.95
renameMethod · 0.95
rmMethod · 0.95
checkConnectMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected