diff --git a/backend/app/dto/app.go b/backend/app/dto/app.go index a38a227c2..3630ce5e8 100644 --- a/backend/app/dto/app.go +++ b/backend/app/dto/app.go @@ -87,6 +87,7 @@ var ( Up AppOperate = "up" Down AppOperate = "down" Restart AppOperate = "restart" + Delete AppOperate = "delete" ) type AppInstallOperate struct { diff --git a/backend/app/repo/app_install.go b/backend/app/repo/app_install.go index deafa72e2..09f43134d 100644 --- a/backend/app/repo/app_install.go +++ b/backend/app/repo/app_install.go @@ -21,11 +21,20 @@ func (a AppInstallRepo) Create(install *model.AppInstall) error { db := global.DB.Model(&model.AppInstall{}) return db.Create(&install).Error } + func (a AppInstallRepo) Save(install model.AppInstall) error { db := global.DB.Model(&model.AppInstall{}) return db.Save(&install).Error } +func (a AppInstallRepo) Delete(opts ...DBOption) error { + db := global.DB.Model(&model.AppInstall{}) + for _, opt := range opts { + db = opt(db) + } + return db.Delete(&model.AppInstall{}).Error +} + func (a AppInstallRepo) Page(page, size int, opts ...DBOption) (int64, []model.AppInstall, error) { var apps []model.AppInstall db := global.DB.Model(&model.AppInstall{}) diff --git a/backend/app/service/app.go b/backend/app/service/app.go index f16ce9be9..6796412ef 100644 --- a/backend/app/service/app.go +++ b/backend/app/service/app.go @@ -154,7 +154,7 @@ func (a AppService) Operate(req dto.AppInstallOperate) error { return err } if len(appInstall) == 0 { - return errors.New("not found") + return errors.New("req not found") } install := appInstall[0] @@ -175,6 +175,20 @@ func (a AppService) Operate(req dto.AppInstallOperate) error { if err != nil { return handleErr(install, err, out) } + case dto.Delete: + op := files.NewFileOp() + appDir := path.Join(global.CONF.System.AppDir, install.App.Key, install.ContainerName) + dir, _ := os.Stat(appDir) + if dir == nil { + _ = appInstallRepo.Delete(commonRepo.WithByID(install.ID)) + break + } + _ = op.DeleteDir(appDir) + out, err := compose.Rmf(dockerComposePath) + if err != nil { + return handleErr(install, err, out) + } + _ = appInstallRepo.Delete(commonRepo.WithByID(install.ID)) default: return errors.New("operate not support") } diff --git a/backend/utils/compose/compose.go b/backend/utils/compose/compose.go index 593b5b9bc..6bbe44016 100644 --- a/backend/utils/compose/compose.go +++ b/backend/utils/compose/compose.go @@ -28,3 +28,12 @@ func Restart(filePath string) (string, error) { } return string(stdout), nil } + +func Rmf(filePath string) (string, error) { + cmd := exec.Command("docker-compose", "-f", filePath, "rm", "-f") + stdout, err := cmd.CombinedOutput() + if err != nil { + return "", err + } + return string(stdout), nil +} diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 6e8e984dd..c103e04e3 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -408,11 +408,12 @@ export default { sync: 'sync', appName: 'App Name', status: 'status', - container: 'container', - restart: 'restart', - up: 'start', - down: 'stop', - name: 'name', - description: 'description', + container: 'Container', + restart: 'Restart', + up: 'Start', + down: 'Stop', + name: 'Name', + description: 'Description', + delete: 'Delete', }, }; diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 3cd216d6f..8b8c25c95 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -406,5 +406,6 @@ export default { down: '停止', name: '名称', description: '描述', + delete: '删除', }, }; diff --git a/frontend/src/views/app-store/installed/index.vue b/frontend/src/views/app-store/installed/index.vue index e26a66a4a..ee85e11b4 100644 --- a/frontend/src/views/app-store/installed/index.vue +++ b/frontend/src/views/app-store/installed/index.vue @@ -1,7 +1,7 @@