(
path: string,
{ repoURL = this.repoURL, branch = this.branch, depth = 1 } = {},
folderSupport?: boolean,
)
| 332 | } |
| 333 | |
| 334 | async listFiles( |
| 335 | path: string, |
| 336 | { repoURL = this.repoURL, branch = this.branch, depth = 1 } = {}, |
| 337 | folderSupport?: boolean, |
| 338 | ): Promise<{ type: string; id: string; name: string; path: string; size: number }[]> { |
| 339 | const folder = trim(path, '/'); |
| 340 | try { |
| 341 | const result: GitGetTreeResponse = await this.request( |
| 342 | `${repoURL}/git/trees/${branch}:${encodeURIComponent(folder)}`, |
| 343 | { |
| 344 | // Gitea API supports recursive=1 for getting the entire recursive tree |
| 345 | // or omitting it to get the non-recursive tree |
| 346 | params: depth > 1 ? { recursive: 1 } : {}, |
| 347 | }, |
| 348 | ); |
| 349 | return ( |
| 350 | result.tree |
| 351 | // filter only files and/or folders up to the required depth |
| 352 | .filter( |
| 353 | file => |
| 354 | (!folderSupport ? file.type === 'blob' : true) && |
| 355 | decodeURIComponent(file.path).split('/').length <= depth, |
| 356 | ) |
| 357 | .map(file => ({ |
| 358 | type: file.type, |
| 359 | id: file.sha, |
| 360 | name: basename(file.path), |
| 361 | path: `${folder}/${file.path}`, |
| 362 | size: file.size!, |
| 363 | })) |
| 364 | ); |
| 365 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 366 | } catch (err: any) { |
| 367 | if (err && err.status === 404) { |
| 368 | console.info('[StaticCMS] This 404 was expected and handled appropriately.'); |
| 369 | return []; |
| 370 | } else { |
| 371 | throw err; |
| 372 | } |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | async persistFiles(dataFiles: DataFile[], mediaFiles: AssetProxy[], options: PersistOptions) { |
| 377 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
no test coverage detected