Files
Gogs/internal/route/api/v1/repo/file.go

67 lines
1.4 KiB
Go
Raw Normal View History

2014-11-16 20:27:04 -05:00
// Copyright 2014 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package repo
2014-11-16 21:32:26 -05:00
import (
2018-05-27 08:53:48 +08:00
"github.com/gogs/git-module"
"gogs.io/gogs/internal/context"
"gogs.io/gogs/internal/db"
"gogs.io/gogs/internal/route/repo"
2014-11-16 21:32:26 -05:00
)
2017-06-03 07:26:09 -04:00
func GetRawFile(c *context.APIContext) {
if !c.Repo.HasAccess() {
2019-08-10 13:40:48 -07:00
c.NotFound()
2014-11-16 21:32:26 -05:00
return
}
2017-06-03 07:26:09 -04:00
if c.Repo.Repository.IsBare {
2019-08-10 13:40:48 -07:00
c.NotFound()
return
}
2017-06-03 07:26:09 -04:00
blob, err := c.Repo.Commit.GetBlobByPath(c.Repo.TreePath)
2014-11-16 21:32:26 -05:00
if err != nil {
2019-08-10 13:40:48 -07:00
c.NotFoundOrServerError("GetBlobByPath", git.IsErrNotExist, err)
2014-11-16 21:32:26 -05:00
return
}
if err = repo.ServeBlob(c.Context, blob); err != nil {
2019-08-10 13:40:48 -07:00
c.ServerError("ServeBlob", err)
2014-11-16 21:32:26 -05:00
}
}
2015-09-02 09:54:35 -04:00
2017-06-03 07:26:09 -04:00
func GetArchive(c *context.APIContext) {
repoPath := db.RepoPath(c.Params(":username"), c.Params(":reponame"))
2015-09-02 09:54:35 -04:00
gitRepo, err := git.OpenRepository(repoPath)
if err != nil {
2019-08-10 13:40:48 -07:00
c.ServerError("OpenRepository", err)
2015-09-02 09:54:35 -04:00
return
}
2017-06-03 07:26:09 -04:00
c.Repo.GitRepo = gitRepo
2015-09-02 09:54:35 -04:00
repo.Download(c.Context)
2015-09-02 09:54:35 -04:00
}
2016-08-30 20:18:40 -03:00
2017-06-03 07:26:09 -04:00
func GetEditorconfig(c *context.APIContext) {
ec, err := c.Repo.GetEditorconfig()
2016-08-30 20:18:40 -03:00
if err != nil {
2019-08-10 13:40:48 -07:00
c.NotFoundOrServerError("GetEditorconfig", git.IsErrNotExist, err)
2016-08-30 20:18:40 -03:00
return
}
2017-06-03 07:26:09 -04:00
fileName := c.Params("filename")
def, err := ec.GetDefinitionForFilename(fileName)
if err != nil {
c.ServerError("GetDefinitionForFilename", err)
return
}
2016-08-30 20:18:40 -03:00
if def == nil {
2019-08-10 13:40:48 -07:00
c.NotFound()
2016-08-30 20:18:40 -03:00
return
}
2019-08-10 13:40:48 -07:00
c.JSONSuccess(def)
2016-08-30 20:18:40 -03:00
}