Skip to content

Commit

Permalink
RecordReadmeCopier now generates a thumbnail automatically if no exis…
Browse files Browse the repository at this point in the history
…ting thumbs exist.
  • Loading branch information
bengarrett committed Sep 30, 2024
1 parent 3ebf353 commit bc7d301
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions handler/htmx/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func RecordReadmeImager(c echo.Context, logger *zap.SugaredLogger, amigaFont boo
`Text filed imaged, the browser will refresh.`)
}

func RecordReadmeCopier(c echo.Context, extraDir string) error {
func RecordReadmeCopier(c echo.Context, dirs command.Dirs) error {
path := c.Param("path")
name, err := url.QueryUnescape(path)
if err != nil {
Expand All @@ -151,10 +151,14 @@ func RecordReadmeCopier(c echo.Context, extraDir string) error {
if st.Size() == 0 {
return c.String(http.StatusOK, "The file is empty and was not copied.")
}
dst := filepath.Join(extraDir, unid+".txt")
dst := filepath.Join(dirs.Extra, unid+".txt")
if _, err = helper.DuplicateOW(src, dst); err != nil {
return badRequest(c, err)
}
if !helper.File(filepath.Join(dirs.Thumbnail, unid+".png")) &&
!helper.File(filepath.Join(dirs.Thumbnail, unid+".webp")) {
return RecordReadmeImager(c, nil, false, dirs)
}
c = pageRefresh(c)
return c.String(http.StatusOK,
`Images copied, the browser will refresh.`)
Expand Down
2 changes: 1 addition & 1 deletion handler/routerlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func editor(g *echo.Group, db *sql.DB, logger *zap.SugaredLogger, dir app.Dirs)
}
readme := g.Group("/readme")
readme.PATCH("/copy/:unid/:path", func(c echo.Context) error {
return htmx.RecordReadmeCopier(c, dir.Extra)
return htmx.RecordReadmeCopier(c, dirs)
})
// /editor/readme/preview
readme.PATCH("/preview/:unid/:path", func(c echo.Context) error {
Expand Down

0 comments on commit bc7d301

Please sign in to comment.