From 1d999712e6902414bbac30db8a5603758c5c539c Mon Sep 17 00:00:00 2001 From: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> Date: Thu, 29 Sep 2022 21:50:43 +0100 Subject: [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 Co-authored-by: tobi <31960611+tsmethurst@users.noreply.github.com> --- internal/processing/account/update.go | 12 ++++++------ internal/processing/admin/emoji.go | 4 ++-- internal/processing/media/create.go | 4 ++-- internal/processing/media/getfile.go | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) (limited to 'internal/processing') 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 -- cgit v1.2.3