Skip to content

Commit

Permalink
fix(infojson): allow fetching revisions
Browse files Browse the repository at this point in the history
Improved error message if keyboard isnt found and allow the use of revisions. (e.g. lily58/rev1).
Closes #11
  • Loading branch information
MrMarble committed Jan 29, 2023
1 parent ee0ea79 commit cfd0924
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 4 additions & 3 deletions cmd/zmk-viewer/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Cmd struct {
}

func (g *Cmd) Run() error {
return generate(strings.ReplaceAll(g.KeyboardName, "/", "_"), g.LayoutFile, g.Output, g.File, g.Transparent, g.Raw, g.Single, g.Unified)
return generate(g.KeyboardName, g.LayoutFile, g.Output, g.File, g.Transparent, g.Raw, g.Single, g.Unified)
}

func generate(keyboardName, layoutFile, output, keymapFile string, isTransparent, isRaw, single, unified bool) error {
Expand Down Expand Up @@ -89,15 +89,16 @@ func generate(keyboardName, layoutFile, output, keymapFile string, isTransparent
}

for path, image := range images {
f, err := os.Create(filepath.Join(output, path))
sanitized := strings.ReplaceAll(path, "/", "_")
f, err := os.Create(filepath.Join(output, sanitized))
if err != nil {
return err
}
defer f.Close()
if err = png.Encode(f, image); err != nil {
return nil
}
log.Info().Str("Path", path).Msg("Image saved")
log.Info().Str("Path", sanitized).Msg("Image saved")
}

return nil
Expand Down
3 changes: 3 additions & 0 deletions pkg/infojson/infojson.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ func fetch(url string) (*file, error) {
log.Debug().Str("url", url).Send()

resp, err := http.Get(url) //nolint:gosec
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("could not fetch keyboard layout: %v", resp.Status)
}
if err != nil {
return nil, err
}
Expand Down

0 comments on commit cfd0924

Please sign in to comment.