preview images
Ted Unangst tedu@tedunangst.com
Thu, 25 Jan 2024 22:18:37 -0500
2 files changed,
16 insertions(+),
0 deletions(-)
M
backend.go
→
backend.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.go
→
web.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")