"go.stargrave.org/tofuproxy/fifos"
)
-const CmdDJXL = "djxl"
-
-func RoundTranscodeJXL(
- host string,
+func transcodeCmd2Png(
+ contentType, ext, cmdName string,
resp *http.Response,
w http.ResponseWriter,
req *http.Request,
) (bool, error) {
- if resp.Header.Get("Content-Type") != "image/jxl" {
+ if resp.Header.Get("Content-Type") != contentType {
return true, nil
}
- tmpFd, err := ioutil.TempFile("", "tofuproxy.*.jxl")
+ tmpFd, err := ioutil.TempFile("", "tofuproxy.*."+ext)
if err != nil {
log.Fatalln(err)
}
}
tmpFd.Close()
dstFn := tmpFd.Name() + ".png"
- cmd := exec.Command(CmdDJXL, tmpFd.Name(), dstFn)
+ cmd := exec.Command(cmdName, tmpFd.Name(), dstFn)
err = cmd.Run()
defer os.Remove(dstFn)
if err != nil {
w.WriteHeader(http.StatusOK)
w.Write(data)
fifos.SinkOther <- fmt.Sprintf(
- "%s %s\t%d\tJPEG XL transcoded to PNG",
+ "%s %s\t%d\t%s transcoded to PNG",
req.Method,
req.URL.String(),
http.StatusOK,
+ contentType,
)
return false, nil
}
+
+func RoundTranscodeJXL(
+ host string,
+ resp *http.Response,
+ w http.ResponseWriter,
+ req *http.Request,
+) (bool, error) {
+ return transcodeCmd2Png("image/jxl", "jxl", "djxl", resp, w, req)
+}