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)
return
}
dump(filename, output)
err := dump(filename, output)
if err != nil {
fmt.Println(err)
return
}
return
}
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()
printIf("reading file '%s'\n", filename)
n, err := nori.FromFile(filename)
if err != nil {
log.Panicf("decode: %s", err)
return fmt.Errorf("decode: %w", err)
}
out := new(bytes.Buffer)
printIf("rendering %d animation(s)\n", n.AnimationCount)
animations, err := renderer.RenderAnimationsApng(n)
if err != nil {
log.Panicf("animation: %s\n", err)
return fmt.Errorf("animation: %w", err)
}
printIf("saving to %s \n", output)
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))
os.WriteFile(output, out.Bytes(), 0740)
return nil
}
func serve() {
@ -92,7 +97,7 @@ func serve() {
r.Use(middleware.Timeout(60 * time.Second))
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 {
case "":
output_type = "apng"