summaryrefslogtreecommitdiffstats
path: root/routers/repo/download.go
diff options
context:
space:
mode:
Diffstat (limited to 'routers/repo/download.go')
-rw-r--r--routers/repo/download.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/routers/repo/download.go b/routers/repo/download.go
index 820a98c0dc..a863236d6e 100644
--- a/routers/repo/download.go
+++ b/routers/repo/download.go
@@ -1,4 +1,5 @@
// Copyright 2014 The Gogs Authors. All rights reserved.
+// Copyright 2018 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
@@ -69,3 +70,19 @@ func SingleDownload(ctx *context.Context) {
ctx.ServerError("ServeBlob", err)
}
}
+
+// DownloadByID download a file by sha1 ID
+func DownloadByID(ctx *context.Context) {
+ blob, err := ctx.Repo.GitRepo.GetBlob(ctx.Params("sha"))
+ if err != nil {
+ if git.IsErrNotExist(err) {
+ ctx.NotFound("GetBlob", nil)
+ } else {
+ ctx.ServerError("GetBlob", err)
+ }
+ return
+ }
+ if err = ServeBlob(ctx, blob); err != nil {
+ ctx.ServerError("ServeBlob", err)
+ }
+}