[API] Expose MAX_RESPONSE_ITEMS for API #5927

Closed
opened 2025-11-02 06:40:33 -06:00 by GiteaMirror · 4 comments
Owner

Originally created by @6543 on GitHub (Aug 31, 2020).

settings -> api.MaxResponseItems could differ from instance to instance

this makes it hard to implement a proper client pagination

Originally created by @6543 on GitHub (Aug 31, 2020). settings -> api.MaxResponseItems could differ from instance to instance this makes it hard to implement a proper client pagination
Author
Owner

@zeripath commented on GitHub (Sep 4, 2020):

I guess something like this would do?

From 41bc6c6c92233d0b46aa2d0bdd5bf3c311cd1abf Mon Sep 17 00:00:00 2001
From: Andrew Thornton <art27@cantab.net>
Date: Fri, 4 Sep 2020 11:44:53 +0100
Subject: [PATCH] Add API settings to GeneralUISettings

Fix #12664

Signed-off-by: Andrew Thornton <art27@cantab.net>
---
 modules/structs/settings.go         | 6 +++++-
 routers/api/v1/settings/settings.go | 6 +++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/modules/structs/settings.go b/modules/structs/settings.go
index 4a6e0ce5a..456cfb74f 100644
--- a/modules/structs/settings.go
+++ b/modules/structs/settings.go
@@ -12,5 +12,9 @@ type GeneralRepoSettings struct {
 
 // GeneralUISettings contains global ui settings exposed by API
 type GeneralUISettings struct {
-	AllowedReactions []string `json:"allowed_reactions"`
+	AllowedReactions       []string `json:"allowed_reactions"`
+	MaxResponseItems       int      `json:"max_response_items"`
+	DefaultPagingNum       int      `json:"default_paging_num`
+	DefaultGitTreesPerPage int      `json:"default_git_trees_per_page"`
+	DefaultMaxBlobSize     int64    `json:"default_max_blob_size"`
 }
diff --git a/routers/api/v1/settings/settings.go b/routers/api/v1/settings/settings.go
index 8403a51d3..4bf750e19 100644
--- a/routers/api/v1/settings/settings.go
+++ b/routers/api/v1/settings/settings.go
@@ -23,7 +23,11 @@ func GetGeneralUISettings(ctx *context.APIContext) {
 	//   "200":
 	//     "$ref": "#/responses/GeneralUISettings"
 	ctx.JSON(http.StatusOK, api.GeneralUISettings{
-		AllowedReactions: setting.UI.Reactions,
+		AllowedReactions:       setting.UI.Reactions,
+		MaxResponseItems:       setting.API.MaxResponseItems,
+		DefaultPagingNum:       setting.API.DefaultPagingNum,
+		DefaultGitTreesPerPage: setting.API.DefaultGitTreesPerPage,
+		DefaultMaxBlobSize:     setting.API.DefaultMaxBlobSize,
 	})
 }
 
-- 
2.25.1
@zeripath commented on GitHub (Sep 4, 2020): I guess something like this would do? ```patch From 41bc6c6c92233d0b46aa2d0bdd5bf3c311cd1abf Mon Sep 17 00:00:00 2001 From: Andrew Thornton <art27@cantab.net> Date: Fri, 4 Sep 2020 11:44:53 +0100 Subject: [PATCH] Add API settings to GeneralUISettings Fix #12664 Signed-off-by: Andrew Thornton <art27@cantab.net> --- modules/structs/settings.go | 6 +++++- routers/api/v1/settings/settings.go | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/modules/structs/settings.go b/modules/structs/settings.go index 4a6e0ce5a..456cfb74f 100644 --- a/modules/structs/settings.go +++ b/modules/structs/settings.go @@ -12,5 +12,9 @@ type GeneralRepoSettings struct { // GeneralUISettings contains global ui settings exposed by API type GeneralUISettings struct { - AllowedReactions []string `json:"allowed_reactions"` + AllowedReactions []string `json:"allowed_reactions"` + MaxResponseItems int `json:"max_response_items"` + DefaultPagingNum int `json:"default_paging_num` + DefaultGitTreesPerPage int `json:"default_git_trees_per_page"` + DefaultMaxBlobSize int64 `json:"default_max_blob_size"` } diff --git a/routers/api/v1/settings/settings.go b/routers/api/v1/settings/settings.go index 8403a51d3..4bf750e19 100644 --- a/routers/api/v1/settings/settings.go +++ b/routers/api/v1/settings/settings.go @@ -23,7 +23,11 @@ func GetGeneralUISettings(ctx *context.APIContext) { // "200": // "$ref": "#/responses/GeneralUISettings" ctx.JSON(http.StatusOK, api.GeneralUISettings{ - AllowedReactions: setting.UI.Reactions, + AllowedReactions: setting.UI.Reactions, + MaxResponseItems: setting.API.MaxResponseItems, + DefaultPagingNum: setting.API.DefaultPagingNum, + DefaultGitTreesPerPage: setting.API.DefaultGitTreesPerPage, + DefaultMaxBlobSize: setting.API.DefaultMaxBlobSize, }) } -- 2.25.1 ```
Author
Owner

@zeripath commented on GitHub (Sep 4, 2020):

probably would be safe to expose all of those settings as an enemy could easily work them out?

@zeripath commented on GitHub (Sep 4, 2020): probably would be safe to expose all of those settings as an enemy could easily work them out?
Author
Owner

@6543 commented on GitHub (Sep 4, 2020):

@zeripath not all but most

@6543 commented on GitHub (Sep 4, 2020): @zeripath not all but most
Author
Owner

@6543 commented on GitHub (Sep 4, 2020):

@zeripath -> #12714

@6543 commented on GitHub (Sep 4, 2020): @zeripath -> #12714
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#5927