forked from go-gitea/gitea
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor list files * check if the file is lfs
- Loading branch information
1 parent
002b35d
commit 0039401
Showing
6 changed files
with
366 additions
and
311 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package structs | ||
|
||
import "time" | ||
|
||
// CommitContentsResponse contains information about a repo's entry's (dir, file, symlink, submodule) metadata and content and commit | ||
type CommitContentsResponse struct { | ||
URL *string `json:"url"` | ||
GitURL *string `json:"git_url"` | ||
HTMLURL *string `json:"html_url"` | ||
DownloadURL *string `json:"download_url"` | ||
|
||
Name string `json:"name"` | ||
Path string `json:"path"` | ||
SHA string `json:"sha"` | ||
LastCommitSHA string `json:"last_commit_sha"` | ||
LastCommitMessage string `json:"last_commit_message"` | ||
LastCommitCreate time.Time `json:"last_commit_create"` | ||
|
||
// `type` will be `file`, `dir`, `symlink`, or `submodule` | ||
Type string `json:"type"` | ||
Size int64 `json:"size"` | ||
IsLFS bool `json:"is_lfs"` | ||
|
||
// `encoding` is populated when `type` is `file`, otherwise null | ||
Encoding *string `json:"encoding"` | ||
|
||
// `content` is populated when `type` is `file`, otherwise null | ||
Content *string `json:"content"` | ||
|
||
// `target` is populated when `type` is `symlink`, otherwise null | ||
Target *string `json:"target"` | ||
|
||
// `submodule_git_url` is populated when `type` is `submodule`, otherwise null | ||
SubmoduleGitURL *string `json:"submodule_git_url"` | ||
Links *FileLinksResponse `json:"_links"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package repo | ||
|
||
import ( | ||
"net/http" | ||
|
||
repo_model "code.gitea.io/gitea/models/repo" | ||
"code.gitea.io/gitea/modules/context" | ||
"code.gitea.io/gitea/modules/git" | ||
files_service "code.gitea.io/gitea/services/repository/files" | ||
) | ||
|
||
// GetCommitsContents Get the metadata and commit and contents (if a file) of an entry in a repository, or a list of entries if a dir | ||
func GetCommitsContents(ctx *context.APIContext) { | ||
// swagger:operation GET /repos/{owner}/{repo}/commit_contents/commits repository repoGetContentsList | ||
// --- | ||
// summary: Gets the metadata of all the entries of the root dir | ||
// produces: | ||
// - application/json | ||
// parameters: | ||
// - name: owner | ||
// in: path | ||
// description: owner of the repo | ||
// type: string | ||
// required: true | ||
// - name: repo | ||
// in: path | ||
// description: name of the repo | ||
// type: string | ||
// required: true | ||
// - name: ref | ||
// in: query | ||
// description: "The name of the commit/branch/tag. Default the repository’s default branch (usually master)" | ||
// type: string | ||
// required: false | ||
// responses: | ||
// "200": | ||
// "$ref": "#/responses/ContentsListResponse" | ||
// "404": | ||
// "$ref": "#/responses/notFound" | ||
|
||
// same as GetContents(), this function is here because swagger fails if path is empty in GetContents() interface | ||
if !canReadFiles(ctx.Repo) { | ||
ctx.Error(http.StatusInternalServerError, "GetContentsOrList", repo_model.ErrUserDoesNotHaveAccessToRepo{ | ||
UserID: ctx.Doer.ID, | ||
RepoName: ctx.Repo.Repository.LowerName, | ||
}) | ||
return | ||
} | ||
|
||
treePath := ctx.Params("*") | ||
ref := ctx.FormTrim("ref") | ||
|
||
if fileList, err := files_service.GetCommitContentsOrList(ctx, ctx.Repo.Repository, treePath, ref); err != nil { | ||
if git.IsErrNotExist(err) { | ||
ctx.NotFound("GetContentsOrList", err) | ||
return | ||
} | ||
ctx.Error(http.StatusInternalServerError, "GetContentsOrList", err) | ||
} else { | ||
ctx.JSON(http.StatusOK, fileList) | ||
} | ||
|
||
} | ||
|
||
// GetCommitsContentsList Get the metadata (include commit information) of all the entries of the root dir | ||
func GetCommitsContentsList(ctx *context.APIContext) { | ||
// swagger:operation GET /repos/{owner}/{repo}/commit_contents repository repoGetContentsList | ||
// --- | ||
// summary: Gets the metadata of all the entries of the root dir | ||
// produces: | ||
// - application/json | ||
// parameters: | ||
// - name: owner | ||
// in: path | ||
// description: owner of the repo | ||
// type: string | ||
// required: true | ||
// - name: repo | ||
// in: path | ||
// description: name of the repo | ||
// type: string | ||
// required: true | ||
// - name: ref | ||
// in: query | ||
// description: "The name of the commit/branch/tag. Default the repository’s default branch (usually master)" | ||
// type: string | ||
// required: false | ||
// responses: | ||
// "200": | ||
// "$ref": "#/responses/ContentsListResponse" | ||
// "404": | ||
// "$ref": "#/responses/notFound" | ||
|
||
// same as GetContents(), this function is here because swagger fails if path is empty in GetContents() interface | ||
GetCommitsContents(ctx) | ||
|
||
} |
Oops, something went wrong.