Skip to content

Commit daa8282

Browse files
committed
fix
1 parent f78bdaf commit daa8282

File tree

1 file changed

+82
-75
lines changed

1 file changed

+82
-75
lines changed

services/repository/files/tree.go

Lines changed: 82 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -189,34 +189,35 @@ func sortTreeViewNodes(nodes []*TreeViewNode) {
189189
/*
190190
Example 1: (path: /)
191191
192-
GET /repo/name/tree/
193-
194-
resp:
195-
[{
196-
"name": "d1",
197-
"isFile": false,
198-
"path": "d1"
199-
},{
200-
"name": "d2",
201-
"isFile": false,
202-
"path": "d2"
203-
},{
204-
"name": "d3",
205-
"isFile": false,
206-
"path": "d3"
207-
},{
208-
"name": "f1",
209-
"isFile": true,
210-
"path": "f1"
211-
},]
192+
GET /repo/name/tree/
193+
194+
resp:
195+
[{
196+
"name": "d1",
197+
"type": "commit",
198+
"path": "d1",
199+
"sub_module_url": "https://gitea.com/gitea/awesome-gitea/tree/887fe27678dced0bd682923b30b2d979575d35d6"
200+
},{
201+
"name": "d2",
202+
"type": "symlink",
203+
"path": "d2"
204+
},{
205+
"name": "d3",
206+
"type": "tree",
207+
"path": "d3"
208+
},{
209+
"name": "f1",
210+
"type": "blob",
211+
"path": "f1"
212+
},]
212213
213214
Example 2: (path: d3)
214215
215216
GET /repo/name/tree/d3
216217
resp:
217218
[{
218219
"name": "d3d1",
219-
"isFile": false,
220+
"type": "tree",
220221
"path": "d3/d3d1"
221222
}]
222223
@@ -226,11 +227,11 @@ Example 3: (path: d3/d3d1)
226227
resp:
227228
[{
228229
"name": "d3d1f1",
229-
"isFile": true,
230+
"type": "blob",
230231
"path": "d3/d3d1/d3d1f1"
231232
},{
232-
"name": "d3d1f1",
233-
"isFile": true,
233+
"name": "d3d1f2",
234+
"type": "blob",
234235
"path": "d3/d3d1/d3d1f2"
235236
}]
236237
*/
@@ -262,7 +263,8 @@ func GetTreeList(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
262263
return nil, err
263264
}
264265

265-
// If the entry is a file, we return a FileContentResponse object
266+
// If the entry is a file, an exception will be thrown.
267+
// This is because this interface is specifically designed for expanding folders and only supports the retrieval and return of the file list within a folder.
266268
if entry.Type() != "tree" {
267269
return nil, fmt.Errorf("%s is not a tree", treePath)
268270
}
@@ -287,7 +289,8 @@ func GetTreeList(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
287289
subTreePath := path.Join(treePath, e.Name())
288290

289291
if strings.Contains(e.Name(), "/") {
290-
mapTree[path.Dir(e.Name())] = append(mapTree[path.Dir(e.Name())], &TreeViewNode{
292+
dirName := path.Dir(e.Name())
293+
mapTree[dirName] = append(mapTree[dirName], &TreeViewNode{
291294
Name: path.Base(e.Name()),
292295
Type: entryModeString(e.Mode()),
293296
Path: subTreePath,
@@ -320,107 +323,111 @@ Example 1: (path: /)
320323
GET /repo/name/tree/?recursive=true
321324
resp:
322325
[{
323-
"name": "d1",
324-
"isFile": false,
325-
"path": "d1"
326-
},{
327-
"name": "d2",
328-
"isFile": false,
329-
"path": "d2"
330-
},{
331-
"name": "d3",
332-
"isFile": false,
333-
"path": "d3"
334-
},{
335-
"name": "f1",
336-
"isFile": true,
337-
"path": "f1"
338-
},]
326+
"name": "d1",
327+
"type": "commit",
328+
"path": "d1",
329+
"sub_module_url": "https://gitea.com/gitea/awesome-gitea/tree/887fe27678dced0bd682923b30b2d979575d35d6"
330+
},{
331+
"name": "d2",
332+
"type": "symlink",
333+
"path": "d2"
334+
},{
335+
"name": "d3",
336+
"type": "tree",
337+
"path": "d3"
338+
},{
339+
"name": "f1",
340+
"type": "blob",
341+
"path": "f1"
342+
},]
339343
340344
Example 2: (path: d3)
341345
GET /repo/name/tree/d3?recursive=true
342346
resp:
343347
[{
344-
"name": "d1",
345-
"isFile": false,
346-
"path": "d1"
347-
},{
348-
"name": "d2",
349-
"isFile": false,
350-
"path": "d2"
351-
},{
348+
"name": "d1",
349+
"type": "commit",
350+
"path": "d1",
351+
"sub_module_url": "https://gitea.com/gitea/awesome-gitea/tree/887fe27678dced0bd682923b30b2d979575d35d6"
352+
},{
353+
"name": "d2",
354+
"type": "symlink",
355+
"path": "d2"
356+
},{
352357
"name": "d3",
353-
"isFile": false,
358+
"type": "tree",
354359
"path": "d3",
355360
"children": [{
356361
"name": "d3d1",
357-
"isFile": false,
362+
"type": "tree",
358363
"path": "d3/d3d1"
359364
}]
360365
},{
361366
"name": "f1",
362-
"isFile": true,
367+
"type": "blob",
363368
"path": "f1"
364369
},]
365370
366371
Example 3: (path: d3/d3d1)
367372
GET /repo/name/tree/d3/d3d1?recursive=true
368373
resp:
369374
[{
370-
"name": "d1",
371-
"isFile": false,
372-
"path": "d1"
373-
},{
374-
"name": "d2",
375-
"isFile": false,
376-
"path": "d2"
377-
},{
375+
"name": "d1",
376+
"type": "commit",
377+
"path": "d1",
378+
"sub_module_url": "https://gitea.com/gitea/awesome-gitea/tree/887fe27678dced0bd682923b30b2d979575d35d6"
379+
},{
380+
"name": "d2",
381+
"type": "symlink",
382+
"path": "d2"
383+
},{
378384
"name": "d3",
379-
"isFile": false,
385+
"type": "tree",
380386
"path": "d3",
381387
"children": [{
382388
"name": "d3d1",
383-
"isFile": false,
389+
"type": "tree",
384390
"path": "d3/d3d1",
385391
"children": [{
386392
"name": "d3d1f1",
387-
"isFile": true,
393+
"type": "blob",
388394
"path": "d3/d3d1/d3d1f1"
389395
},{
390-
"name": "d3d1f1",
391-
"isFile": true,
396+
"name": "d3d1f2",
397+
"type": "blob",
392398
"path": "d3/d3d1/d3d1f2"
393399
}]
394400
}]
395401
},{
396402
"name": "f1",
397-
"isFile": true,
403+
"type": "blob",
398404
"path": "f1"
399405
},]
400406
401407
Example 4: (path: d2/d2f1)
402408
GET /repo/name/tree/d2/d2f1?recursive=true
403409
resp:
404410
[{
405-
"name": "d1",
406-
"isFile": false,
407-
"path": "d1"
408-
},{
411+
"name": "d1",
412+
"type": "commit",
413+
"path": "d1",
414+
"sub_module_url": "https://gitea.com/gitea/awesome-gitea/tree/887fe27678dced0bd682923b30b2d979575d35d6"
415+
},{
409416
"name": "d2",
410-
"isFile": false,
417+
"type": "tree",
411418
"path": "d2",
412419
"children": [{
413420
"name": "d2f1",
414-
"isFile": true,
421+
"type": "blob",
415422
"path": "d2/d2f1"
416423
}]
417424
},{
418425
"name": "d3",
419-
"isFile": false,
426+
"type": "tree",
420427
"path": "d3"
421428
},{
422429
"name": "f1",
423-
"isFile": true,
430+
"type": "blob",
424431
"path": "f1"
425432
},]
426433
*/

0 commit comments

Comments
 (0)