()
| 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(); |
no outgoing calls
no test coverage detected