This commit is contained in:
a 2024-08-05 22:43:54 -05:00
parent 1e90b34fe2
commit 6c3b24ecaa
Signed by: a
GPG Key ID: 374BC539FE795AF0
1 changed files with 11 additions and 6 deletions

View File

@ -48,7 +48,11 @@ func main() {
printIf("could not find file %s\n", filename) printIf("could not find file %s\n", filename)
return return
} }
dump(filename, output) err := dump(filename, output)
if err != nil {
fmt.Println(err)
return
}
return return
} }
flag.PrintDefaults() flag.PrintDefaults()
@ -60,25 +64,26 @@ func printIf(s string, args ...interface{}) {
} }
} }
func dump(filename string, output string) { func dump(filename string, output string) error {
start := time.Now() start := time.Now()
printIf("reading file '%s'\n", filename) printIf("reading file '%s'\n", filename)
n, err := nori.FromFile(filename) n, err := nori.FromFile(filename)
if err != nil { if err != nil {
log.Panicf("decode: %s", err) return fmt.Errorf("decode: %w", err)
} }
out := new(bytes.Buffer) out := new(bytes.Buffer)
printIf("rendering %d animation(s)\n", n.AnimationCount) printIf("rendering %d animation(s)\n", n.AnimationCount)
animations, err := renderer.RenderAnimationsApng(n) animations, err := renderer.RenderAnimationsApng(n)
if err != nil { if err != nil {
log.Panicf("animation: %s\n", err) return fmt.Errorf("animation: %w", err)
} }
printIf("saving to %s \n", output) printIf("saving to %s \n", output)
if err := utils.ZipApngs(out, animations); err != nil { if err := utils.ZipApngs(out, animations); err != nil {
log.Panicf("zipping: %s\n", err) return fmt.Errorf("zipping: %w", err)
} }
printIf("done in %v \n", time.Now().Sub(start)) printIf("done in %v \n", time.Now().Sub(start))
os.WriteFile(output, out.Bytes(), 0740) os.WriteFile(output, out.Bytes(), 0740)
return nil
} }
func serve() { func serve() {
@ -92,7 +97,7 @@ func serve() {
r.Use(middleware.Timeout(60 * time.Second)) r.Use(middleware.Timeout(60 * time.Second))
r.Post("/animations", func(w http.ResponseWriter, r *http.Request) { r.Post("/animations", func(w http.ResponseWriter, r *http.Request) {
output_type := chi.URLParam(r, "format") output_type := r.URL.Query().Get("format")
switch output_type { switch output_type {
case "": case "":
output_type = "apng" output_type = "apng"