Monorepo for Tangled tangled.org

appview,knotserver,camo: add AVIF and modern image format support #1117

open opened by overby.me targeting master from overby.me/core: feat/avif-support

Add support for AVIF, JPEG XL, and HEIF image formats across the stack. Currently these formats fail at three points in the rendering pipeline:

  1. Knot server returns 403: http.DetectContentType() in Go doesn't recognize AVIF/JXL/HEIF, returning application/octet-stream, which hits the default case and returns HTTP 403.
  2. Camo proxy returns 415: image/avif, image/jxl, and image/heif are missing from the allowed MIME types list in mimetypes.json.
  3. Blob viewer doesn't render as image: .avif, .jxl, .heic, .heif are missing from the image extension switch in NewBlobView.

Changes#

  • knotserver/xrpc/repo_blob.go: Replace the single if for .svg with a switch that also overrides MIME types for .avif, .jxl, .heic, .heif
  • camo/src/mimetypes.json: Add image/avif, image/heif, image/jxl to the allowed MIME types list
  • appview/repo/blob.go: Add .avif, .jxl, .heic, .heif to the image extension case in the blob viewer

Reproduction#

Any repo with .avif images in its README, e.g. https://tangled.org/@overby.me/overby-me

AVIF has 97%+ browser support and is increasingly common as a modern replacement for JPEG/PNG/WebP.

Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:eukcx4amfqmhfrnkix7zwm34/sh.tangled.repo.pull/3mgfgepvxfr22
+13 -2
Diff #0
+1 -1
appview/repo/blob.go
··· 236 236 ext := strings.ToLower(filepath.Ext(resp.Path)) 237 237 238 238 switch ext { 239 - case ".jpg", ".jpeg", ".png", ".gif", ".webp": 239 + case ".jpg", ".jpeg", ".png", ".gif", ".webp", ".avif", ".jxl", ".heic", ".heif": 240 240 view.ContentType = models.BlobContentTypeImage 241 241 view.HasRawView = true 242 242 view.HasRenderedView = true
+3
camo/src/mimetypes.json
··· 1 1 [ 2 + "image/avif", 2 3 "image/bmp", 3 4 "image/cgm", 4 5 "image/g3fax", 5 6 "image/gif", 7 + "image/heif", 6 8 "image/ief", 7 9 "image/jp2", 10 + "image/jxl", 8 11 "image/jpeg", 9 12 "image/jpg", 10 13 "image/pict",
+9 -1
knotserver/xrpc/repo_blob.go
··· 74 74 75 75 mimeType := http.DetectContentType(contents) 76 76 77 - if filepath.Ext(treePath) == ".svg" { 77 + // override MIME types for formats that http.DetectContentType does not recognize 78 + switch filepath.Ext(treePath) { 79 + case ".svg": 78 80 mimeType = "image/svg+xml" 81 + case ".avif": 82 + mimeType = "image/avif" 83 + case ".jxl": 84 + mimeType = "image/jxl" 85 + case ".heic", ".heif": 86 + mimeType = "image/heif" 79 87 } 80 88 81 89 if raw {

History

1 round 0 comments
sign up or login to add to the discussion
overby.me submitted #0
1 commit
expand
appview,knotserver,camo: add AVIF and modern image format support
no conflicts, ready to merge
expand 0 comments