From 0253c7ef253ce6e640bb213e7614c94f16aa1fca Mon Sep 17 00:00:00 2001 From: Laurent Evrard Date: Fri, 5 Dec 2025 06:47:51 +0100 Subject: [PATCH] Allow to remove files --- main.go | 11 +++++++---- views/templates/index.html | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index dde5e7e..2c7cabd 100644 --- a/main.go +++ b/main.go @@ -29,10 +29,6 @@ func (t *Template) Render(w io.Writer, name string, data interface{}, c echo.Con } func upload(c echo.Context) error { - //----------- - // Read file - //----------- - // Source file, err := c.FormFile("file") if err != nil { @@ -95,6 +91,12 @@ func index(c echo.Context) error { return c.Render(http.StatusOK, "index", map[string][]File{"Files": files}) } +func remove(c echo.Context) error { + filename := c.FormValue("Filename") + os.Remove(filepath.Join(DATA_DIR, filename)) + return c.Redirect(http.StatusTemporaryRedirect, "/admin") +} + func main() { t := &Template{ templates: template.Must(template.ParseGlob("views/templates/*.html")), @@ -110,6 +112,7 @@ func main() { e.Static("/assets", "assets") e.GET("/admin", index) e.POST("/admin/upload", upload) + e.GET("/admin/remove", remove) e.Logger.Fatal(e.Start(":1323")) } diff --git a/views/templates/index.html b/views/templates/index.html index fb01471..17279c9 100644 --- a/views/templates/index.html +++ b/views/templates/index.html @@ -11,7 +11,7 @@
-

Upload de fichiers

+

Hébergement de fichiers

Enfin une solution simple que vous gérez vous même

@@ -31,7 +31,7 @@
- +
@@ -54,7 +54,16 @@ {{ .Filename }} {{ .URL }} - + +
+ +
+
+ +
+
+
+ {{ end }}