MCPcopy Create free account
hub / github.com/decaporg/decap-cms / listFiles

Method listFiles

packages/decap-cms-backend-gitea/src/API.ts:334–374  ·  view source on GitHub ↗
(
    path: string,
    { repoURL = this.repoURL, branch = this.branch, depth = 1 } = {},
    folderSupport?: boolean,
  )

Source from the content-addressed store, hash-verified

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

Callers 3

getCommitItemsMethod · 0.95
APIClass · 0.95
API.spec.jsFile · 0.45

Calls 4

requestMethod · 0.95
basenameFunction · 0.90
mapMethod · 0.80
filterMethod · 0.80

Tested by

no test coverage detected