summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2022-09-29 21:50:43 +0100
committerLibravatar GitHub <noreply@github.com>2022-09-29 21:50:43 +0100
commit1d999712e6902414bbac30db8a5603758c5c539c (patch)
tree6d4da7aaa8c1e7fc94c5723703f13e5b6d062dfc /internal
parent[chore] Add ipv6 localhost to trusted proxies by default (#868) (diff)
downloadgotosocial-1d999712e6902414bbac30db8a5603758c5c539c.tar.xz
[feature] update config types to use bytesize.Size (#828)
* update config size types to use bytesize.Size * submit unchecked-out file ... :facepalm: * fix bytesize config var decoding * bump bytesize version * update kim's libraries in readme * update envparse.sh to output more useful errors * improve envparse.sh * remove reliance on jq * instead, use uint64 for bytesize flag types * remove redundant type * fix viper unmarshaling * Update envparsing.sh * fix envparsing test Signed-off-by: kim <grufwub@gmail.com> Co-authored-by: tobi <31960611+tsmethurst@users.noreply.github.com>
Diffstat (limited to 'internal')
-rw-r--r--internal/config/config.go15
-rw-r--r--internal/config/flags.go8
-rw-r--r--internal/config/gen/gen.go2
-rw-r--r--internal/config/global.go4
-rw-r--r--internal/config/helpers.gen.go34
-rw-r--r--internal/config/state.go6
-rw-r--r--internal/config/validate.go8
-rw-r--r--internal/config/validate_test.go10
-rw-r--r--internal/federation/dereferencing/account.go4
-rw-r--r--internal/federation/dereferencing/emoji.go2
-rw-r--r--internal/federation/dereferencing/media.go2
-rw-r--r--internal/media/manager_test.go46
-rw-r--r--internal/media/processingemoji.go8
-rw-r--r--internal/media/processingmedia.go4
-rw-r--r--internal/media/pruneremote_test.go4
-rw-r--r--internal/media/types.go2
-rw-r--r--internal/media/util.go6
-rw-r--r--internal/processing/account/update.go12
-rw-r--r--internal/processing/admin/emoji.go4
-rw-r--r--internal/processing/media/create.go4
-rw-r--r--internal/processing/media/getfile.go4
-rw-r--r--internal/transport/derefmedia.go4
-rw-r--r--internal/transport/transport.go2
-rw-r--r--internal/typeutils/internaltofrontend.go4
24 files changed, 96 insertions, 103 deletions
diff --git a/internal/config/config.go b/internal/config/config.go
index ff77bd367..79babf8bc 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -21,6 +21,7 @@ package config
import (
"reflect"
+ "codeberg.org/gruf/go-bytesize"
"github.com/mitchellh/mapstructure"
)
@@ -76,13 +77,13 @@ type Configuration struct {
AccountsReasonRequired bool `name:"accounts-reason-required" usage:"Do new account signups require a reason to be submitted on registration?"`
AccountsAllowCustomCSS bool `name:"accounts-allow-custom-css" usage:"Allow accounts to enable custom CSS for their profile pages and statuses."`
- MediaImageMaxSize int `name:"media-image-max-size" usage:"Max size of accepted images in bytes"`
- MediaVideoMaxSize int `name:"media-video-max-size" usage:"Max size of accepted videos in bytes"`
- MediaDescriptionMinChars int `name:"media-description-min-chars" usage:"Min required chars for an image description"`
- MediaDescriptionMaxChars int `name:"media-description-max-chars" usage:"Max permitted chars for an image description"`
- MediaRemoteCacheDays int `name:"media-remote-cache-days" usage:"Number of days to locally cache media from remote instances. If set to 0, remote media will be kept indefinitely."`
- MediaEmojiLocalMaxSize int `name:"media-emoji-local-max-size" usage:"Max size in bytes of emojis uploaded to this instance via the admin API."`
- MediaEmojiRemoteMaxSize int `name:"media-emoji-remote-max-size" usage:"Max size in bytes of emojis to download from other instances."`
+ MediaImageMaxSize bytesize.Size `name:"media-image-max-size" usage:"Max size of accepted images in bytes"`
+ MediaVideoMaxSize bytesize.Size `name:"media-video-max-size" usage:"Max size of accepted videos in bytes"`
+ MediaDescriptionMinChars int `name:"media-description-min-chars" usage:"Min required chars for an image description"`
+ MediaDescriptionMaxChars int `name:"media-description-max-chars" usage:"Max permitted chars for an image description"`
+ MediaRemoteCacheDays int `name:"media-remote-cache-days" usage:"Number of days to locally cache media from remote instances. If set to 0, remote media will be kept indefinitely."`
+ MediaEmojiLocalMaxSize bytesize.Size `name:"media-emoji-local-max-size" usage:"Max size in bytes of emojis uploaded to this instance via the admin API."`
+ MediaEmojiRemoteMaxSize bytesize.Size `name:"media-emoji-remote-max-size" usage:"Max size in bytes of emojis to download from other instances."`
StorageBackend string `name:"storage-backend" usage:"Storage backend to use for media attachments"`
StorageLocalBasePath string `name:"storage-local-base-path" usage:"Full path to an already-created directory where gts should store/retrieve media files. Subfolders will be created within this dir."`
diff --git a/internal/config/flags.go b/internal/config/flags.go
index f37a50c9e..7b416815e 100644
--- a/internal/config/flags.go
+++ b/internal/config/flags.go
@@ -72,13 +72,13 @@ func AddServerFlags(cmd *cobra.Command) {
cmd.Flags().Bool(AccountsAllowCustomCSSFlag(), cfg.AccountsAllowCustomCSS, fieldtag("AccountsAllowCustomCSS", "usage"))
// Media
- cmd.Flags().Int(MediaImageMaxSizeFlag(), cfg.MediaImageMaxSize, fieldtag("MediaImageMaxSize", "usage"))
- cmd.Flags().Int(MediaVideoMaxSizeFlag(), cfg.MediaVideoMaxSize, fieldtag("MediaVideoMaxSize", "usage"))
+ cmd.Flags().Uint64(MediaImageMaxSizeFlag(), uint64(cfg.MediaImageMaxSize), fieldtag("MediaImageMaxSize", "usage"))
+ cmd.Flags().Uint64(MediaVideoMaxSizeFlag(), uint64(cfg.MediaVideoMaxSize), fieldtag("MediaVideoMaxSize", "usage"))
cmd.Flags().Int(MediaDescriptionMinCharsFlag(), cfg.MediaDescriptionMinChars, fieldtag("MediaDescriptionMinChars", "usage"))
cmd.Flags().Int(MediaDescriptionMaxCharsFlag(), cfg.MediaDescriptionMaxChars, fieldtag("MediaDescriptionMaxChars", "usage"))
cmd.Flags().Int(MediaRemoteCacheDaysFlag(), cfg.MediaRemoteCacheDays, fieldtag("MediaRemoteCacheDays", "usage"))
- cmd.Flags().Int(MediaEmojiLocalMaxSizeFlag(), cfg.MediaEmojiLocalMaxSize, fieldtag("MediaEmojiLocalMaxSize", "usage"))
- cmd.Flags().Int(MediaEmojiRemoteMaxSizeFlag(), cfg.MediaEmojiRemoteMaxSize, fieldtag("MediaEmojiRemoteMaxSize", "usage"))
+ cmd.Flags().Uint64(MediaEmojiLocalMaxSizeFlag(), uint64(cfg.MediaEmojiLocalMaxSize), fieldtag("MediaEmojiLocalMaxSize", "usage"))
+ cmd.Flags().Uint64(MediaEmojiRemoteMaxSizeFlag(), uint64(cfg.MediaEmojiRemoteMaxSize), fieldtag("MediaEmojiRemoteMaxSize", "usage"))
// Storage
cmd.Flags().String(StorageBackendFlag(), cfg.StorageBackend, fieldtag("StorageBackend", "usage"))
diff --git a/internal/config/gen/gen.go b/internal/config/gen/gen.go
index d36fee0e9..e92483939 100644
--- a/internal/config/gen/gen.go
+++ b/internal/config/gen/gen.go
@@ -100,7 +100,7 @@ func main() {
fmt.Fprintf(output, "func Set%[1]s(v %[2]s) { global.Set%[1]s(v) }\n\n", field.Name, field.Type.String())
}
_ = output.Close()
- _ = exec.Command("gofmt", "-w", out).Run()
+ _ = exec.Command("gofumports", "-w", out).Run()
// The plain here is that eventually we might be able
// to generate an example configuration from struct tags
diff --git a/internal/config/global.go b/internal/config/global.go
index 8752fc925..707afb3cd 100644
--- a/internal/config/global.go
+++ b/internal/config/global.go
@@ -18,7 +18,9 @@
package config
-import "github.com/spf13/cobra"
+import (
+ "github.com/spf13/cobra"
+)
var global *ConfigState
diff --git a/internal/config/helpers.gen.go b/internal/config/helpers.gen.go
index adc020aba..71f96920f 100644
--- a/internal/config/helpers.gen.go
+++ b/internal/config/helpers.gen.go
@@ -18,6 +18,8 @@
*/
package config
+import "codeberg.org/gruf/go-bytesize"
+
// GetLogLevel safely fetches the Configuration value for state's 'LogLevel' field
func (st *ConfigState) GetLogLevel() (v string) {
st.mutex.Lock()
@@ -719,7 +721,7 @@ func GetAccountsAllowCustomCSS() bool { return global.GetAccountsAllowCustomCSS(
func SetAccountsAllowCustomCSS(v bool) { global.SetAccountsAllowCustomCSS(v) }
// GetMediaImageMaxSize safely fetches the Configuration value for state's 'MediaImageMaxSize' field
-func (st *ConfigState) GetMediaImageMaxSize() (v int) {
+func (st *ConfigState) GetMediaImageMaxSize() (v bytesize.Size) {
st.mutex.Lock()
v = st.config.MediaImageMaxSize
st.mutex.Unlock()
@@ -727,7 +729,7 @@ func (st *ConfigState) GetMediaImageMaxSize() (v int) {
}
// SetMediaImageMaxSize safely sets the Configuration value for state's 'MediaImageMaxSize' field
-func (st *ConfigState) SetMediaImageMaxSize(v int) {
+func (st *ConfigState) SetMediaImageMaxSize(v bytesize.Size) {
st.mutex.Lock()
defer st.mutex.Unlock()
st.config.MediaImageMaxSize = v
@@ -738,13 +740,13 @@ func (st *ConfigState) SetMediaImageMaxSize(v int) {
func MediaImageMaxSizeFlag() string { return "media-image-max-size" }
// GetMediaImageMaxSize safely fetches the value for global configuration 'MediaImageMaxSize' field
-func GetMediaImageMaxSize() int { return global.GetMediaImageMaxSize() }
+func GetMediaImageMaxSize() bytesize.Size { return global.GetMediaImageMaxSize() }
// SetMediaImageMaxSize safely sets the value for global configuration 'MediaImageMaxSize' field
-func SetMediaImageMaxSize(v int) { global.SetMediaImageMaxSize(v) }
+func SetMediaImageMaxSize(v bytesize.Size) { global.SetMediaImageMaxSize(v) }
// GetMediaVideoMaxSize safely fetches the Configuration value for state's 'MediaVideoMaxSize' field
-func (st *ConfigState) GetMediaVideoMaxSize() (v int) {
+func (st *ConfigState) GetMediaVideoMaxSize() (v bytesize.Size) {
st.mutex.Lock()
v = st.config.MediaVideoMaxSize
st.mutex.Unlock()
@@ -752,7 +754,7 @@ func (st *ConfigState) GetMediaVideoMaxSize() (v int) {
}
// SetMediaVideoMaxSize safely sets the Configuration value for state's 'MediaVideoMaxSize' field
-func (st *ConfigState) SetMediaVideoMaxSize(v int) {
+func (st *ConfigState) SetMediaVideoMaxSize(v bytesize.Size) {
st.mutex.Lock()
defer st.mutex.Unlock()
st.config.MediaVideoMaxSize = v
@@ -763,10 +765,10 @@ func (st *ConfigState) SetMediaVideoMaxSize(v int) {
func MediaVideoMaxSizeFlag() string { return "media-video-max-size" }
// GetMediaVideoMaxSize safely fetches the value for global configuration 'MediaVideoMaxSize' field
-func GetMediaVideoMaxSize() int { return global.GetMediaVideoMaxSize() }
+func GetMediaVideoMaxSize() bytesize.Size { return global.GetMediaVideoMaxSize() }
// SetMediaVideoMaxSize safely sets the value for global configuration 'MediaVideoMaxSize' field
-func SetMediaVideoMaxSize(v int) { global.SetMediaVideoMaxSize(v) }
+func SetMediaVideoMaxSize(v bytesize.Size) { global.SetMediaVideoMaxSize(v) }
// GetMediaDescriptionMinChars safely fetches the Configuration value for state's 'MediaDescriptionMinChars' field
func (st *ConfigState) GetMediaDescriptionMinChars() (v int) {
@@ -844,7 +846,7 @@ func GetMediaRemoteCacheDays() int { return global.GetMediaRemoteCacheDays() }
func SetMediaRemoteCacheDays(v int) { global.SetMediaRemoteCacheDays(v) }
// GetMediaEmojiLocalMaxSize safely fetches the Configuration value for state's 'MediaEmojiLocalMaxSize' field
-func (st *ConfigState) GetMediaEmojiLocalMaxSize() (v int) {
+func (st *ConfigState) GetMediaEmojiLocalMaxSize() (v bytesize.Size) {
st.mutex.Lock()
v = st.config.MediaEmojiLocalMaxSize
st.mutex.Unlock()
@@ -852,7 +854,7 @@ func (st *ConfigState) GetMediaEmojiLocalMaxSize() (v int) {
}
// SetMediaEmojiLocalMaxSize safely sets the Configuration value for state's 'MediaEmojiLocalMaxSize' field
-func (st *ConfigState) SetMediaEmojiLocalMaxSize(v int) {
+func (st *ConfigState) SetMediaEmojiLocalMaxSize(v bytesize.Size) {
st.mutex.Lock()
defer st.mutex.Unlock()
st.config.MediaEmojiLocalMaxSize = v
@@ -863,13 +865,13 @@ func (st *ConfigState) SetMediaEmojiLocalMaxSize(v int) {
func MediaEmojiLocalMaxSizeFlag() string { return "media-emoji-local-max-size" }
// GetMediaEmojiLocalMaxSize safely fetches the value for global configuration 'MediaEmojiLocalMaxSize' field
-func GetMediaEmojiLocalMaxSize() int { return global.GetMediaEmojiLocalMaxSize() }
+func GetMediaEmojiLocalMaxSize() bytesize.Size { return global.GetMediaEmojiLocalMaxSize() }
// SetMediaEmojiLocalMaxSize safely sets the value for global configuration 'MediaEmojiLocalMaxSize' field
-func SetMediaEmojiLocalMaxSize(v int) { global.SetMediaEmojiLocalMaxSize(v) }
+func SetMediaEmojiLocalMaxSize(v bytesize.Size) { global.SetMediaEmojiLocalMaxSize(v) }
// GetMediaEmojiRemoteMaxSize safely fetches the Configuration value for state's 'MediaEmojiRemoteMaxSize' field
-func (st *ConfigState) GetMediaEmojiRemoteMaxSize() (v int) {
+func (st *ConfigState) GetMediaEmojiRemoteMaxSize() (v bytesize.Size) {
st.mutex.Lock()
v = st.config.MediaEmojiRemoteMaxSize
st.mutex.Unlock()
@@ -877,7 +879,7 @@ func (st *ConfigState) GetMediaEmojiRemoteMaxSize() (v int) {
}
// SetMediaEmojiRemoteMaxSize safely sets the Configuration value for state's 'MediaEmojiRemoteMaxSize' field
-func (st *ConfigState) SetMediaEmojiRemoteMaxSize(v int) {
+func (st *ConfigState) SetMediaEmojiRemoteMaxSize(v bytesize.Size) {
st.mutex.Lock()
defer st.mutex.Unlock()
st.config.MediaEmojiRemoteMaxSize = v
@@ -888,10 +890,10 @@ func (st *ConfigState) SetMediaEmojiRemoteMaxSize(v int) {
func MediaEmojiRemoteMaxSizeFlag() string { return "media-emoji-remote-max-size" }
// GetMediaEmojiRemoteMaxSize safely fetches the value for global configuration 'MediaEmojiRemoteMaxSize' field
-func GetMediaEmojiRemoteMaxSize() int { return global.GetMediaEmojiRemoteMaxSize() }
+func GetMediaEmojiRemoteMaxSize() bytesize.Size { return global.GetMediaEmojiRemoteMaxSize() }
// SetMediaEmojiRemoteMaxSize safely sets the value for global configuration 'MediaEmojiRemoteMaxSize' field
-func SetMediaEmojiRemoteMaxSize(v int) { global.SetMediaEmojiRemoteMaxSize(v) }
+func SetMediaEmojiRemoteMaxSize(v bytesize.Size) { global.SetMediaEmojiRemoteMaxSize(v) }
// GetStorageBackend safely fetches the Configuration value for state's 'StorageBackend' field
func (st *ConfigState) GetStorageBackend() (v string) {
diff --git a/internal/config/state.go b/internal/config/state.go
index 1364fb84e..17fd31e2a 100644
--- a/internal/config/state.go
+++ b/internal/config/state.go
@@ -133,6 +133,12 @@ func (st *ConfigState) reloadFromViper() {
if err := st.viper.Unmarshal(&st.config, func(c *mapstructure.DecoderConfig) {
c.TagName = "name"
c.ZeroFields = true // empty the config struct before we marshal values into it
+
+ oldhook := c.DecodeHook
+ c.DecodeHook = mapstructure.ComposeDecodeHookFunc(
+ mapstructure.TextUnmarshallerHookFunc(),
+ oldhook,
+ )
}); err != nil {
panic(err)
}
diff --git a/internal/config/validate.go b/internal/config/validate.go
index b9fdb013b..064eae07a 100644
--- a/internal/config/validate.go
+++ b/internal/config/validate.go
@@ -67,14 +67,6 @@ func Validate() error {
errs = append(errs, fmt.Errorf("%s must be set", WebAssetBaseDirFlag()))
}
- if m := GetMediaEmojiLocalMaxSize(); m < 0 {
- errs = append(errs, fmt.Errorf("%s must not be less than 0", MediaEmojiLocalMaxSizeFlag()))
- }
-
- if m := GetMediaEmojiRemoteMaxSize(); m < 0 {
- errs = append(errs, fmt.Errorf("%s must not be less than 0", MediaEmojiRemoteMaxSizeFlag()))
- }
-
if len(errs) > 0 {
errStrings := []string{}
for _, err := range errs {
diff --git a/internal/config/validate_test.go b/internal/config/validate_test.go
index f7450cdaa..c3a998a4a 100644
--- a/internal/config/validate_test.go
+++ b/internal/config/validate_test.go
@@ -141,16 +141,6 @@ func (suite *ConfigValidateTestSuite) TestValidateConfigBadProtocolNoHost() {
suite.EqualError(err, "host must be set; protocol must be set to either http or https, provided value was foo")
}
-func (suite *ConfigValidateTestSuite) TestValidateConfigBadEmojiSizes() {
- testrig.InitTestConfig()
-
- config.SetMediaEmojiLocalMaxSize(-10)
- config.SetMediaEmojiRemoteMaxSize(-50)
-
- err := config.Validate()
- suite.EqualError(err, "media-emoji-local-max-size must not be less than 0; media-emoji-remote-max-size must not be less than 0")
-}
-
func TestConfigValidateTestSuite(t *testing.T) {
suite.Run(t, &ConfigValidateTestSuite{})
}
diff --git a/internal/federation/dereferencing/account.go b/internal/federation/dereferencing/account.go
index 41a8aa8a9..dfe7693fb 100644
--- a/internal/federation/dereferencing/account.go
+++ b/internal/federation/dereferencing/account.go
@@ -496,7 +496,7 @@ func (d *deref) fetchRemoteAccountMedia(ctx context.Context, targetAccount *gtsm
}
}
- data := func(innerCtx context.Context) (io.Reader, int, error) {
+ data := func(innerCtx context.Context) (io.Reader, int64, error) {
return t.DereferenceMedia(innerCtx, avatarIRI)
}
@@ -562,7 +562,7 @@ func (d *deref) fetchRemoteAccountMedia(ctx context.Context, targetAccount *gtsm
}
}
- data := func(innerCtx context.Context) (io.Reader, int, error) {
+ data := func(innerCtx context.Context) (io.Reader, int64, error) {
return t.DereferenceMedia(innerCtx, headerIRI)
}
diff --git a/internal/federation/dereferencing/emoji.go b/internal/federation/dereferencing/emoji.go
index 87d0bd515..622b131c9 100644
--- a/internal/federation/dereferencing/emoji.go
+++ b/internal/federation/dereferencing/emoji.go
@@ -42,7 +42,7 @@ func (d *deref) GetRemoteEmoji(ctx context.Context, requestingUsername string, r
return nil, fmt.Errorf("GetRemoteEmoji: error parsing url: %s", err)
}
- dataFunc := func(innerCtx context.Context) (io.Reader, int, error) {
+ dataFunc := func(innerCtx context.Context) (io.Reader, int64, error) {
return t.DereferenceMedia(innerCtx, derefURI)
}
diff --git a/internal/federation/dereferencing/media.go b/internal/federation/dereferencing/media.go
index 05fd70589..1b99eaa96 100644
--- a/internal/federation/dereferencing/media.go
+++ b/internal/federation/dereferencing/media.go
@@ -42,7 +42,7 @@ func (d *deref) GetRemoteMedia(ctx context.Context, requestingUsername string, a
return nil, fmt.Errorf("GetRemoteMedia: error parsing url: %s", err)
}
- dataFunc := func(innerCtx context.Context) (io.Reader, int, error) {
+ dataFunc := func(innerCtx context.Context) (io.Reader, int64, error) {
return t.DereferenceMedia(innerCtx, derefURI)
}
diff --git a/internal/media/manager_test.go b/internal/media/manager_test.go
index 7d1f59e70..f9c96259d 100644
--- a/internal/media/manager_test.go
+++ b/internal/media/manager_test.go
@@ -43,13 +43,13 @@ type ManagerTestSuite struct {
func (suite *ManagerTestSuite) TestEmojiProcessBlocking() {
ctx := context.Background()
- data := func(_ context.Context) (io.Reader, int, error) {
+ data := func(_ context.Context) (io.Reader, int64, error) {
// load bytes from a test image
b, err := os.ReadFile("./test/rainbow-original.png")
if err != nil {
panic(err)
}
- return bytes.NewBuffer(b), len(b), nil
+ return bytes.NewBuffer(b), int64(len(b)), nil
}
emojiID := "01GDQ9G782X42BAMFASKP64343"
@@ -104,13 +104,13 @@ func (suite *ManagerTestSuite) TestEmojiProcessBlocking() {
func (suite *ManagerTestSuite) TestEmojiProcessBlockingTooLarge() {
ctx := context.Background()
- data := func(_ context.Context) (io.Reader, int, error) {
+ data := func(_ context.Context) (io.Reader, int64, error) {
// load bytes from a test image
b, err := os.ReadFile("./test/big-panda.gif")
if err != nil {
panic(err)
}
- return bytes.NewBuffer(b), len(b), nil
+ return bytes.NewBuffer(b), int64(len(b)), nil
}
emojiID := "01GDQ9G782X42BAMFASKP64343"
@@ -128,13 +128,13 @@ func (suite *ManagerTestSuite) TestEmojiProcessBlockingTooLarge() {
func (suite *ManagerTestSuite) TestEmojiProcessBlockingTooLargeNoSizeGiven() {
ctx := context.Background()
- data := func(_ context.Context) (io.Reader, int, error) {
+ data := func(_ context.Context) (io.Reader, int64, error) {
// load bytes from a test image
b, err := os.ReadFile("./test/big-panda.gif")
if err != nil {
panic(err)
}
- return bytes.NewBuffer(b), len(b), nil
+ return bytes.NewBuffer(b), int64(len(b)), nil
}
emojiID := "01GDQ9G782X42BAMFASKP64343"
@@ -152,7 +152,7 @@ func (suite *ManagerTestSuite) TestEmojiProcessBlockingTooLargeNoSizeGiven() {
func (suite *ManagerTestSuite) TestEmojiProcessBlockingNoFileSizeGiven() {
ctx := context.Background()
- data := func(_ context.Context) (io.Reader, int, error) {
+ data := func(_ context.Context) (io.Reader, int64, error) {
// load bytes from a test image
b, err := os.ReadFile("./test/rainbow-original.png")
if err != nil {
@@ -214,13 +214,13 @@ func (suite *ManagerTestSuite) TestEmojiProcessBlockingNoFileSizeGiven() {
func (suite *ManagerTestSuite) TestSimpleJpegProcessBlocking() {
ctx := context.Background()
- data := func(_ context.Context) (io.Reader, int, error) {
+ data := func(_ context.Context) (io.Reader, int64, error) {
// load bytes from a test image
b, err := os.ReadFile("./test/test-jpeg.jpg")
if err != nil {
panic(err)
}
- return bytes.NewBuffer(b), len(b), nil
+ return bytes.NewBuffer(b), int64(len(b)), nil
}
accountID := "01FS1X72SK9ZPW0J1QQ68BD264"
@@ -286,7 +286,7 @@ func (suite *ManagerTestSuite) TestSimpleJpegProcessBlocking() {
func (suite *ManagerTestSuite) TestSimpleJpegProcessBlockingNoContentLengthGiven() {
ctx := context.Background()
- data := func(_ context.Context) (io.Reader, int, error) {
+ data := func(_ context.Context) (io.Reader, int64, error) {
// load bytes from a test image
b, err := os.ReadFile("./test/test-jpeg.jpg")
if err != nil {
@@ -359,7 +359,7 @@ func (suite *ManagerTestSuite) TestSimpleJpegProcessBlockingNoContentLengthGiven
func (suite *ManagerTestSuite) TestSimpleJpegProcessBlockingReadCloser() {
ctx := context.Background()
- data := func(_ context.Context) (io.Reader, int, error) {
+ data := func(_ context.Context) (io.Reader, int64, error) {
// open test image as a file
f, err := os.Open("./test/test-jpeg.jpg")
if err != nil {
@@ -432,13 +432,13 @@ func (suite *ManagerTestSuite) TestSimpleJpegProcessBlockingReadCloser() {
func (suite *ManagerTestSuite) TestPngNoAlphaChannelProcessBlocking() {
ctx := context.Background()
- data := func(_ context.Context) (io.Reader, int, error) {
+ data := func(_ context.Context) (io.Reader, int64, error) {
// load bytes from a test image
b, err := os.ReadFile("./test/test-png-noalphachannel.png")
if err != nil {
panic(err)
}
- return bytes.NewBuffer(b), len(b), nil
+ return bytes.NewBuffer(b), int64(len(b)), nil
}
accountID := "01FS1X72SK9ZPW0J1QQ68BD264"
@@ -504,13 +504,13 @@ func (suite *ManagerTestSuite) TestPngNoAlphaChannelProcessBlocking() {
func (suite *ManagerTestSuite) TestPngAlphaChannelProcessBlocking() {
ctx := context.Background()
- data := func(_ context.Context) (io.Reader, int, error) {
+ data := func(_ context.Context) (io.Reader, int64, error) {
// load bytes from a test image
b, err := os.ReadFile("./test/test-png-alphachannel.png")
if err != nil {
panic(err)
}
- return bytes.NewBuffer(b), len(b), nil
+ return bytes.NewBuffer(b), int64(len(b)), nil
}
accountID := "01FS1X72SK9ZPW0J1QQ68BD264"
@@ -576,13 +576,13 @@ func (suite *ManagerTestSuite) TestPngAlphaChannelProcessBlocking() {
func (suite *ManagerTestSuite) TestSimpleJpegProcessBlockingWithCallback() {
ctx := context.Background()
- data := func(_ context.Context) (io.Reader, int, error) {
+ data := func(_ context.Context) (io.Reader, int64, error) {
// load bytes from a test image
b, err := os.ReadFile("./test/test-jpeg.jpg")
if err != nil {
panic(err)
}
- return bytes.NewBuffer(b), len(b), nil
+ return bytes.NewBuffer(b), int64(len(b)), nil
}
// test the callback function by setting a simple boolean
@@ -659,13 +659,13 @@ func (suite *ManagerTestSuite) TestSimpleJpegProcessBlockingWithCallback() {
func (suite *ManagerTestSuite) TestSimpleJpegProcessAsync() {
ctx := context.Background()
- data := func(_ context.Context) (io.Reader, int, error) {
+ data := func(_ context.Context) (io.Reader, int64, error) {
// load bytes from a test image
b, err := os.ReadFile("./test/test-jpeg.jpg")
if err != nil {
panic(err)
}
- return bytes.NewBuffer(b), len(b), nil
+ return bytes.NewBuffer(b), int64(len(b)), nil
}
accountID := "01FS1X72SK9ZPW0J1QQ68BD264"
@@ -744,9 +744,9 @@ func (suite *ManagerTestSuite) TestSimpleJpegQueueSpamming() {
panic(err)
}
- data := func(_ context.Context) (io.Reader, int, error) {
+ data := func(_ context.Context) (io.Reader, int64, error) {
// load bytes from a test image
- return bytes.NewReader(b), len(b), nil
+ return bytes.NewReader(b), int64(len(b)), nil
}
accountID := "01FS1X72SK9ZPW0J1QQ68BD264"
@@ -820,13 +820,13 @@ func (suite *ManagerTestSuite) TestSimpleJpegQueueSpamming() {
func (suite *ManagerTestSuite) TestSimpleJpegProcessBlockingWithDiskStorage() {
ctx := context.Background()
- data := func(_ context.Context) (io.Reader, int, error) {
+ data := func(_ context.Context) (io.Reader, int64, error) {
// load bytes from a test image
b, err := os.ReadFile("./test/test-jpeg.jpg")
if err != nil {
panic(err)
}
- return bytes.NewBuffer(b), len(b), nil
+ return bytes.NewBuffer(b), int64(len(b)), nil
}
accountID := "01FS1X72SK9ZPW0J1QQ68BD264"
diff --git a/internal/media/processingemoji.go b/internal/media/processingemoji.go
index 7dfe51cb3..6495b991e 100644
--- a/internal/media/processingemoji.go
+++ b/internal/media/processingemoji.go
@@ -210,11 +210,11 @@ func (p *ProcessingEmoji) store(ctx context.Context) error {
// concatenate the first bytes with the existing bytes still in the reader (thanks Mara)
readerToStore := io.MultiReader(bytes.NewBuffer(firstBytes), reader)
- var maxEmojiSize int
+ var maxEmojiSize int64
if p.emoji.Domain == "" {
- maxEmojiSize = config.GetMediaEmojiLocalMaxSize()
+ maxEmojiSize = int64(config.GetMediaEmojiLocalMaxSize())
} else {
- maxEmojiSize = config.GetMediaEmojiRemoteMaxSize()
+ maxEmojiSize = int64(config.GetMediaEmojiRemoteMaxSize())
}
// if we know the fileSize already, make sure it's not bigger than our limit
@@ -241,7 +241,7 @@ func (p *ProcessingEmoji) store(ctx context.Context) error {
return fmt.Errorf("store: discovered emoji fileSize (%db) is larger than allowed emojiRemoteMaxSize (%db)", fileSize, maxEmojiSize)
}
- p.emoji.ImageFileSize = fileSize
+ p.emoji.ImageFileSize = int(fileSize)
p.read = true
if p.postData != nil {
diff --git a/internal/media/processingmedia.go b/internal/media/processingmedia.go
index 5a8e6f590..c22bddfeb 100644
--- a/internal/media/processingmedia.go
+++ b/internal/media/processingmedia.go
@@ -315,7 +315,7 @@ func (p *ProcessingMedia) store(ctx context.Context) error {
p.attachment.Type = gtsmodel.FileTypeImage
if fileSize > 0 {
var err error
- readerToStore, err = terminator.Terminate(readerToStore, fileSize, extension)
+ readerToStore, err = terminator.Terminate(readerToStore, int(fileSize), extension)
if err != nil {
return fmt.Errorf("store: exif error: %s", err)
}
@@ -344,7 +344,7 @@ func (p *ProcessingMedia) store(ctx context.Context) error {
cached := true
p.attachment.Cached = &cached
- p.attachment.File.FileSize = fileSize
+ p.attachment.File.FileSize = int(fileSize)
p.read = true
if p.postData != nil {
diff --git a/internal/media/pruneremote_test.go b/internal/media/pruneremote_test.go
index ddf4cb568..e71d3310b 100644
--- a/internal/media/pruneremote_test.go
+++ b/internal/media/pruneremote_test.go
@@ -74,13 +74,13 @@ func (suite *PruneRemoteTestSuite) TestPruneAndRecache() {
suite.ErrorIs(err, storage.ErrNotFound)
// now recache the image....
- data := func(_ context.Context) (io.Reader, int, error) {
+ data := func(_ context.Context) (io.Reader, int64, error) {
// load bytes from a test image
b, err := os.ReadFile("../../testrig/media/thoughtsofdog-original.jpeg")
if err != nil {
panic(err)
}
- return bytes.NewBuffer(b), len(b), nil
+ return bytes.NewBuffer(b), int64(len(b)), nil
}
processingRecache, err := suite.manager.RecacheMedia(ctx, data, nil, testAttachment.ID)
suite.NoError(err)
diff --git a/internal/media/types.go b/internal/media/types.go
index cceff216c..d71080658 100644
--- a/internal/media/types.go
+++ b/internal/media/types.go
@@ -118,7 +118,7 @@ type AdditionalEmojiInfo struct {
}
// DataFunc represents a function used to retrieve the raw bytes of a piece of media.
-type DataFunc func(ctx context.Context) (reader io.Reader, fileSize int, err error)
+type DataFunc func(ctx context.Context) (reader io.Reader, fileSize int64, err error)
// PostDataCallbackFunc represents a function executed after the DataFunc has been executed,
// and the returned reader has been read. It can be used to clean up any remaining resources.
diff --git a/internal/media/util.go b/internal/media/util.go
index b89196f87..2968ca2f6 100644
--- a/internal/media/util.go
+++ b/internal/media/util.go
@@ -151,19 +151,19 @@ func parseOlderThan(olderThanDays int) (time.Time, error) {
// lengthReader wraps a reader and reads the length of total bytes written as it goes.
type lengthReader struct {
source io.Reader
- length int
+ length int64
}
func (r *lengthReader) Read(b []byte) (int, error) {
n, err := r.source.Read(b)
- r.length += n
+ r.length += int64(n)
return n, err
}
// putStream either puts a file with a known fileSize into storage directly, and returns the
// fileSize unchanged, or it wraps the reader with a lengthReader and returns the discovered
// fileSize.
-func putStream(ctx context.Context, storage storage.Driver, key string, r io.Reader, fileSize int) (int, error) {
+func putStream(ctx context.Context, storage storage.Driver, key string, r io.Reader, fileSize int64) (int64, error) {
if fileSize > 0 {
return fileSize, storage.PutStream(ctx, key, r)
}
diff --git a/internal/processing/account/update.go b/internal/processing/account/update.go
index eddaeab27..94e91ca4c 100644
--- a/internal/processing/account/update.go
+++ b/internal/processing/account/update.go
@@ -184,13 +184,13 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form
// the account's new avatar image.
func (p *processor) UpdateAvatar(ctx context.Context, avatar *multipart.FileHeader, accountID string) (*gtsmodel.MediaAttachment, error) {
maxImageSize := config.GetMediaImageMaxSize()
- if int(avatar.Size) > maxImageSize {
+ if avatar.Size > int64(maxImageSize) {
return nil, fmt.Errorf("UpdateAvatar: avatar with size %d exceeded max image size of %d bytes", avatar.Size, maxImageSize)
}
- dataFunc := func(innerCtx context.Context) (io.Reader, int, error) {
+ dataFunc := func(innerCtx context.Context) (io.Reader, int64, error) {
f, err := avatar.Open()
- return f, int(avatar.Size), err
+ return f, avatar.Size, err
}
isAvatar := true
@@ -211,13 +211,13 @@ func (p *processor) UpdateAvatar(ctx context.Context, avatar *multipart.FileHead
// the account's new header image.
func (p *processor) UpdateHeader(ctx context.Context, header *multipart.FileHeader, accountID string) (*gtsmodel.MediaAttachment, error) {
maxImageSize := config.GetMediaImageMaxSize()
- if int(header.Size) > maxImageSize {
+ if header.Size > int64(maxImageSize) {
return nil, fmt.Errorf("UpdateHeader: header with size %d exceeded max image size of %d bytes", header.Size, maxImageSize)
}
- dataFunc := func(innerCtx context.Context) (io.Reader, int, error) {
+ dataFunc := func(innerCtx context.Context) (io.Reader, int64, error) {
f, err := header.Open()
- return f, int(header.Size), err
+ return f, header.Size, err
}
isHeader := true
diff --git a/internal/processing/admin/emoji.go b/internal/processing/admin/emoji.go
index ffb369493..50399279c 100644
--- a/internal/processing/admin/emoji.go
+++ b/internal/processing/admin/emoji.go
@@ -52,9 +52,9 @@ func (p *processor) EmojiCreate(ctx context.Context, account *gtsmodel.Account,
emojiURI := uris.GenerateURIForEmoji(emojiID)
- data := func(innerCtx context.Context) (io.Reader, int, error) {
+ data := func(innerCtx context.Context) (io.Reader, int64, error) {
f, err := form.Image.Open()
- return f, int(form.Image.Size), err
+ return f, form.Image.Size, err
}
processingEmoji, err := p.mediaManager.ProcessEmoji(ctx, data, nil, form.Shortcode, emojiID, emojiURI, nil)
diff --git a/internal/processing/media/create.go b/internal/processing/media/create.go
index 1f40ac48f..eb0c251e9 100644
--- a/internal/processing/media/create.go
+++ b/internal/processing/media/create.go
@@ -30,9 +30,9 @@ import (
)
func (p *processor) Create(ctx context.Context, account *gtsmodel.Account, form *apimodel.AttachmentRequest) (*apimodel.Attachment, gtserror.WithCode) {
- data := func(innerCtx context.Context) (io.Reader, int, error) {
+ data := func(innerCtx context.Context) (io.Reader, int64, error) {
f, err := form.File.Open()
- return f, int(form.File.Size), err
+ return f, form.File.Size, err
}
focusX, focusY, err := parseFocus(form.Focus)
diff --git a/internal/processing/media/getfile.go b/internal/processing/media/getfile.go
index 7435a241d..104bca770 100644
--- a/internal/processing/media/getfile.go
+++ b/internal/processing/media/getfile.go
@@ -138,7 +138,7 @@ func (p *processor) getAttachmentContent(ctx context.Context, requestingAccount
// if it's the thumbnail that's requested then the user will have to wait a bit while we process the
// large version and derive a thumbnail from it, so use the normal recaching procedure: fetch the media,
// process it, then return the thumbnail data
- data = func(innerCtx context.Context) (io.Reader, int, error) {
+ data = func(innerCtx context.Context) (io.Reader, int64, error) {
transport, err := p.transportController.NewTransportForUsername(innerCtx, requestingUsername)
if err != nil {
return nil, 0, err
@@ -169,7 +169,7 @@ func (p *processor) getAttachmentContent(ctx context.Context, requestingAccount
// the caller will read from the buffered reader, so it doesn't matter if they drop out without reading everything
attachmentContent.Content = bufferedReader
- data = func(innerCtx context.Context) (io.Reader, int, error) {
+ data = func(innerCtx context.Context) (io.Reader, int64, error) {
transport, err := p.transportController.NewTransportForUsername(innerCtx, requestingUsername)
if err != nil {
return nil, 0, err
diff --git a/internal/transport/derefmedia.go b/internal/transport/derefmedia.go
index 8feb7ed20..14c054cdf 100644
--- a/internal/transport/derefmedia.go
+++ b/internal/transport/derefmedia.go
@@ -26,7 +26,7 @@ import (
"net/url"
)
-func (t *transport) DereferenceMedia(ctx context.Context, iri *url.URL) (io.ReadCloser, int, error) {
+func (t *transport) DereferenceMedia(ctx context.Context, iri *url.URL) (io.ReadCloser, int64, error) {
// Build IRI just once
iriStr := iri.String()
@@ -50,5 +50,5 @@ func (t *transport) DereferenceMedia(ctx context.Context, iri *url.URL) (io.Read
return nil, 0, fmt.Errorf("GET request to %s failed (%d): %s", iriStr, rsp.StatusCode, rsp.Status)
}
- return rsp.Body, int(rsp.ContentLength), nil
+ return rsp.Body, rsp.ContentLength, nil
}
diff --git a/internal/transport/transport.go b/internal/transport/transport.go
index 80710a519..5af8b738e 100644
--- a/internal/transport/transport.go
+++ b/internal/transport/transport.go
@@ -47,7 +47,7 @@ import (
type Transport interface {
pub.Transport
// DereferenceMedia fetches the given media attachment IRI, returning the reader and filesize.
- DereferenceMedia(ctx context.Context, iri *url.URL) (io.ReadCloser, int, error)
+ DereferenceMedia(ctx context.Context, iri *url.URL) (io.ReadCloser, int64, error)
// DereferenceInstance dereferences remote instance information, first by checking /api/v1/instance, and then by checking /.well-known/nodeinfo.
DereferenceInstance(ctx context.Context, iri *url.URL) (*gtsmodel.Instance, error)
// Finger performs a webfinger request with the given username and domain, and returns the bytes from the response body.
diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go
index ca86a1284..aa98180d3 100644
--- a/internal/typeutils/internaltofrontend.go
+++ b/internal/typeutils/internaltofrontend.go
@@ -688,9 +688,9 @@ func (c *converter) InstanceToAPIInstance(ctx context.Context, i *gtsmodel.Insta
},
MediaAttachments: &model.InstanceConfigurationMediaAttachments{
SupportedMimeTypes: media.AllSupportedMIMETypes(),
- ImageSizeLimit: config.GetMediaImageMaxSize(),
+ ImageSizeLimit: int(config.GetMediaImageMaxSize()),
ImageMatrixLimit: instanceMediaAttachmentsImageMatrixLimit, // height*width
- VideoSizeLimit: config.GetMediaVideoMaxSize(),
+ VideoSizeLimit: int(config.GetMediaVideoMaxSize()),
VideoFrameRateLimit: instanceMediaAttachmentsVideoFrameRateLimit,
VideoMatrixLimit: instanceMediaAttachmentsVideoMatrixLimit, // height*width
},