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 <art27@cantab.net>
Reviewed-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
6543 2020-09-07 22:19:38 +00:00 committed by techknowlogick
parent 5b418aa8c6
commit 87f7b1866d
2 changed files with 26 additions and 0 deletions

View File

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

View File

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