diff options
| author | 2025-07-17 13:20:01 +0200 | |
|---|---|---|
| committer | 2025-07-17 13:20:01 +0200 | |
| commit | a4b54aa935f60d392cdaec7c4d315ff274ce73b5 (patch) | |
| tree | 26e18a529929f6170570f0ca8b42a3ef10d84839 /internal/media/manager_test.go | |
| parent | [bugfix] use correct interaction type for pre-accepted interaction requests (... (diff) | |
| download | gotosocial-a4b54aa935f60d392cdaec7c4d315ff274ce73b5.tar.xz | |
[feature] Add `avif` file support (#4331)
# Description
> If this is a code change, please include a summary of what you've coded, and link to the issue(s) it closes/implements.
>
> If this is a documentation change, please briefly describe what you've changed and why.
This pull request implements support for reading avif images properly.
closes https://codeberg.org/superseriousbusiness/gotosocial/issues/4330
## Checklist
Please put an x inside each checkbox to indicate that you've read and followed it: `[ ]` -> `[x]`
If this is a documentation change, only the first checkbox must be filled (you can delete the others if you want).
- [x] I/we have read the [GoToSocial contribution guidelines](https://codeberg.org/superseriousbusiness/gotosocial/src/branch/main/CONTRIBUTING.md).
- [x] I/we have discussed the proposed changes already, either in an issue on the repository, or in the Matrix chat.
- [x] I/we have not leveraged AI to create the proposed changes.
- [x] I/we have performed a self-review of added code.
- [x] I/we have written code that is legible and maintainable by others.
- [x] I/we have commented the added code, particularly in hard-to-understand areas.
- [x] I/we have made any necessary changes to documentation.
- [x] I/we have added tests that cover new code.
- [x] I/we have run tests and they pass locally with the changes.
- [x] I/we have run `go fmt ./...` and `golangci-lint run`.
Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4331
Co-authored-by: tobi <tobi.smethurst@protonmail.com>
Co-committed-by: tobi <tobi.smethurst@protonmail.com>
Diffstat (limited to 'internal/media/manager_test.go')
| -rw-r--r-- | internal/media/manager_test.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/internal/media/manager_test.go b/internal/media/manager_test.go index 6182babbb..f6914acf0 100644 --- a/internal/media/manager_test.go +++ b/internal/media/manager_test.go @@ -789,6 +789,62 @@ func (suite *ManagerTestSuite) TestPngAlphaChannelProcess() { equalFiles(suite.T(), suite.state.Storage, dbAttachment.Thumbnail.Path, "./test/test-png-alphachannel-thumbnail.jpeg") } +func (suite *ManagerTestSuite) TestAvifProcess() { + ctx := suite.T().Context() + + data := func(_ context.Context) (io.ReadCloser, error) { + // load bytes from a test image + b, err := os.ReadFile("./test/gotosocial.avif") + if err != nil { + panic(err) + } + return io.NopCloser(bytes.NewBuffer(b)), nil + } + + accountID := "01FS1X72SK9ZPW0J1QQ68BD264" + + // process the media with no additional info provided + processing, err := suite.manager.CreateMedia(ctx, + accountID, + data, + media.AdditionalMediaInfo{}, + ) + suite.NoError(err) + suite.NotNil(processing) + + // do a blocking call to fetch the attachment + attachment, err := processing.Load(ctx) + suite.NoError(err) + suite.NotNil(attachment) + + // make sure it's got the stuff set on it that we expect + // the attachment ID and accountID we expect + suite.Equal(processing.ID(), attachment.ID) + suite.Equal(accountID, attachment.AccountID) + + // file meta should be correctly derived from the image + suite.EqualValues(gtsmodel.Original{ + Width: 1038, Height: 980, Size: 1017240, Aspect: 1.0591837, + }, attachment.FileMeta.Original) + suite.EqualValues(gtsmodel.Small{ + Width: 512, Height: 483, Size: 247296, Aspect: 1.0591837, + }, attachment.FileMeta.Small) + suite.Equal("image/avif", attachment.File.ContentType) + suite.Equal("image/webp", attachment.Thumbnail.ContentType) + suite.Equal(3815, attachment.File.FileSize) + suite.Equal(4198, attachment.Thumbnail.FileSize) + suite.Equal("LNQJQ7%M?w-;-pj[bbj[?^ofDiWB", attachment.Blurhash) + + // now make sure the attachment is in the database + dbAttachment, err := suite.db.GetAttachmentByID(ctx, attachment.ID) + suite.NoError(err) + suite.NotNil(dbAttachment) + + // ensure the files contain the expected data. + equalFiles(suite.T(), suite.state.Storage, dbAttachment.File.Path, "./test/gotosocial-processed.avif") + equalFiles(suite.T(), suite.state.Storage, dbAttachment.Thumbnail.Path, "./test/gotosocial-thumbnail.webp") +} + func (suite *ManagerTestSuite) TestSimpleJpegProcessWithCallback() { ctx := suite.T().Context() |
