1
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-12-04 14:46:57 -05:00

improve the releases api paging (#5831)

* improve the releases api paging

* add max limit on API paging
This commit is contained in:
Lunny Xiao 2019-01-25 02:59:27 +08:00 committed by Lauris BH
parent 9a137faaaf
commit 892bfd0b19
5 changed files with 29 additions and 2 deletions

View File

@ -622,6 +622,8 @@ MIN_INTERVAL = 10m
ENABLE_SWAGGER = true
; Max number of items in a page
MAX_RESPONSE_ITEMS = 50
; Default paging number of api
DEFAULT_PAGING_NUM = 30
[i18n]
LANGS = en-US,zh-CN,zh-HK,zh-TW,de-DE,fr-FR,nl-NL,lv-LV,ru-RU,uk-UA,ja-JP,es-ES,pt-BR,pl-PL,bg-BG,it-IT,fi-FI,tr-TR,cs-CZ,sr-SP,sv-SE,ko-KR

View File

@ -325,6 +325,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
- `ENABLE_SWAGGER`: **true**: Enables /api/swagger, /api/v1/swagger etc. endpoints. True or false; default is true.
- `MAX_RESPONSE_ITEMS`: **50**: Max number of items in a page.
- `DEFAULT_PAGING_NUM`: **30**: Default paging number of api.
## i18n (`i18n`)

View File

@ -194,7 +194,13 @@ menu:
- `PULL`: **300**: 内部仓库间拉取的超时时间,单位秒
- `GC`: **60**: git仓库GC的超时时间单位秒
## markup (`markup`)
## API (`api`)
- `ENABLE_SWAGGER`: **true**: 是否启用swagger路由 /api/swagger, /api/v1/swagger etc. endpoints. True 或 false; 默认是 true.
- `MAX_RESPONSE_ITEMS`: **50**: 一个页面最大的项目数。
- `DEFAULT_PAGING_NUM`: **30**: API中默认分页条数。
## Markup (`markup`)
外部渲染工具支持,你可以用你熟悉的文档渲染工具. 比如一下将新增一个名字为 `asciidoc` 的渲染工具which is followed `markup.` ini section. And there are some config items below.

View File

@ -557,9 +557,11 @@ var (
API = struct {
EnableSwagger bool
MaxResponseItems int
DefaultPagingNum int
}{
EnableSwagger: true,
MaxResponseItems: 50,
DefaultPagingNum: 30,
}
U2F = struct {

View File

@ -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