Skip to content

Commit

Permalink
fix: show import file (#1998)
Browse files Browse the repository at this point in the history
Signed-off-by: 张启航 <[email protected]>
  • Loading branch information
ZhangSetSail authored Nov 10, 2024
1 parent dfa5e1f commit 9d1bf20
Showing 1 changed file with 7 additions and 23 deletions.
30 changes: 7 additions & 23 deletions api/controller/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"net/http"
"os"
"os/exec"
"path/filepath"
"strings"

"github.com/go-chi/chi"
Expand Down Expand Up @@ -99,34 +98,19 @@ func (a *AppStruct) ImportID(w http.ResponseWriter, r *http.Request) {

httputil.ReturnSuccess(r, w, map[string]string{"path": dirName})
case "GET":
_, err := os.Stat(dirName)

err := storage.Default().StorageCli.MkdirAll(dirName)
if err != nil {
if !os.IsExist(err) {
err := os.MkdirAll(dirName, 0755)
if err != nil {
httputil.ReturnError(r, w, 502, "Failed to create directory by event id: "+err.Error())
return
}
}
httputil.ReturnError(r, w, 502, "Failed to create directory by event id: "+err.Error())
return
}
apps, err := ioutil.ReadDir(dirName)
appArr, err := storage.Default().StorageCli.ReadDir(dirName)
if err != nil {
httputil.ReturnSuccess(r, w, map[string][]string{"apps": {}})
logrus.Errorf("read dir failure")
httputil.ReturnSuccess(r, w, map[string][]string{"packages": {}})
return
}

appArr := make([]string, 0, 10)
for _, dir := range apps {
if dir.IsDir() {
continue
}
ex := filepath.Ext(dir.Name())
if ex != ".zip" && ex != ".tar.gz" && ex != ".gz" && ex != ".tgz" {
continue
}
appArr = append(appArr, dir.Name())
}

httputil.ReturnSuccess(r, w, map[string][]string{"apps": appArr})
case "DELETE":
cmd := exec.Command("rm", "-rf", dirName)
Expand Down

0 comments on commit 9d1bf20

Please sign in to comment.