all repos — honk @ 89b6a314476a7a18ecdfc580477c605db6ab5fa0

my fork of honk

preview images
Ted Unangst tedu@tedunangst.com
Thu, 25 Jan 2024 22:18:37 -0500
commit

89b6a314476a7a18ecdfc580477c605db6ab5fa0

parent

2718526d6166cdb7faea728c3540fb5021a7498c

2 files changed, 16 insertions(+), 0 deletions(-)

jump to
M backend.gobackend.go

@@ -118,6 +118,15 @@ }

return res.Image, nil } +func lilshrink(data []byte) (*image.Image, error) { + params := image.Params{ + LimitSize: 14200 * 4200, + MaxWidth: 256, + MaxHeight: 256, + MaxSize: 16 * 1024, + } + return callshrink(data, params) +} func bigshrink(data []byte) (*image.Image, error) { params := image.Params{ LimitSize: 14200 * 4200,
M web.goweb.go

@@ -2393,6 +2393,7 @@ }

func servefile(w http.ResponseWriter, r *http.Request) { xid := mux.Vars(r)["xid"] + preview := r.FormValue("preview") == "1" var media string var data []byte row := stmtGetFileData.QueryRow(xid)

@@ -2401,6 +2402,12 @@ if err != nil {

elog.Printf("error loading file: %s", err) http.NotFound(w, r) return + } + if preview && strings.HasPrefix(media, "image") { + img, err := lilshrink(data) + if err == nil { + data = img.Data + } } w.Header().Set("Content-Type", media) w.Header().Set("X-Content-Type-Options", "nosniff")