reorg test code into build structure

This commit is contained in:
2023-02-16 14:22:46 +01:00
parent 4f547ac906
commit a7cbd93f5e
10 changed files with 899 additions and 0 deletions

View File

@@ -21,6 +21,7 @@ import (
"archive/zip"
"fmt"
"github.com/gin-gonic/gin"
//"github.com/gin-gonic/gin/binding"
"github.com/google/uuid"
"github.com/tlinden/up/upd/cfg"
"io"
@@ -53,6 +54,11 @@ func NormalizeFilename(file string) string {
return Ts() + r.ReplaceAllString(file, "")
}
// Binding from JSON
type Meta struct {
Expire string `form:"expire"`
}
func Runserver(cfg *cfg.Config, args []string) error {
dst := cfg.StorageDir
router := gin.Default()
@@ -78,6 +84,12 @@ func Runserver(cfg *cfg.Config, args []string) error {
os.MkdirAll(filepath.Join(dst, id), os.ModePerm)
var formdata Meta
if err := c.ShouldBind(&formdata); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
form, _ := c.MultipartForm()
files := form.File["upload[]"]
uploaded := []string{}
@@ -137,6 +149,7 @@ func Runserver(cfg *cfg.Config, args []string) error {
})
Log("Now serving %s from %s/%s", returnUrl, dst, id)
Log("Expire set to: %s", formdata.Expire)
})
api.GET("/getfile/:id/:file", func(c *gin.Context) {