@@ -6,6 +6,8 @@ package repo
6
6
import (
7
7
"fmt"
8
8
"net/http"
9
+ "net/url"
10
+ "strings"
9
11
10
12
"code.gitea.io/gitea/modules/base"
11
13
"code.gitea.io/gitea/modules/context"
@@ -27,15 +29,15 @@ func GetDirInfos(ctx *context.APIContext) {
27
29
return
28
30
}
29
31
path := ctx .Req .URL .Query ().Get ("path" )
30
- entries , err := getDirectoryEntries (ctx , path )
32
+ entries , err := getDirectoryEntries (ctx , branch , path )
31
33
if err != nil {
32
34
ctx .JSON (http .StatusInternalServerError , "failed to get directry entries, error: " + err .Error ())
33
35
return
34
36
}
35
37
ctx .JSON (http .StatusOK , entries )
36
38
}
37
39
38
- func getDirectoryEntries (ctx * context.APIContext , folder string ) ([]structs.GitEntry , error ) {
40
+ func getDirectoryEntries (ctx * context.APIContext , branch , folder string ) ([]structs.GitEntry , error ) {
39
41
tree , err := ctx .Repo .Commit .SubTree (folder )
40
42
if err != nil {
41
43
return nil , fmt .Errorf ("failed to exec SubTree, cause:%w" , err )
@@ -52,27 +54,30 @@ func getDirectoryEntries(ctx *context.APIContext, folder string) ([]structs.GitE
52
54
if err != nil {
53
55
return nil , fmt .Errorf ("failed to exec GetCommitsInfo, cause:%w" , err )
54
56
}
57
+
55
58
var ges = make ([]structs.GitEntry , 0 , len (commits ))
56
59
for _ , c := range commits {
57
-
58
60
e := structs.GitEntry {
59
61
Name : c .Entry .Name (),
60
62
Path : folder + "/" + c .Entry .Name (),
61
63
Mode : c .Entry .Mode ().String (),
62
64
Type : c .Entry .Type (),
63
65
Size : c .Entry .Size (),
64
66
SHA : c .Commit .ID .String (),
65
- URL : "" ,
66
67
CommitMsg : c .Commit .CommitMessage ,
67
68
CommitterDate : c .Commit .Committer .When ,
68
69
}
70
+ e .URL = ctx .Repo .Repository .HTMLURL () + "/raw/branch/" + url .PathEscape (branch ) + "/" + url .PathEscape (strings .TrimPrefix (e .Path , "/" ))
71
+ e .DownloadUrl = e .URL
69
72
//lfs pointer size is less than 1024
70
73
if c .Entry .Size () <= 1024 {
71
74
content , _ := c .Entry .Blob ().GetBlobContent (1024 )
72
75
p , _ := lfs .ReadPointerFromBuffer ([]byte (content ))
73
76
if p .IsValid () {
74
77
e .Size = p .Size
75
78
e .IsLfs = true
79
+ e .LfsRelativePath = p .RelativePath ()
80
+ e .DownloadUrl = ctx .Repo .Repository .HTMLURL () + "/media/branch/" + url .PathEscape (branch ) + "/" + url .PathEscape (strings .TrimPrefix (e .Path , "/" ))
76
81
}
77
82
}
78
83
ges = append (ges , e )
0 commit comments