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.
|
|
|
|
|
|
2015-12-04 17:16:42 -05:00
|
|
|
package repo
|
2014-11-16 21:32:26 -05:00
|
|
|
|
|
|
|
|
import (
|
2018-05-27 08:53:48 +08:00
|
|
|
"github.com/gogs/git-module"
|
2015-12-09 20:46:05 -05:00
|
|
|
|
2019-10-24 01:51:46 -07:00
|
|
|
"gogs.io/gogs/internal/context"
|
|
|
|
|
"gogs.io/gogs/internal/db"
|
2019-10-24 19:56:09 -07:00
|
|
|
"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()
|
2017-01-27 13:09:25 +01:00
|
|
|
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
|
|
|
|
|
}
|
2019-10-24 19:56:09 -07:00
|
|
|
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) {
|
2019-10-24 01:51:46 -07:00
|
|
|
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
|
|
|
|
2019-10-24 19:56:09 -07: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")
|
2019-12-25 03:26:57 +01:00
|
|
|
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
|
|
|
}
|