File tree Expand file tree Collapse file tree 3 files changed +24
-0
lines changed Expand file tree Collapse file tree 3 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -479,6 +479,8 @@ const (
479479 RepoRefTag
480480 // RepoRefCommit commit
481481 RepoRefCommit
482+ // RepoRefObject object
483+ RepoRefBlob
482484)
483485
484486// RepoRef handles repository reference names when the ref name is not
@@ -514,6 +516,9 @@ func getRefName(ctx *Context, pathType RepoRefType) string {
514516 if refName := getRefName (ctx , RepoRefCommit ); len (refName ) > 0 {
515517 return refName
516518 }
519+ if refName := getRefName (ctx , RepoRefBlob ); len (refName ) > 0 {
520+ return refName
521+ }
517522 ctx .Repo .TreePath = path
518523 return ctx .Repo .Repository .DefaultBranch
519524 case RepoRefBranch :
@@ -526,6 +531,8 @@ func getRefName(ctx *Context, pathType RepoRefType) string {
526531 ctx .Repo .TreePath = strings .Join (parts [1 :], "/" )
527532 return parts [0 ]
528533 }
534+ case RepoRefBlob :
535+ return getRefNameFromPath (ctx , path , ctx .Repo .GitRepo .IsBlobExist )
529536 default :
530537 log .Error (4 , "Unrecognized path type: %v" , path )
531538 }
Original file line number Diff line number Diff line change @@ -69,3 +69,19 @@ func SingleDownload(ctx *context.Context) {
6969 ctx .ServerError ("ServeBlob" , err )
7070 }
7171}
72+
73+ // DownloadById download a file by sha1 ID
74+ func DownloadByID (ctx * context.Context ) {
75+ blob , err := ctx .Repo .GitRepo .GetBlob (ctx .Params ["sha" ])
76+ if err != nil {
77+ if git .IsErrNotExist (err ) {
78+ ctx .NotFound ("GetBlob" , nil )
79+ } else {
80+ ctx .ServerError ("GetBlob" , err )
81+ }
82+ return
83+ }
84+ if err = ServeBlob (ctx , blob ); err != nil {
85+ ctx .ServerError ("ServeBlob" , err )
86+ }
87+ }
Original file line number Diff line number Diff line change @@ -678,6 +678,7 @@ func RegisterRoutes(m *macaron.Macaron) {
678678 m .Get ("/branch/*" , context .RepoRefByType (context .RepoRefBranch ), repo .SingleDownload )
679679 m .Get ("/tag/*" , context .RepoRefByType (context .RepoRefTag ), repo .SingleDownload )
680680 m .Get ("/commit/*" , context .RepoRefByType (context .RepoRefCommit ), repo .SingleDownload )
681+ m .Get ("/blob/:sha" , context .RepoRefByType (context .RepoRefBlob ), repo .DownloadByID )
681682 // "/*" route is deprecated, and kept for backward compatibility
682683 m .Get ("/*" , context .RepoRefByType (context .RepoRefLegacy ), repo .SingleDownload )
683684 }, repo .MustBeNotBare , context .CheckUnit (models .UnitTypeCode ))
You can’t perform that action at this time.
0 commit comments