summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--custom/conf/app.ini.sample2
-rw-r--r--docs/content/doc/advanced/config-cheat-sheet.en-us.md1
-rw-r--r--docs/content/doc/advanced/config-cheat-sheet.zh-cn.md8
-rw-r--r--modules/setting/setting.go2
-rw-r--r--routers/api/v1/repo/release.go18
5 files changed, 29 insertions, 2 deletions
diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample
index 39513833e7..b89c5b5e96 100644
--- a/custom/conf/app.ini.sample
+++ b/custom/conf/app.ini.sample
@@ -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
diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md
index 775fef6f89..15f90769bc 100644
--- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md
+++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md
@@ -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`)
diff --git a/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md b/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md
index a7109572dc..990d4d42f4 100644
--- a/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md
+++ b/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md
@@ -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.
diff --git a/modules/setting/setting.go b/modules/setting/setting.go
index e561b4f96b..ec9fa02c25 100644
--- a/modules/setting/setting.go
+++ b/modules/setting/setting.go
@@ -557,9 +557,11 @@ var (
API = struct {
EnableSwagger bool
MaxResponseItems int
+ DefaultPagingNum int
}{
EnableSwagger: true,
MaxResponseItems: 50,
+ DefaultPagingNum: 30,
}
U2F = struct {
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