@@ -25,7 +25,9 @@ import (
2525 "code.gitea.io/gitea/modules/setting"
2626 "code.gitea.io/gitea/modules/storage"
2727 api "code.gitea.io/gitea/modules/structs"
28+ "code.gitea.io/gitea/modules/util"
2829 "code.gitea.io/gitea/modules/web"
30+ "code.gitea.io/gitea/routers/api/v1/utils"
2931 "code.gitea.io/gitea/routers/common"
3032 "code.gitea.io/gitea/services/context"
3133 pull_service "code.gitea.io/gitea/services/pull"
@@ -982,3 +984,64 @@ func GetContentsList(ctx *context.APIContext) {
982984 // same as GetContents(), this function is here because swagger fails if path is empty in GetContents() interface
983985 GetContents (ctx )
984986}
987+
988+ // GetContentsFiles Get the metadata and contents of requested files
989+ func GetContentsFiles (ctx * context.APIContext ) {
990+ // swagger:operation POST /repos/{owner}/{repo}/contents/files repository repoGetContentsFiles
991+ // ---
992+ // summary: Get the metadata and contents of requested files
993+ // produces:
994+ // - application/json
995+ // parameters:
996+ // - name: owner
997+ // in: path
998+ // description: owner of the repo
999+ // type: string
1000+ // required: true
1001+ // - name: repo
1002+ // in: path
1003+ // description: name of the repo
1004+ // type: string
1005+ // required: true
1006+ // - name: ref
1007+ // in: query
1008+ // description: "The name of the commit/branch/tag. Default the repository’s default branch (usually master)"
1009+ // type: string
1010+ // required: false
1011+ // - name: page
1012+ // in: query
1013+ // description: page number of results to return (1-based)
1014+ // type: integer
1015+ // - name: limit
1016+ // in: query
1017+ // description: page size of results
1018+ // type: integer
1019+ // - name: body
1020+ // in: body
1021+ // required: true
1022+ // schema:
1023+ // "$ref": "#/definitions/GetFilesOptions"
1024+ // responses:
1025+ // "200":
1026+ // "$ref": "#/responses/FilesList"
1027+ // "404":
1028+ // "$ref": "#/responses/notFound"
1029+
1030+ apiOpts := web .GetForm (ctx ).(* api.GetFilesOptions )
1031+
1032+ ref := ctx .FormTrim ("ref" )
1033+ if ref == "" {
1034+ ref = ctx .Repo .Repository .DefaultBranch
1035+ }
1036+
1037+ files := apiOpts .Files
1038+
1039+ filesResponse := files_service .GetContentsListFromTrees (ctx , ctx .Repo .Repository , ref , files )
1040+ count := len (filesResponse )
1041+
1042+ listOpts := utils .GetListOptions (ctx )
1043+ filesResponse = util .PaginateSlice (filesResponse , listOpts .Page , listOpts .PageSize ).([]* api.ContentsResponse )
1044+
1045+ ctx .SetTotalCountHeader (int64 (count ))
1046+ ctx .JSON (http .StatusOK , filesResponse )
1047+ }
0 commit comments