]> Sergey Matveev's repositories - tofuproxy.git/blobdiff - rounds/45transcodeJXL.go
AVIF transcoding
[tofuproxy.git] / rounds / 45transcodeJXL.go
index 2d748fa4854ff5202f0276b43b6085fd10d12181..2043fb189154a4e851fa8318faf8fa82dd9a9f1d 100644 (file)
@@ -29,18 +29,16 @@ import (
        "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)
        }
@@ -53,7 +51,7 @@ func RoundTranscodeJXL(
        }
        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 {
@@ -67,10 +65,20 @@ func RoundTranscodeJXL(
        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)
+}