mirror of https://github.com/gogits/gogs.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
1.6 KiB
73 lines
1.6 KiB
10 years ago
|
// 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.
|
||
|
|
||
9 years ago
|
package repo
|
||
10 years ago
|
|
||
|
import (
|
||
9 years ago
|
"github.com/gogits/git-module"
|
||
9 years ago
|
|
||
9 years ago
|
"github.com/gogits/gogs/models"
|
||
8 years ago
|
"github.com/gogits/gogs/pkg/context"
|
||
8 years ago
|
"github.com/gogits/gogs/routes/repo"
|
||
10 years ago
|
)
|
||
|
|
||
9 years ago
|
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Contents#download-raw-content
|
||
8 years ago
|
func GetRawFile(c *context.APIContext) {
|
||
|
if !c.Repo.HasAccess() {
|
||
|
c.Status(404)
|
||
10 years ago
|
return
|
||
|
}
|
||
|
|
||
8 years ago
|
if c.Repo.Repository.IsBare {
|
||
|
c.Status(404)
|
||
8 years ago
|
return
|
||
|
}
|
||
|
|
||
8 years ago
|
blob, err := c.Repo.Commit.GetBlobByPath(c.Repo.TreePath)
|
||
10 years ago
|
if err != nil {
|
||
9 years ago
|
if git.IsErrNotExist(err) {
|
||
8 years ago
|
c.Status(404)
|
||
10 years ago
|
} else {
|
||
8 years ago
|
c.Error(500, "GetBlobByPath", err)
|
||
10 years ago
|
}
|
||
|
return
|
||
|
}
|
||
8 years ago
|
if err = repo.ServeBlob(c.Context, blob); err != nil {
|
||
|
c.Error(500, "ServeBlob", err)
|
||
10 years ago
|
}
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Contents#download-archive
|
||
8 years ago
|
func GetArchive(c *context.APIContext) {
|
||
|
repoPath := models.RepoPath(c.Params(":username"), c.Params(":reponame"))
|
||
9 years ago
|
gitRepo, err := git.OpenRepository(repoPath)
|
||
|
if err != nil {
|
||
8 years ago
|
c.Error(500, "OpenRepository", err)
|
||
9 years ago
|
return
|
||
|
}
|
||
8 years ago
|
c.Repo.GitRepo = gitRepo
|
||
9 years ago
|
|
||
8 years ago
|
repo.Download(c.Context)
|
||
9 years ago
|
}
|
||
8 years ago
|
|
||
8 years ago
|
func GetEditorconfig(c *context.APIContext) {
|
||
|
ec, err := c.Repo.GetEditorconfig()
|
||
8 years ago
|
if err != nil {
|
||
|
if git.IsErrNotExist(err) {
|
||
8 years ago
|
c.Error(404, "GetEditorconfig", err)
|
||
8 years ago
|
} else {
|
||
8 years ago
|
c.Error(500, "GetEditorconfig", err)
|
||
8 years ago
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
8 years ago
|
fileName := c.Params("filename")
|
||
8 years ago
|
def := ec.GetDefinitionForFilename(fileName)
|
||
|
if def == nil {
|
||
8 years ago
|
c.Error(404, "GetDefinitionForFilename", err)
|
||
8 years ago
|
return
|
||
|
}
|
||
8 years ago
|
c.JSON(200, def)
|
||
8 years ago
|
}
|