From 87f7b1866d63d46c14d171809794221cbe83bb83 Mon Sep 17 00:00:00 2001 From: 6543 <6543@noreply.gitea.io> Date: Mon, 7 Sep 2020 22:19:38 +0000 Subject: [PATCH] Add GetGlobalAttachmentSettings (#414) Add GetGlobalAttachmentSettings Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/414 Reviewed-by: Andrew Thornton Reviewed-by: techknowlogick --- gitea/settings.go | 17 +++++++++++++++++ gitea/settings_test.go | 9 +++++++++ 2 files changed, 26 insertions(+) diff --git a/gitea/settings.go b/gitea/settings.go index 1e8cd2a..1ef1d93 100644 --- a/gitea/settings.go +++ b/gitea/settings.go @@ -23,6 +23,14 @@ type GlobalAPISettings struct { DefaultMaxBlobSize int64 `json:"default_max_blob_size"` } +// GlobalAttachmentSettings contains global Attachment settings exposed by API +type GlobalAttachmentSettings struct { + Enabled bool `json:"enabled"` + AllowedTypes string `json:"allowed_types"` + MaxSize int64 `json:"max_size"` + MaxFiles int `json:"max_files"` +} + // GetGlobalUISettings get global ui settings witch are exposed by API func (c *Client) GetGlobalUISettings() (settings *GlobalUISettings, err error) { if err := c.CheckServerVersionConstraint(">=1.13.0"); err != nil { @@ -49,3 +57,12 @@ func (c *Client) GetGlobalAPISettings() (settings *GlobalAPISettings, err error) conf := new(GlobalAPISettings) return conf, c.getParsedResponse("GET", "/settings/api", jsonHeader, nil, &conf) } + +// GetGlobalAttachmentSettings get global repository settings witch are exposed by API +func (c *Client) GetGlobalAttachmentSettings() (settings *GlobalAttachmentSettings, err error) { + if err := c.CheckServerVersionConstraint(">=1.13.0"); err != nil { + return nil, err + } + conf := new(GlobalAttachmentSettings) + return conf, c.getParsedResponse("GET", "/settings/attachment", jsonHeader, nil, &conf) +} diff --git a/gitea/settings_test.go b/gitea/settings_test.go index cd9a43c..d4e1027 100644 --- a/gitea/settings_test.go +++ b/gitea/settings_test.go @@ -35,4 +35,13 @@ func TestGetGlobalSettings(t *testing.T) { DefaultGitTreesPerPage: 1000, DefaultMaxBlobSize: 10485760, }, apiSettings) + + attachSettings, err := c.GetGlobalAttachmentSettings() + assert.NoError(t, err) + assert.EqualValues(t, &GlobalAttachmentSettings{ + Enabled: true, + AllowedTypes: "image/jpeg,image/png,application/zip,application/gzip", + MaxSize: 4, + MaxFiles: 5, + }, attachSettings) }