loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request 'feat: Make AVIF Images work with Forgejo' (#5940) from JakobDev/forgejo:avif into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/5940
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Reviewed-by: Otto <otto@codeberg.org>

Gusted b86f6cae 9e95f80d

+23 -5
+3 -3
custom/conf/app.example.ini
··· 1938 1938 ;ENABLED = true 1939 1939 ;; 1940 1940 ;; Comma-separated list of allowed file extensions (`.zip`), mime types (`text/plain`) or wildcard type (`image/*`, `audio/*`, `video/*`). Empty value or `*/*` allows all types. 1941 - ;ALLOWED_TYPES = .cpuprofile,.csv,.dmp,.docx,.fodg,.fodp,.fods,.fodt,.gif,.gz,.jpeg,.jpg,.json,.jsonc,.log,.md,.mov,.mp4,.odf,.odg,.odp,.ods,.odt,.patch,.pdf,.png,.pptx,.svg,.tgz,.txt,.webm,.xls,.xlsx,.zip 1941 + ;ALLOWED_TYPES = .avif,.cpuprofile,.csv,.dmp,.docx,.fodg,.fodp,.fods,.fodt,.gif,.gz,.jpeg,.jpg,.json,.jsonc,.log,.md,.mov,.mp4,.odf,.odg,.odp,.ods,.odt,.patch,.pdf,.png,.pptx,.svg,.tgz,.txt,.webm,.xls,.xlsx,.zip 1942 1942 ;; 1943 1943 ;; Max size of each file. Defaults to 2048MB 1944 1944 ;MAX_SIZE = 2048 ··· 1976 1976 ;; Url lookup for the minio bucket only available when STORAGE_TYPE is `minio` 1977 1977 ;; Available values: auto, dns, path 1978 1978 ;; If empty, it behaves the same as "auto" was set 1979 - ;MINIO_BUCKET_LOOKUP = 1979 + ;MINIO_BUCKET_LOOKUP = 1980 1980 ;; 1981 1981 ;; Minio location to create bucket only available when STORAGE_TYPE is `minio` 1982 1982 ;MINIO_LOCATION = us-east-1 ··· 2703 2703 ;; Url lookup for the minio bucket only available when STORAGE_TYPE is `minio` 2704 2704 ;; Available values: auto, dns, path 2705 2705 ;; If empty, it behaves the same as "auto" was set 2706 - ;MINIO_BUCKET_LOOKUP = 2706 + ;MINIO_BUCKET_LOOKUP = 2707 2707 ;; 2708 2708 ;; Minio location to create bucket only available when STORAGE_TYPE is `minio` 2709 2709 ;MINIO_LOCATION = us-east-1
+2 -2
modules/setting/attachment.go
··· 12 12 Enabled bool 13 13 }{ 14 14 Storage: &Storage{}, 15 - AllowedTypes: ".cpuprofile,.csv,.dmp,.docx,.fodg,.fodp,.fods,.fodt,.gif,.gz,.jpeg,.jpg,.json,.jsonc,.log,.md,.mov,.mp4,.odf,.odg,.odp,.ods,.odt,.patch,.pdf,.png,.pptx,.svg,.tgz,.txt,.webm,.webp,.xls,.xlsx,.zip", 15 + AllowedTypes: ".avif,.cpuprofile,.csv,.dmp,.docx,.fodg,.fodp,.fods,.fodt,.gif,.gz,.jpeg,.jpg,.json,.jsonc,.log,.md,.mov,.mp4,.odf,.odg,.odp,.ods,.odt,.patch,.pdf,.png,.pptx,.svg,.tgz,.txt,.webm,.webp,.xls,.xlsx,.zip", 16 16 MaxSize: 2048, 17 17 MaxFiles: 5, 18 18 Enabled: true, ··· 25 25 return err 26 26 } 27 27 28 - Attachment.AllowedTypes = sec.Key("ALLOWED_TYPES").MustString(".cpuprofile,.csv,.dmp,.docx,.fodg,.fodp,.fods,.fodt,.gif,.gz,.jpeg,.jpg,.json,.jsonc,.log,.md,.mov,.mp4,.odf,.odg,.odp,.ods,.odt,.patch,.pdf,.png,.pptx,.svg,.tgz,.txt,.webm,.webp,.xls,.xlsx,.zip") 28 + Attachment.AllowedTypes = sec.Key("ALLOWED_TYPES").MustString(".avif,.cpuprofile,.csv,.dmp,.docx,.fodg,.fodp,.fods,.fodt,.gif,.gz,.jpeg,.jpg,.json,.jsonc,.log,.md,.mov,.mp4,.odf,.odg,.odp,.ods,.odt,.patch,.pdf,.png,.pptx,.svg,.tgz,.txt,.webm,.webp,.xls,.xlsx,.zip") 29 29 Attachment.MaxSize = sec.Key("MAX_SIZE").MustInt64(2048) 30 30 Attachment.MaxFiles = sec.Key("MAX_FILES").MustInt(5) 31 31 Attachment.Enabled = sec.Key("ENABLED").MustBool(true)
+8
modules/typesniffer/typesniffer.go
··· 20 20 const ( 21 21 // SvgMimeType MIME type of SVG images. 22 22 SvgMimeType = "image/svg+xml" 23 + // AvifMimeType MIME type of AVIF images 24 + AvifMimeType = "image/avif" 23 25 // ApplicationOctetStream MIME type of binary files. 24 26 ApplicationOctetStream = "application/octet-stream" 25 27 ) ··· 104 106 detectByXML && svgTagInXMLRegex.Match(dataProcessed) { 105 107 ct = SvgMimeType 106 108 } 109 + } 110 + 111 + // AVIF is unsuported by http.DetectContentType 112 + // Signature taken from https://stackoverflow.com/a/68322450 113 + if bytes.Index(data, []byte("ftypavif")) == 4 { 114 + ct = AvifMimeType 107 115 } 108 116 109 117 if strings.HasPrefix(ct, "audio/") && bytes.HasPrefix(data, []byte("ID3")) {
+10
modules/typesniffer/typesniffer_test.go
··· 135 135 require.NoError(t, err) 136 136 assert.True(t, st.IsVideo()) 137 137 } 138 + 139 + func TestDetectContentTypeAvif(t *testing.T) { 140 + avifImage, err := hex.DecodeString("000000206674797061766966") 141 + require.NoError(t, err) 142 + 143 + st, err := DetectContentTypeFromReader(bytes.NewReader(avifImage)) 144 + require.NoError(t, err) 145 + 146 + assert.True(t, st.IsImage()) 147 + }