Skip to content

Commit

Permalink
UploadReplacement removes the repack file.
Browse files Browse the repository at this point in the history
  • Loading branch information
bengarrett committed Sep 22, 2024
1 parent 56c09c1 commit 1505d5f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions handler/htmx/htmx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 3 additions & 1 deletion handler/htmx/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion handler/routerlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1505d5f

Please sign in to comment.