This commit is contained in:
w-mj 2023-03-13 21:42:33 +08:00
parent 4d282304d7
commit 9b0e21775a
No known key found for this signature in database
GPG Key ID: 3A2CB5BE2F835897
2 changed files with 13 additions and 4 deletions

View File

@ -1,4 +1,4 @@
TAG ?= v1.1.12
TAG ?= v1.1.13
IMAGE_TAG ?= docker.educg.net/cg/k8s-manager:$(TAG)
build: export CGO_ENABLED=0

View File

@ -16,10 +16,12 @@ func GetFiles(c *gin.Context) {
dirPath := path.Join(config.NFSPath, username, appName)
dir, err := os.ReadDir(dirPath)
if err != nil {
if !os.IsNotExist(err) {
log.WithError(err).Error("Cannot ReadDir ", dirPath)
c.JSON(http.StatusBadRequest, gin.H{"ok": false, "msg": err})
return
}
}
c.JSON(http.StatusOK, gin.H{"ok": true, "files": funk.Map(dir, func(d fs.DirEntry) string { return d.Name() }).([]string)})
}
@ -27,6 +29,7 @@ func GetPostOrDeleteFile(c *gin.Context) {
username := c.MustGet("username").(string)
appName := c.Param("app")
fileName := c.Param("filename")
dirPath := path.Join(config.NFSPath, username, appName)
filePath := path.Join(config.NFSPath, username, appName, fileName)
if c.Request.Method == http.MethodGet {
c.FileAttachment(filePath, fileName)
@ -37,6 +40,12 @@ func GetPostOrDeleteFile(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"ok": false, "msg": err})
return
}
if _, err := os.Stat(dirPath); os.IsNotExist(err) {
err := os.MkdirAll(dirPath, 0777)
if err != nil {
log.WithError(err).Error("GetPostOrDeleteFile: Make nfs dir error")
}
}
err = c.SaveUploadedFile(file, filePath)
if err != nil {
log.WithError(err).Error("GetPostOrDeleteFile: Save file error")