Files
Gogs/routes/api/v1/repo/file.go

73 lines
1.6 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 (
2015-12-15 17:25:45 -05:00
"github.com/gogits/git-module"
2015-09-02 09:54:35 -04:00
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/pkg/context"
"github.com/gogits/gogs/routes/repo"
2014-11-16 21:32:26 -05:00
)
2015-12-03 00:24:37 -05:00
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Contents#download-raw-content
2017-06-03 07:26:09 -04:00
func GetRawFile(c *context.APIContext) {
if !c.Repo.HasAccess() {
c.Status(404)
2014-11-16 21:32:26 -05:00
return
}
2017-06-03 07:26:09 -04:00
if c.Repo.Repository.IsBare {
c.Status(404)
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 {
if git.IsErrNotExist(err) {
2017-06-03 07:26:09 -04:00
c.Status(404)
2014-11-16 21:32:26 -05:00
} else {
2017-06-03 07:26:09 -04:00
c.Error(500, "GetBlobByPath", err)
2014-11-16 21:32:26 -05:00
}
return
}
2017-06-03 07:26:09 -04:00
if err = repo.ServeBlob(c.Context, blob); err != nil {
c.Error(500, "ServeBlob", err)
2014-11-16 21:32:26 -05:00
}
}
2015-09-02 09:54:35 -04:00
2015-12-03 00:24:37 -05:00
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Contents#download-archive
2017-06-03 07:26:09 -04:00
func GetArchive(c *context.APIContext) {
repoPath := models.RepoPath(c.Params(":username"), c.Params(":reponame"))
2015-09-02 09:54:35 -04:00
gitRepo, err := git.OpenRepository(repoPath)
if err != nil {
2017-06-03 07:26:09 -04:00
c.Error(500, "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
2017-06-03 07:26:09 -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 {
if git.IsErrNotExist(err) {
2017-06-03 07:26:09 -04:00
c.Error(404, "GetEditorconfig", err)
2016-08-30 20:18:40 -03:00
} else {
2017-06-03 07:26:09 -04:00
c.Error(500, "GetEditorconfig", err)
2016-08-30 20:18:40 -03:00
}
return
}
2017-06-03 07:26:09 -04:00
fileName := c.Params("filename")
2016-08-30 20:18:40 -03:00
def := ec.GetDefinitionForFilename(fileName)
if def == nil {
2017-06-03 07:26:09 -04:00
c.Error(404, "GetDefinitionForFilename", err)
2016-08-30 20:18:40 -03:00
return
}
2017-06-03 07:26:09 -04:00
c.JSON(200, def)
2016-08-30 20:18:40 -03:00
}