Merge pull request '仓库获取文件添加分支、commit、tag参数' (#20) from yystopf/gitea-1120-rc1:hh_raw_delay into develop

This commit is contained in:
jasder 2021-09-10 11:37:47 +08:00
commit 4e0a133712
2 changed files with 26 additions and 25 deletions

View File

@ -57,6 +57,11 @@ func GetRawFile(ctx *context.APIContext) {
// description: filepath of the file to get
// type: string
// required: true
// - name: ref
// in: query
// description: "The name of the commit/branch/tag. Default the repositorys default branch (usually master)"
// type: string
// required: false
// responses:
// 200:
// description: success
@ -68,7 +73,14 @@ func GetRawFile(ctx *context.APIContext) {
return
}
blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreePath)
ref := ctx.QueryTrim("ref")
commit, err := ctx.Repo.GitRepo.GetCommit(ref)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetCommit", err)
return
}
blob, err := commit.GetBlobByPath(ctx.Repo.TreePath)
if err != nil {
if git.IsErrNotExist(err) {
ctx.NotFound()
@ -528,8 +540,7 @@ func GetContents(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
start:=time.Now()
start := time.Now()
if !canReadFiles(ctx.Repo) {
ctx.Error(http.StatusInternalServerError, "GetContentsOrList", models.ErrUserDoesNotHaveAccessToRepo{
@ -542,8 +553,8 @@ func GetContents(ctx *context.APIContext) {
treePath := ctx.Params("*")
ref := ctx.QueryTrim("ref")
fmt.Println("***GetContents.treePath:",treePath)
fmt.Println("***GetContents.ref:",ref)
fmt.Println("***GetContents.treePath:", treePath)
fmt.Println("***GetContents.ref:", ref)
if fileList, err := repofiles.GetContentsOrList(ctx.Repo.Repository, treePath, ref); err != nil {
if git.IsErrNotExist(err) {
ctx.NotFound("GetContentsOrList", err)
@ -553,7 +564,7 @@ func GetContents(ctx *context.APIContext) {
} else {
ctx.JSON(http.StatusOK, fileList)
}
log.Info("*****************GetContents:%v",time.Now().Sub(start))
log.Info("*****************GetContents:%v", time.Now().Sub(start))
}
// add by qiubing

View File

@ -7699,6 +7699,12 @@
"name": "filepath",
"in": "path",
"required": true
},
{
"type": "string",
"description": "The name of the commit/branch/tag. Default the repositorys default branch (usually master)",
"name": "ref",
"in": "query"
}
],
"responses": {
@ -14086,17 +14092,14 @@
"type": "object",
"required": [
"clone_addr",
"uid"
"uid",
"repo_name"
],
"properties": {
"auth_password": {
"type": "string",
"x-go-name": "AuthPassword"
},
"auth_token": {
"type": "string",
"x-go-name": "AuthToken"
},
"auth_username": {
"type": "string",
"x-go-name": "AuthUsername"
@ -14125,10 +14128,6 @@
"type": "boolean",
"x-go-name": "Mirror"
},
"mirror_interval": {
"type": "string",
"x-go-name": "MirrorInterval"
},
"private": {
"type": "boolean",
"x-go-name": "Private"
@ -14145,15 +14144,6 @@
"type": "string",
"x-go-name": "RepoName"
},
"repo_owner": {
"type": "string",
"x-go-name": "RepoOwner"
},
"service": {
"description": "add configure",
"type": "string",
"x-go-name": "Service"
},
"uid": {
"type": "integer",
"format": "int64",
@ -16521,4 +16511,4 @@
"TOTPHeader": []
}
]
}
}