From 1505d5f3abd26ba6165385c85ca614f101a199ef Mon Sep 17 00:00:00 2001 From: Code by Ben Date: Sun, 22 Sep 2024 14:21:25 +1000 Subject: [PATCH] UploadReplacement removes the repack file. --- handler/htmx/htmx_test.go | 4 ++-- handler/htmx/transfer.go | 4 +++- handler/routerlock.go | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/handler/htmx/htmx_test.go b/handler/htmx/htmx_test.go index 14e43ff2..179ea567 100644 --- a/handler/htmx/htmx_test.go +++ b/handler/htmx/htmx_test.go @@ -169,10 +169,10 @@ func TestUploadPreview(t *testing.T) { func TestUploadReplacement(t *testing.T) { t.Parallel() - err := htmx.UploadReplacement(newContext(), nil, "") + err := htmx.UploadReplacement(newContext(), nil, "", "") require.NoError(t, err) dir, err := os.Getwd() require.NoError(t, err) - err = htmx.UploadReplacement(newContext(), nil, dir) + err = htmx.UploadReplacement(newContext(), nil, dir, "") require.NoError(t, err) } diff --git a/handler/htmx/transfer.go b/handler/htmx/transfer.go index ba54e814..fdb06019 100644 --- a/handler/htmx/transfer.go +++ b/handler/htmx/transfer.go @@ -607,7 +607,7 @@ func reloader(c echo.Context, filename string) error { // UploadReplacement is the file transfer handler that uploads, validates a new file upload // and updates the existing artifact record with the new file information. // The logger is optional and if nil then the function will not log any debug information. -func UploadReplacement(c echo.Context, db *sql.DB, downloadDir string) error { +func UploadReplacement(c echo.Context, db *sql.DB, downloadDir, extraDir string) error { if db == nil { return c.HTML(http.StatusInternalServerError, "error, the database connection is nil") } @@ -669,6 +669,8 @@ func UploadReplacement(c echo.Context, db *sql.DB, downloadDir string) error { if err := tx.Commit(); err != nil { return c.HTML(http.StatusInternalServerError, "The database commit failed") } + repack := filepath.Join(extraDir, up.unid+".zip") + defer os.Remove(repack) if mkc, err := helper.MkContent(abs); err == nil { defer os.RemoveAll(mkc) } diff --git a/handler/routerlock.go b/handler/routerlock.go index 2c13fd0f..43aabc04 100644 --- a/handler/routerlock.go +++ b/handler/routerlock.go @@ -204,7 +204,7 @@ func editor(g *echo.Group, db *sql.DB, logger *zap.SugaredLogger, dir app.Dirs) upload := g.Group("/upload") // /upload/file upload.POST("/file", func(c echo.Context) error { - return htmx.UploadReplacement(c, db, dir.Download) + return htmx.UploadReplacement(c, db, dir.Download, dir.Extra) }) // /upload/preview upload.POST("/preview", func(c echo.Context) error {