diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2019-01-25 02:59:27 +0800 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2019-01-24 20:59:27 +0200 |
commit | 892bfd0b19fb8c222abc4660c4f584ba0bf6972a (patch) | |
tree | 5d911f8077684112a4d98cf644ef07c8c1342eca /routers | |
parent | 9a137faaaf02661910fdf9037c995e0a54228ad2 (diff) | |
download | gitea-892bfd0b19fb8c222abc4660c4f584ba0bf6972a.tar.gz gitea-892bfd0b19fb8c222abc4660c4f584ba0bf6972a.zip |
improve the releases api paging (#5831)
* improve the releases api paging
* add max limit on API paging
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/repo/release.go | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/routers/api/v1/repo/release.go b/routers/api/v1/repo/release.go index caa2905e93..84cb871b76 100644 --- a/routers/api/v1/repo/release.go +++ b/routers/api/v1/repo/release.go @@ -7,6 +7,7 @@ package repo import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/setting" api "code.gitea.io/sdk/gitea" ) @@ -55,6 +56,20 @@ func GetRelease(ctx *context.APIContext) { ctx.JSON(200, release.APIFormat()) } +func getPagesInfo(ctx *context.APIContext) (int, int) { + page := ctx.QueryInt("page") + if page == 0 { + page = 1 + } + perPage := ctx.QueryInt("per_page") + if perPage == 0 { + perPage = setting.API.DefaultPagingNum + } else if perPage > setting.API.MaxResponseItems { + perPage = setting.API.MaxResponseItems + } + return page, perPage +} + // ListReleases list a repository's releases func ListReleases(ctx *context.APIContext) { // swagger:operation GET /repos/{owner}/{repo}/releases repository repoListReleases @@ -76,10 +91,11 @@ func ListReleases(ctx *context.APIContext) { // responses: // "200": // "$ref": "#/responses/ReleaseList" + page, limit := getPagesInfo(ctx) releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, models.FindReleasesOptions{ IncludeDrafts: ctx.Repo.AccessMode >= models.AccessModeWrite, IncludeTags: false, - }, 1, 2147483647) + }, page, limit) if err != nil { ctx.Error(500, "GetReleasesByRepoID", err) return |