feat: 修改安装限制

pull/43/head
zhengkunwang223 2022-11-22 14:32:45 +08:00 committed by zhengkunwang223
parent bdfad5e710
commit 546b684f92
4 changed files with 32 additions and 77 deletions

View File

@ -137,13 +137,13 @@ type AppDefine struct {
Name string `json:"name"` Name string `json:"name"`
Tags []string `json:"tags"` Tags []string `json:"tags"`
Versions []string `json:"versions"` Versions []string `json:"versions"`
//Icon string `json:"icon"`
Author string `json:"author"` Author string `json:"author"`
Source string `json:"source"` Source string `json:"source"`
ShortDesc string `json:"short_desc"` ShortDesc string `json:"short_desc"`
Type string `json:"type"` Type string `json:"type"`
Required []string `json:"Required"` Required []string `json:"Required"`
CrossVersionUpdate bool `json:"crossVersionUpdate"` CrossVersionUpdate bool `json:"crossVersionUpdate"`
Limit int `json:"limit"`
} }
func (define AppDefine) GetRequired() string { func (define AppDefine) GetRequired() string {

View File

@ -136,7 +136,7 @@ func (a AppService) Install(name string, appDetailId uint, params map[string]int
} }
httpsPort, err := checkPort("PANEL_APP_PORT_HTTPS", params) httpsPort, err := checkPort("PANEL_APP_PORT_HTTPS", params)
if err != nil { if err != nil {
return nil, fmt.Errorf("%d port is in used", httpPort) return nil, fmt.Errorf("%d port is in used", httpsPort)
} }
appDetail, err := appDetailRepo.GetFirst(commonRepo.WithByID(appDetailId)) appDetail, err := appDetailRepo.GetFirst(commonRepo.WithByID(appDetailId))
@ -483,51 +483,5 @@ func (a AppService) SyncAppList() error {
tx.Commit() tx.Commit()
go syncCanUpdate()
return nil return nil
} }
func syncCanUpdate() {
apps, err := appRepo.GetBy()
if err != nil {
global.LOG.Errorf("sync update app error: %s", err.Error())
}
for _, app := range apps {
details, err := appDetailRepo.GetBy(appDetailRepo.WithAppId(app.ID))
if err != nil {
global.LOG.Errorf("sync update app error: %s", err.Error())
}
var versions []string
for _, detail := range details {
versions = append(versions, detail.Version)
}
versions = common.GetSortedVersions(versions)
lastVersion := versions[0]
var updateDetailIds []uint
for _, detail := range details {
if lastVersion == detail.Version {
continue
}
if common.CompareVersion(lastVersion, detail.Version) && (app.CrossVersionUpdate || !common.IsCrossVersion(detail.Version, lastVersion)) {
updateDetailIds = append(updateDetailIds, detail.ID)
}
}
if err := appDetailRepo.BatchUpdateBy(map[string]interface{}{"last_version": ""}); err != nil {
global.LOG.Errorf("sync update app error: %s", err.Error())
}
if err := appInstallRepo.BatchUpdateBy(map[string]interface{}{"can_update": 0}); err != nil {
global.LOG.Errorf("sync update app error: %s", err.Error())
}
if len(updateDetailIds) > 0 {
if err := appDetailRepo.BatchUpdateBy(map[string]interface{}{"last_version": lastVersion}, commonRepo.WithIdsIn(updateDetailIds)); err != nil {
global.LOG.Errorf("sync update app error: %s", err.Error())
}
//if err := appInstallRepo.BatchUpdateBy(map[string]interface{}{"can_update": 1}, appInstallRepo.WithDetailIdsIn(updateDetailIds)); err != nil {
// global.LOG.Errorf("sync update app error: %s", err.Error())
//}
}
}
}

View File

@ -488,6 +488,7 @@ func getApps(oldApps []model.App, items []dto.AppDefine) map[string]model.App {
app = model.App{} app = model.App{}
} }
app.Name = item.Name app.Name = item.Name
app.Limit = item.Limit
app.Key = item.Key app.Key = item.Key
app.ShortDesc = item.ShortDesc app.ShortDesc = item.ShortDesc
app.Author = item.Author app.Author = item.Author

View File

@ -57,14 +57,14 @@
/> />
</ComplexTable> </ComplexTable>
<el-dialog v-model="open" :title="$t('commons.msg.operate')" :before-close="handleClose" width="30%"> <el-dialog v-model="open" :title="$t('commons.msg.operate')" :before-close="handleClose" width="30%">
<el-alert <!-- <el-alert
v-if="operateReq.operate != 'update'" v-if="operateReq.operate != 'update'"
:title="getMsg(operateReq.operate)" :title="getMsg(operateReq.operate)"
type="warning" type="warning"
:closable="false" :closable="false"
show-icon show-icon
/> /> -->
<div v-else style="text-align: center"> <div style="text-align: center">
<p>{{ $t('app.versioneSelect') }}</p> <p>{{ $t('app.versioneSelect') }}</p>
<el-select v-model="operateReq.detailId"> <el-select v-model="operateReq.detailId">
<el-option <el-option
@ -198,28 +198,28 @@ const onOperate = async (operation: string) => {
}); });
}; };
const getMsg = (op: string) => { // const getMsg = (op: string) => {
let tip = ''; // let tip = '';
switch (op) { // switch (op) {
case 'up': // case 'up':
tip = i18n.global.t('app.up'); // tip = i18n.global.t('app.up');
break; // break;
case 'down': // case 'down':
tip = i18n.global.t('app.down'); // tip = i18n.global.t('app.down');
break; // break;
case 'restart': // case 'restart':
tip = i18n.global.t('app.restart'); // tip = i18n.global.t('app.restart');
break; // break;
case 'delete': // case 'delete':
tip = i18n.global.t('app.deleteWarn'); // tip = i18n.global.t('app.deleteWarn');
break; // break;
case 'sync': // case 'sync':
tip = i18n.global.t('app.sync'); // tip = i18n.global.t('app.sync');
break; // break;
default: // default:
} // }
return tip; // return tip;
}; // };
const buttons = [ const buttons = [
{ {