File tree 3 files changed +24
-0
lines changed
3 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -479,6 +479,8 @@ const (
479
479
RepoRefTag
480
480
// RepoRefCommit commit
481
481
RepoRefCommit
482
+ // RepoRefObject object
483
+ RepoRefBlob
482
484
)
483
485
484
486
// RepoRef handles repository reference names when the ref name is not
@@ -514,6 +516,9 @@ func getRefName(ctx *Context, pathType RepoRefType) string {
514
516
if refName := getRefName (ctx , RepoRefCommit ); len (refName ) > 0 {
515
517
return refName
516
518
}
519
+ if refName := getRefName (ctx , RepoRefBlob ); len (refName ) > 0 {
520
+ return refName
521
+ }
517
522
ctx .Repo .TreePath = path
518
523
return ctx .Repo .Repository .DefaultBranch
519
524
case RepoRefBranch :
@@ -526,6 +531,8 @@ func getRefName(ctx *Context, pathType RepoRefType) string {
526
531
ctx .Repo .TreePath = strings .Join (parts [1 :], "/" )
527
532
return parts [0 ]
528
533
}
534
+ case RepoRefBlob :
535
+ return getRefNameFromPath (ctx , path , ctx .Repo .GitRepo .IsBlobExist )
529
536
default :
530
537
log .Error (4 , "Unrecognized path type: %v" , path )
531
538
}
Original file line number Diff line number Diff line change @@ -69,3 +69,19 @@ func SingleDownload(ctx *context.Context) {
69
69
ctx .ServerError ("ServeBlob" , err )
70
70
}
71
71
}
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) {
678
678
m .Get ("/branch/*" , context .RepoRefByType (context .RepoRefBranch ), repo .SingleDownload )
679
679
m .Get ("/tag/*" , context .RepoRefByType (context .RepoRefTag ), repo .SingleDownload )
680
680
m .Get ("/commit/*" , context .RepoRefByType (context .RepoRefCommit ), repo .SingleDownload )
681
+ m .Get ("/blob/:sha" , context .RepoRefByType (context .RepoRefBlob ), repo .DownloadByID )
681
682
// "/*" route is deprecated, and kept for backward compatibility
682
683
m .Get ("/*" , context .RepoRefByType (context .RepoRefLegacy ), repo .SingleDownload )
683
684
}, repo .MustBeNotBare , context .CheckUnit (models .UnitTypeCode ))
You can’t perform that action at this time.
0 commit comments