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

@ -133,17 +133,17 @@ type AppList struct {
}
type AppDefine struct {
Key string `json:"key"`
Name string `json:"name"`
Tags []string `json:"tags"`
Versions []string `json:"versions"`
//Icon string `json:"icon"`
Key string `json:"key"`
Name string `json:"name"`
Tags []string `json:"tags"`
Versions []string `json:"versions"`
Author string `json:"author"`
Source string `json:"source"`
ShortDesc string `json:"short_desc"`
Type string `json:"type"`
Required []string `json:"Required"`
CrossVersionUpdate bool `json:"crossVersionUpdate"`
Limit int `json:"limit"`
}
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)
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))
@ -483,51 +483,5 @@ func (a AppService) SyncAppList() error {
tx.Commit()
go syncCanUpdate()
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.Name = item.Name
app.Limit = item.Limit
app.Key = item.Key
app.ShortDesc = item.ShortDesc
app.Author = item.Author

View File

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