From bc7d30183409529082d200856412ed139811cd3d Mon Sep 17 00:00:00 2001 From: Code by Ben Date: Mon, 30 Sep 2024 12:28:13 +1000 Subject: [PATCH] RecordReadmeCopier now generates a thumbnail automatically if no existing thumbs exist. --- handler/htmx/artifact.go | 8 ++++++-- handler/routerlock.go | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/handler/htmx/artifact.go b/handler/htmx/artifact.go index e084ecd3..3ddfa154 100644 --- a/handler/htmx/artifact.go +++ b/handler/htmx/artifact.go @@ -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 { @@ -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.`) diff --git a/handler/routerlock.go b/handler/routerlock.go index 43aabc04..357f1bf5 100644 --- a/handler/routerlock.go +++ b/handler/routerlock.go @@ -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 {