M activity.go +31 -6
@@ 1042,10 1042,24 @@ func xonksaver2(user *WhatAbout, item ju
if ua, ok := att.GetArray("url"); ok && len(ua) > 0 {
u, ok = ua[0].(string)
if !ok {
- if uu, ok := ua[0].(junk.Junk); ok {
- u, _ = uu.GetString("href")
- if mt == "" {
- mt, _ = uu.GetString("mediaType")
+ mtprio := -1
+ for _, item := range ua {
+ if uu, ok := item.(junk.Junk); ok {
+ p := 0
+ m, _ := uu.GetString("mediaType")
+ switch m {
+ case "image/jpeg":
+ p = 1
+ case "image/avif":
+ if convertAVIF {
+ p = 2
+ }
+ }
+ if p > mtprio {
+ mtprio = p
+ u, _ = uu.GetString("href")
+ mt = m
+ }
}
}
}
@@ 1408,11 1422,22 @@ func activatedonks(donks []*Donk) []junk
continue
}
jd := junk.New()
- jd["mediaType"] = d.Media
jd["name"] = d.Name
jd["summary"] = html.EscapeString(d.Desc)
jd["type"] = "Document"
- jd["url"] = d.URL
+ if convertAVIF && d.Media == "image/jpeg" {
+ var u [2]junk.Junk
+ u[0] = junk.New()
+ u[0]["mediaType"] = "image/jpeg"
+ u[0]["href"] = d.URL
+ u[1] = junk.New()
+ u[1]["mediaType"] = "image/avif"
+ u[1]["href"] = d.URL + ".avif"
+ jd["url"] = u
+ } else {
+ jd["mediaType"] = d.Media
+ jd["url"] = d.URL
+ }
atts = append(atts, jd)
}
return atts
M docs/changelog.txt +1 -1
@@ 2,7 2,7 @@ changelog
### next
-+ AVIF transcoding. wip.
++ AVIF image support. Optional with config option convertavif.
### 1.4.2 Kindred Key
M docs/honk.8 +2 -0
@@ 260,6 260,8 @@ Custom URL seperators (not "u" and "h")
e.g. example.com/users/username/honk/somehonk instead of
example.com/u/username/h/somehonk.
.Bl -tag -width collectforwards
+.It convertavif
+Support AVIF images if libavif can be found.
.It fasttimeout
Short timeout for fetching activities.
(Default: 5)
M filestoragemanagerfactory.go +10 -1
@@ 203,7 203,9 @@ func loaddata(xid string) ([]byte, func(
}
func servefiledata(w http.ResponseWriter, r *http.Request, xid string) {
- if strings.HasSuffix(xid, ".avif") {
+ wantAVIF := false
+ if convertAVIF && strings.HasSuffix(xid, ".avif") {
+ wantAVIF = true
xid = xid[:len(xid)-5]
}
var media string
@@ 228,6 230,13 @@ func servefiledata(w http.ResponseWriter
data = img.Data
}
}
+ if wantAVIF {
+ d2 := avifEncode(data)
+ if d2 != nil {
+ data = d2
+ media = "image/avif"
+ }
+ }
w.Header().Set("Content-Type", media)
w.Header().Set("X-Content-Type-Options", "nosniff")
w.Header().Set("Cache-Control", "max-age="+somedays())
M go.mod +1 -1
@@ 11,7 11,7 @@ require (
humungus.tedunangst.com/r/go-sqlite3 v1.2.1
humungus.tedunangst.com/r/gonix v0.1.4
humungus.tedunangst.com/r/termvc v0.1.3
- humungus.tedunangst.com/r/webs v0.7.23
+ humungus.tedunangst.com/r/webs v0.7.24
)
require (
M go.sum +2 -2
@@ 80,5 80,5 @@ humungus.tedunangst.com/r/gonix v0.1.4 h
humungus.tedunangst.com/r/gonix v0.1.4/go.mod h1:VFBc2bPDXr1ayHOmHUutxYu8fSM+pkwK8o36h4rkORg=
humungus.tedunangst.com/r/termvc v0.1.3 h1:BYxcqdA2Ijhqolf2BdNlGw5355qE80EzAqiNgi7d5tk=
humungus.tedunangst.com/r/termvc v0.1.3/go.mod h1:TnlG9PbH77OpEf46iDyb/H9drjegQNwhpXalmGGrbhU=
-humungus.tedunangst.com/r/webs v0.7.23 h1:LEamoWvtgBOukGuzHj/T1qhRwNQkoz2RMCiwvvxwIug=
-humungus.tedunangst.com/r/webs v0.7.23/go.mod h1:ylhqHSPI0Oi7b4nsnx5mSO7AjLXN7wFpEHayLfN/ugk=
+humungus.tedunangst.com/r/webs v0.7.24 h1:zZCMN8ZnmKQB+aALM4EFiSuJHJfRBJ3SCKOs2LuNfa8=
+humungus.tedunangst.com/r/webs v0.7.24/go.mod h1:ylhqHSPI0Oi7b4nsnx5mSO7AjLXN7wFpEHayLfN/ugk=
M main.go +6 -4
@@ 57,13 57,10 @@ func serverURL(u string, args ...interfa
}
func ElaborateUnitTests() {
- data, _ := os.ReadFile("input.jpg")
- d2 := avifEncode(data)
- os.WriteFile("output.avif", d2, 0600)
}
func avifEncode(data []byte) []byte {
- return lazif.Encode(data)
+ return lazif.EncodeJPEG(data)
}
func unplugserver(hostname string) {
@@ 187,6 184,11 @@ func main() {
honkwindow *= 24 * time.Hour
getconfig("collectforwards", &collectForwards)
getconfig("convertavif", &convertAVIF)
+ if convertAVIF {
+ if !lazif.Load() {
+ elog.Printf("libavif could not be loaded")
+ }
+ }
prepareStatements(db)