2018-05-10 11:08:49 +08:00
|
|
|
|
package controller
|
|
|
|
|
|
|
|
|
|
import (
|
2018-05-11 23:49:02 +08:00
|
|
|
|
"fmt"
|
2018-05-18 11:02:43 +08:00
|
|
|
|
"io"
|
2018-09-26 22:02:02 +08:00
|
|
|
|
"io/ioutil"
|
2019-04-02 17:37:04 +08:00
|
|
|
|
"net/http"
|
|
|
|
|
"os"
|
2018-09-26 22:02:02 +08:00
|
|
|
|
"path/filepath"
|
2019-04-02 17:37:04 +08:00
|
|
|
|
"strings"
|
2018-09-26 22:02:02 +08:00
|
|
|
|
|
2018-05-23 14:26:27 +08:00
|
|
|
|
"github.com/Sirupsen/logrus"
|
2018-05-18 11:02:43 +08:00
|
|
|
|
"github.com/go-chi/chi"
|
2018-10-15 21:03:39 +08:00
|
|
|
|
"github.com/goodrain/rainbond/api/controller/upload"
|
2018-05-10 11:08:49 +08:00
|
|
|
|
"github.com/goodrain/rainbond/api/handler"
|
|
|
|
|
"github.com/goodrain/rainbond/api/model"
|
2018-05-10 17:45:23 +08:00
|
|
|
|
"github.com/goodrain/rainbond/db"
|
2018-05-18 11:02:43 +08:00
|
|
|
|
httputil "github.com/goodrain/rainbond/util/http"
|
2018-09-27 14:31:52 +08:00
|
|
|
|
"github.com/jinzhu/gorm"
|
2018-05-10 11:08:49 +08:00
|
|
|
|
)
|
|
|
|
|
|
2019-03-08 19:22:22 +08:00
|
|
|
|
//AppStruct -
|
2018-05-10 16:37:55 +08:00
|
|
|
|
type AppStruct struct{}
|
2018-05-10 11:08:49 +08:00
|
|
|
|
|
2019-03-08 19:22:22 +08:00
|
|
|
|
//ExportApp -
|
2018-05-10 11:08:49 +08:00
|
|
|
|
func (a *AppStruct) ExportApp(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
2018-05-18 11:02:43 +08:00
|
|
|
|
switch r.Method {
|
2018-05-14 14:30:32 +08:00
|
|
|
|
case "POST":
|
|
|
|
|
var tr model.ExportAppStruct
|
|
|
|
|
ok := httputil.ValidatorRequestStructAndErrorResponse(r, w, &tr.Body, nil)
|
|
|
|
|
if !ok {
|
|
|
|
|
return
|
|
|
|
|
}
|
2018-05-10 17:45:23 +08:00
|
|
|
|
|
2018-05-14 14:30:32 +08:00
|
|
|
|
if err := handler.GetAppHandler().Complete(&tr); err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-15 15:12:42 +08:00
|
|
|
|
// 要先更新数据库再通知builder组件
|
2018-05-21 18:21:42 +08:00
|
|
|
|
app := model.NewAppStatusFromExport(&tr)
|
2018-05-15 12:26:17 +08:00
|
|
|
|
db.GetManager().AppDao().DeleteModelByEventId(app.EventID)
|
2018-05-14 14:30:32 +08:00
|
|
|
|
if err := db.GetManager().AppDao().AddModel(app); err != nil {
|
2018-05-17 11:27:04 +08:00
|
|
|
|
httputil.ReturnError(r, w, 502, fmt.Sprintf("Failed to export app %s: %v", app.EventID, err))
|
2018-05-14 14:30:32 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-15 15:12:42 +08:00
|
|
|
|
err := handler.GetAppHandler().ExportApp(&tr)
|
|
|
|
|
if err != nil {
|
|
|
|
|
httputil.ReturnError(r, w, 501, fmt.Sprintf("Failed to export app: %v", err))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-14 14:30:32 +08:00
|
|
|
|
httputil.ReturnSuccess(r, w, nil)
|
|
|
|
|
case "GET":
|
2019-03-09 13:51:36 +08:00
|
|
|
|
eventID := strings.TrimSpace(chi.URLParam(r, "eventID"))
|
2019-03-08 19:22:22 +08:00
|
|
|
|
if eventID == "" {
|
2019-03-09 13:51:36 +08:00
|
|
|
|
httputil.ReturnError(r, w, 400, fmt.Sprintf("Arguments eventID is must defined."))
|
2018-05-14 14:30:32 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2018-05-10 11:08:49 +08:00
|
|
|
|
|
2019-03-08 19:22:22 +08:00
|
|
|
|
res, err := db.GetManager().AppDao().GetByEventId(eventID)
|
2018-05-14 14:30:32 +08:00
|
|
|
|
if err != nil {
|
2019-03-08 19:22:22 +08:00
|
|
|
|
httputil.ReturnError(r, w, 404, fmt.Sprintf("Failed to query status of export app by event id %s: %v", eventID, err))
|
2018-05-14 14:30:32 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2018-05-11 23:49:02 +08:00
|
|
|
|
|
2018-05-17 16:10:44 +08:00
|
|
|
|
httputil.ReturnSuccess(r, w, res)
|
2018-05-10 17:45:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-10 11:08:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-09 13:51:36 +08:00
|
|
|
|
//Download -
|
2018-05-15 11:03:03 +08:00
|
|
|
|
func (a *AppStruct) Download(w http.ResponseWriter, r *http.Request) {
|
2018-05-15 11:30:31 +08:00
|
|
|
|
format := strings.TrimSpace(chi.URLParam(r, "format"))
|
|
|
|
|
fileName := strings.TrimSpace(chi.URLParam(r, "fileName"))
|
2018-05-15 11:03:03 +08:00
|
|
|
|
tarFile := fmt.Sprintf("%s/%s/%s", handler.GetAppHandler().GetStaticDir(), format, fileName)
|
|
|
|
|
|
2018-09-27 12:38:25 +08:00
|
|
|
|
// return status code 404 if the file not exists.
|
2018-05-15 12:26:17 +08:00
|
|
|
|
if _, err := os.Stat(tarFile); os.IsNotExist(err) {
|
2018-09-27 12:38:25 +08:00
|
|
|
|
httputil.ReturnError(r, w, 404, fmt.Sprintf("Not found export app tar file: %s", tarFile))
|
2018-05-15 11:03:03 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
http.ServeFile(w, r, tarFile)
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-09 13:51:36 +08:00
|
|
|
|
//ImportID -
|
2018-05-22 12:33:26 +08:00
|
|
|
|
func (a *AppStruct) ImportID(w http.ResponseWriter, r *http.Request) {
|
2019-03-09 13:51:36 +08:00
|
|
|
|
eventID := strings.TrimSpace(chi.URLParam(r, "eventID"))
|
|
|
|
|
if eventID == "" {
|
|
|
|
|
httputil.ReturnError(r, w, 400, "Failed to parse eventID.")
|
2018-05-22 14:01:12 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2019-03-09 13:51:36 +08:00
|
|
|
|
dirName := fmt.Sprintf("%s/import/%s", handler.GetAppHandler().GetStaticDir(), eventID)
|
2018-05-22 14:01:12 +08:00
|
|
|
|
|
2018-05-22 12:33:26 +08:00
|
|
|
|
switch r.Method {
|
|
|
|
|
case "POST":
|
|
|
|
|
err := os.MkdirAll(dirName, 0755)
|
|
|
|
|
if err != nil {
|
2018-09-25 14:42:06 +08:00
|
|
|
|
httputil.ReturnError(r, w, 502, "Failed to create directory by event id: "+err.Error())
|
2018-05-22 12:33:26 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-22 14:26:12 +08:00
|
|
|
|
httputil.ReturnSuccess(r, w, map[string]string{"path": dirName})
|
2018-05-22 12:33:26 +08:00
|
|
|
|
case "GET":
|
2018-09-25 19:14:08 +08:00
|
|
|
|
_, err := os.Stat(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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-22 14:01:12 +08:00
|
|
|
|
apps, err := ioutil.ReadDir(dirName)
|
2018-05-22 12:33:26 +08:00
|
|
|
|
if err != nil {
|
2018-09-25 17:46:31 +08:00
|
|
|
|
httputil.ReturnSuccess(r, w, map[string][]string{"apps": []string{}})
|
2018-05-22 12:33:26 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-22 14:01:12 +08:00
|
|
|
|
appArr := make([]string, 0, 10)
|
|
|
|
|
for _, dir := range apps {
|
|
|
|
|
if dir.IsDir() {
|
2018-05-22 12:33:26 +08:00
|
|
|
|
continue
|
|
|
|
|
}
|
2018-05-23 14:26:27 +08:00
|
|
|
|
ex := filepath.Ext(dir.Name())
|
2018-09-25 17:38:47 +08:00
|
|
|
|
if ex != ".zip" {
|
2018-05-23 14:26:27 +08:00
|
|
|
|
continue
|
|
|
|
|
}
|
2018-05-22 14:01:12 +08:00
|
|
|
|
appArr = append(appArr, dir.Name())
|
2018-05-23 14:26:27 +08:00
|
|
|
|
}
|
2018-05-22 12:33:26 +08:00
|
|
|
|
|
2018-05-22 14:26:12 +08:00
|
|
|
|
httputil.ReturnSuccess(r, w, map[string][]string{"apps": appArr})
|
2018-05-22 12:33:26 +08:00
|
|
|
|
case "DELETE":
|
|
|
|
|
err := os.RemoveAll(dirName)
|
|
|
|
|
if err != nil {
|
2019-03-09 13:51:36 +08:00
|
|
|
|
httputil.ReturnError(r, w, 501, "Failed to delete directory by id: "+eventID)
|
2018-05-22 12:33:26 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2019-03-09 13:51:36 +08:00
|
|
|
|
res, err := db.GetManager().AppDao().GetByEventId(eventID)
|
2018-09-25 21:55:51 +08:00
|
|
|
|
if err != nil {
|
2019-03-09 13:51:36 +08:00
|
|
|
|
httputil.ReturnError(r, w, 404, fmt.Sprintf("Failed to query status of export app by event id %s: %v", eventID, err))
|
2018-09-25 21:55:51 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
res.Status = "cleaned"
|
|
|
|
|
db.GetManager().AppDao().UpdateModel(res)
|
2018-05-22 12:33:26 +08:00
|
|
|
|
|
|
|
|
|
httputil.ReturnSuccess(r, w, "successful")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-09 13:51:36 +08:00
|
|
|
|
//NewUpload -
|
2018-09-26 16:12:28 +08:00
|
|
|
|
func (a *AppStruct) NewUpload(w http.ResponseWriter, r *http.Request) {
|
2019-03-21 19:28:03 +08:00
|
|
|
|
eventID := strings.TrimSpace(chi.URLParam(r, "eventID"))
|
2018-09-26 22:02:02 +08:00
|
|
|
|
switch r.Method {
|
2018-09-26 16:12:28 +08:00
|
|
|
|
case "OPTIONS":
|
|
|
|
|
origin := r.Header.Get("Origin")
|
|
|
|
|
w.Header().Add("Access-Control-Allow-Origin", origin)
|
|
|
|
|
w.Header().Add("Access-Control-Allow-Methods", "POST,OPTIONS")
|
|
|
|
|
w.Header().Add("Access-Control-Allow-Credentials", "true")
|
|
|
|
|
w.Header().Add("Access-Control-Allow-Headers", "x-requested-with,Content-Type,X-Custom-Header")
|
|
|
|
|
httputil.ReturnSuccess(r, w, nil)
|
|
|
|
|
|
|
|
|
|
case "POST":
|
2019-03-09 13:51:36 +08:00
|
|
|
|
if eventID == "" {
|
|
|
|
|
httputil.ReturnError(r, w, 500, "Failed to parse eventID.")
|
2018-09-26 16:12:28 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2019-03-09 13:51:36 +08:00
|
|
|
|
dirName := fmt.Sprintf("%s/import/%s", handler.GetAppHandler().GetStaticDir(), eventID)
|
2018-09-26 16:12:28 +08:00
|
|
|
|
|
2018-09-28 13:09:25 +08:00
|
|
|
|
st := upload.NewStorage(dirName)
|
|
|
|
|
st.UploadHandler(w, r)
|
2018-09-26 16:12:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-09 13:51:36 +08:00
|
|
|
|
//Upload -
|
2018-05-15 11:03:03 +08:00
|
|
|
|
func (a *AppStruct) Upload(w http.ResponseWriter, r *http.Request) {
|
2019-03-21 19:28:03 +08:00
|
|
|
|
eventID := strings.TrimSpace(chi.URLParam(r, "eventID"))
|
2018-09-26 22:02:02 +08:00
|
|
|
|
switch r.Method {
|
2018-09-25 14:42:06 +08:00
|
|
|
|
case "POST":
|
2019-03-09 13:51:36 +08:00
|
|
|
|
if eventID == "" {
|
|
|
|
|
httputil.ReturnError(r, w, 400, "Failed to parse eventID.")
|
2018-09-25 14:42:06 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2018-05-17 11:27:04 +08:00
|
|
|
|
|
2019-03-09 13:51:36 +08:00
|
|
|
|
logrus.Debug("Start receive upload file: ", eventID)
|
2018-09-25 14:42:06 +08:00
|
|
|
|
reader, header, err := r.FormFile("appTarFile")
|
|
|
|
|
if err != nil {
|
2018-11-22 16:22:44 +08:00
|
|
|
|
logrus.Errorf("Failed to parse upload file: %s", err.Error())
|
2018-09-25 14:42:06 +08:00
|
|
|
|
httputil.ReturnError(r, w, 501, "Failed to parse upload file.")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
defer reader.Close()
|
2018-05-17 11:27:04 +08:00
|
|
|
|
|
2019-03-09 13:51:36 +08:00
|
|
|
|
dirName := fmt.Sprintf("%s/import/%s", handler.GetAppHandler().GetStaticDir(), eventID)
|
2018-09-25 14:42:06 +08:00
|
|
|
|
os.MkdirAll(dirName, 0755)
|
2018-05-17 11:27:04 +08:00
|
|
|
|
|
2018-09-25 14:42:06 +08:00
|
|
|
|
fileName := fmt.Sprintf("%s/%s", dirName, header.Filename)
|
2018-10-15 21:03:39 +08:00
|
|
|
|
file, err := os.OpenFile(fileName, os.O_WRONLY|os.O_CREATE, 0644)
|
2018-09-25 14:42:06 +08:00
|
|
|
|
if err != nil {
|
2018-11-22 16:22:44 +08:00
|
|
|
|
logrus.Errorf("Failed to open file: %s", err.Error())
|
2018-09-25 14:42:06 +08:00
|
|
|
|
httputil.ReturnError(r, w, 502, "Failed to open file: "+err.Error())
|
|
|
|
|
}
|
|
|
|
|
defer file.Close()
|
2018-05-17 11:27:04 +08:00
|
|
|
|
|
2018-09-25 14:42:06 +08:00
|
|
|
|
logrus.Debug("Start write file to: ", fileName)
|
|
|
|
|
if _, err := io.Copy(file, reader); err != nil {
|
2018-09-26 22:02:02 +08:00
|
|
|
|
logrus.Errorf("Failed to write file:%s", err.Error())
|
2018-09-25 14:42:06 +08:00
|
|
|
|
httputil.ReturnError(r, w, 503, "Failed to write file: "+err.Error())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logrus.Debug("successful write file to: ", fileName)
|
2018-09-26 22:02:02 +08:00
|
|
|
|
origin := r.Header.Get("Origin")
|
|
|
|
|
w.Header().Add("Access-Control-Allow-Origin", origin)
|
|
|
|
|
w.Header().Add("Access-Control-Allow-Methods", "POST,OPTIONS")
|
|
|
|
|
w.Header().Add("Access-Control-Allow-Credentials", "true")
|
|
|
|
|
w.Header().Add("Access-Control-Allow-Headers", "x-requested-with,Content-Type,X-Custom-Header")
|
|
|
|
|
httputil.ReturnSuccess(r, w, nil)
|
2018-09-25 14:42:06 +08:00
|
|
|
|
|
|
|
|
|
case "OPTIONS":
|
2018-09-25 15:23:36 +08:00
|
|
|
|
origin := r.Header.Get("Origin")
|
|
|
|
|
w.Header().Add("Access-Control-Allow-Origin", origin)
|
|
|
|
|
w.Header().Add("Access-Control-Allow-Methods", "POST,OPTIONS")
|
|
|
|
|
w.Header().Add("Access-Control-Allow-Credentials", "true")
|
2018-09-25 15:41:19 +08:00
|
|
|
|
w.Header().Add("Access-Control-Allow-Headers", "x-requested-with,Content-Type,X-Custom-Header")
|
2018-09-25 14:42:06 +08:00
|
|
|
|
httputil.ReturnSuccess(r, w, nil)
|
2018-05-17 11:27:04 +08:00
|
|
|
|
}
|
2018-05-23 14:26:27 +08:00
|
|
|
|
|
2018-05-15 11:03:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-09 13:51:36 +08:00
|
|
|
|
//ImportApp -
|
2018-05-10 11:08:49 +08:00
|
|
|
|
func (a *AppStruct) ImportApp(w http.ResponseWriter, r *http.Request) {
|
2018-05-17 11:27:04 +08:00
|
|
|
|
switch r.Method {
|
|
|
|
|
case "POST":
|
2018-05-21 18:21:42 +08:00
|
|
|
|
var importApp = model.ImportAppStruct{
|
2018-05-17 11:27:04 +08:00
|
|
|
|
Format: "rainbond-app",
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-21 18:21:42 +08:00
|
|
|
|
ok := httputil.ValidatorRequestStructAndErrorResponse(r, w, &importApp, nil)
|
2018-05-17 11:27:04 +08:00
|
|
|
|
if !ok {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取tar包所在目录
|
2018-05-21 18:21:42 +08:00
|
|
|
|
importApp.SourceDir = fmt.Sprintf("%s/import/%s", handler.GetAppHandler().GetStaticDir(), importApp.EventID)
|
2018-05-17 11:27:04 +08:00
|
|
|
|
|
|
|
|
|
// 要先更新数据库再通知builder组件
|
2018-05-21 18:21:42 +08:00
|
|
|
|
app := model.NewAppStatusFromImport(&importApp)
|
2018-05-17 11:27:04 +08:00
|
|
|
|
db.GetManager().AppDao().DeleteModelByEventId(app.EventID)
|
2018-05-21 18:21:42 +08:00
|
|
|
|
if err := db.GetManager().AppDao().AddModel(app); err != nil {
|
|
|
|
|
httputil.ReturnError(r, w, 502, fmt.Sprintf("Failed to import app %s: %v", app.SourceDir, err))
|
2018-05-17 11:27:04 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-21 18:21:42 +08:00
|
|
|
|
err := handler.GetAppHandler().ImportApp(&importApp)
|
2018-05-17 11:27:04 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
httputil.ReturnError(r, w, 501, fmt.Sprintf("Failed to import app: %v", err))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
httputil.ReturnSuccess(r, w, nil)
|
|
|
|
|
case "GET":
|
2019-03-09 13:51:36 +08:00
|
|
|
|
eventID := strings.TrimSpace(chi.URLParam(r, "eventID"))
|
|
|
|
|
if eventID == "" {
|
|
|
|
|
httputil.ReturnError(r, w, 400, fmt.Sprintf("Arguments eventID is must defined."))
|
2018-05-17 11:27:04 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-09 13:51:36 +08:00
|
|
|
|
res, err := db.GetManager().AppDao().GetByEventId(eventID)
|
2018-05-17 11:27:04 +08:00
|
|
|
|
if err != nil {
|
2018-09-28 13:09:25 +08:00
|
|
|
|
if err == gorm.ErrRecordNotFound {
|
2018-09-28 11:03:33 +08:00
|
|
|
|
res.Status = "uploading"
|
|
|
|
|
httputil.ReturnSuccess(r, w, res)
|
2018-09-27 14:31:52 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2019-03-09 13:51:36 +08:00
|
|
|
|
httputil.ReturnError(r, w, 500, fmt.Sprintf("Failed to query status of export app by event id %s: %v", eventID, err))
|
2018-05-17 11:27:04 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2018-09-25 21:55:51 +08:00
|
|
|
|
if res.Status == "cleaned" {
|
|
|
|
|
res.Metadata = ""
|
|
|
|
|
httputil.ReturnSuccess(r, w, res)
|
|
|
|
|
return
|
|
|
|
|
}
|
2018-05-17 11:27:04 +08:00
|
|
|
|
|
2018-05-29 11:21:38 +08:00
|
|
|
|
if res.Status == "success" {
|
|
|
|
|
metadatasFile := fmt.Sprintf("%s/metadatas.json", res.SourceDir)
|
|
|
|
|
data, err := ioutil.ReadFile(metadatasFile)
|
|
|
|
|
if err != nil {
|
|
|
|
|
httputil.ReturnError(r, w, 503, fmt.Sprintf("Can not read apps metadata from metadatas.json file: %v", err))
|
|
|
|
|
return
|
|
|
|
|
}
|
2018-05-17 11:27:04 +08:00
|
|
|
|
|
2018-05-29 11:21:38 +08:00
|
|
|
|
res.Metadata = string(data)
|
|
|
|
|
}
|
2018-05-23 14:26:27 +08:00
|
|
|
|
|
2018-05-28 21:55:58 +08:00
|
|
|
|
httputil.ReturnSuccess(r, w, res)
|
2018-09-12 11:42:10 +08:00
|
|
|
|
|
|
|
|
|
case "DELETE":
|
2019-03-09 13:51:36 +08:00
|
|
|
|
eventID := strings.TrimSpace(chi.URLParam(r, "eventID"))
|
|
|
|
|
if eventID == "" {
|
|
|
|
|
httputil.ReturnError(r, w, 400, fmt.Sprintf("Arguments eventID is must defined."))
|
2018-09-12 11:42:10 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2019-03-09 13:51:36 +08:00
|
|
|
|
res, err := db.GetManager().AppDao().GetByEventId(eventID)
|
2018-09-12 11:42:10 +08:00
|
|
|
|
if err != nil {
|
2019-03-09 13:51:36 +08:00
|
|
|
|
httputil.ReturnError(r, w, 404, fmt.Sprintf("Failed to query status of export app by event id %s: %v", eventID, err))
|
2018-09-12 11:42:10 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2018-09-25 14:42:06 +08:00
|
|
|
|
if err := db.GetManager().AppDao().DeleteModelByEventId(res.EventID); err != nil {
|
2019-03-09 13:51:36 +08:00
|
|
|
|
httputil.ReturnError(r, w, 503, fmt.Sprintf("Deleting database records by event ID failed %s: %v", eventID, err))
|
2018-09-12 11:42:10 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if _, err := os.Stat(res.SourceDir); err == nil {
|
2018-09-25 14:42:06 +08:00
|
|
|
|
if err := os.RemoveAll(res.SourceDir); err != nil {
|
2018-09-12 11:42:10 +08:00
|
|
|
|
httputil.ReturnError(r, w, 504, fmt.Sprintf("Deleting uploading application directory failed %s : %v", res.SourceDir, err))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
httputil.ReturnSuccess(r, w, "successfully deleted")
|
2018-05-28 21:55:58 +08:00
|
|
|
|
}
|
2018-05-23 14:26:27 +08:00
|
|
|
|
|
|
|
|
|
}
|