fix(app): fix issue with reinstall openresty failed (#8265)

This commit is contained in:
zhengkunwang 2025-03-27 16:55:36 +08:00 committed by GitHub
parent d09a3d82b9
commit 1908a59174
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 78 additions and 98 deletions

View file

@ -111,8 +111,9 @@ type Resource struct {
} }
type Database struct { type Database struct {
Name string `json:"name"` Name string `json:"name"`
Type string `json:"type"` DatabaseName string `json:"databaseName"`
From string `json:"from"` Type string `json:"type"`
ID uint `json:"id"` From string `json:"from"`
ID uint `json:"id"`
} }

View file

@ -192,16 +192,18 @@ func (a AppService) GetApp(ctx *gin.Context, key string) (*response.AppDTO, erro
} }
var versionsRaw []string var versionsRaw []string
hasLatest := false hasLatest := false
latestVersion := ""
for _, detail := range details { for _, detail := range details {
if strings.Contains(detail.Version, "latest") { if strings.Contains(detail.Version, "latest") {
hasLatest = true hasLatest = true
latestVersion = detail.Version
continue continue
} }
versionsRaw = append(versionsRaw, detail.Version) versionsRaw = append(versionsRaw, detail.Version)
} }
appDTO.Versions = common.GetSortedVersions(versionsRaw) appDTO.Versions = common.GetSortedVersions(versionsRaw)
if hasLatest { if hasLatest {
appDTO.Versions = append([]string{"latest"}, appDTO.Versions...) appDTO.Versions = append([]string{latestVersion}, appDTO.Versions...)
} }
tags, err := getAppTags(app.ID, strings.ToLower(common.GetLang(ctx))) tags, err := getAppTags(app.ID, strings.ToLower(common.GetLang(ctx)))
if err != nil { if err != nil {

View file

@ -1834,19 +1834,18 @@ func handleOpenrestyFile(appInstall *model.AppInstall) error {
break break
} }
} }
if !hasDefaultWebsite { if hasDefaultWebsite {
return nil installDir := appInstall.GetPath()
defaultConfigPath := path.Join(installDir, "conf", "default", "00.default.conf")
fileOp := files.NewFileOp()
content, err := fileOp.GetContent(defaultConfigPath)
if err != nil {
return err
}
newContent := strings.ReplaceAll(string(content), "default_server", "")
if err := fileOp.WriteFile(defaultConfigPath, strings.NewReader(newContent), constant.FilePerm); err != nil {
return err
}
} }
installDir := appInstall.GetPath() return createAllWebsitesWAFConfig(websites)
defaultConfigPath := path.Join(installDir, "conf", "default", "00.default.conf")
fileOp := files.NewFileOp()
content, err := fileOp.GetContent(defaultConfigPath)
if err != nil {
return err
}
newContent := strings.ReplaceAll(string(content), "default_server", "")
if err := fileOp.WriteFile(defaultConfigPath, strings.NewReader(newContent), constant.FilePerm); err != nil {
return err
}
return createAllWebsitesWAFConfig()
} }

View file

@ -3210,10 +3210,11 @@ func (w WebsiteService) ListDatabases() ([]response.Database, error) {
database, _ := databaseRepo.Get(repo.WithByName(db.MysqlName)) database, _ := databaseRepo.Get(repo.WithByName(db.MysqlName))
if database.ID > 0 { if database.ID > 0 {
res = append(res, response.Database{ res = append(res, response.Database{
ID: db.ID, ID: db.ID,
Name: db.Name, Name: db.Name,
Type: database.Type, Type: database.Type,
From: database.From, From: database.From,
DatabaseName: database.Name,
}) })
} }
} }
@ -3222,10 +3223,11 @@ func (w WebsiteService) ListDatabases() ([]response.Database, error) {
database, _ := databaseRepo.Get(repo.WithByName(db.PostgresqlName)) database, _ := databaseRepo.Get(repo.WithByName(db.PostgresqlName))
if database.ID > 0 { if database.ID > 0 {
res = append(res, response.Database{ res = append(res, response.Database{
ID: db.ID, ID: db.ID,
Name: db.Name, Name: db.Name,
Type: database.Type, Type: database.Type,
From: database.From, From: database.From,
DatabaseName: database.Name,
}) })
} }
} }

View file

@ -297,11 +297,7 @@ func moveDefaultWafConfig(websiteDir string, defaultConfigContent []byte, defaul
return nil return nil
} }
func createAllWebsitesWAFConfig() error { func createAllWebsitesWAFConfig(websites []model.Website) error {
websites, _ := websiteRepo.List()
if len(websites) == 0 {
return nil
}
nginxInstall, err := getAppInstallByKey(constant.AppOpenresty) nginxInstall, err := getAppInstallByKey(constant.AppOpenresty)
if err != nil { if err != nil {
return err return err

View file

@ -196,7 +196,6 @@ func (c Client) PullImageWithProcessAndOptions(task *task.Task, imageName string
} }
return err return err
} }
timeStr := time.Now().Format("2006/01/02 15:04:05")
status, _ := progress["status"].(string) status, _ := progress["status"].(string)
if status == "Downloading" || status == "Extracting" { if status == "Downloading" || status == "Extracting" {
id, _ := progress["id"].(string) id, _ := progress["id"].(string)
@ -204,16 +203,17 @@ func (c Client) PullImageWithProcessAndOptions(task *task.Task, imageName string
current, _ := progressDetail["current"].(float64) current, _ := progressDetail["current"].(float64)
progressStr := "" progressStr := ""
total, ok := progressDetail["total"].(float64) total, ok := progressDetail["total"].(float64)
timeStr := time.Now().Format("2006/01/02 15:04:05")
if ok { if ok {
progressStr = fmt.Sprintf("%s %s [%s] --- %.2f%%", timeStr, status, id, (current/total)*100) progressStr = fmt.Sprintf("%s %s [%s] --- %.2f%%", timeStr, status, id, (current/total)*100)
} else { } else {
progressStr = fmt.Sprintf("%s %s [%s] --- %.2f%%", timeStr, status, id, current) progressStr = fmt.Sprintf("%s %s [%s] --- %.2f%%", timeStr, status, id, current)
} }
_ = setLog(id, progressStr, task) _ = setLog(id, progressStr, task)
} }
if status == "Pull complete" || status == "Download complete" { if status == "Pull complete" || status == "Download complete" {
id, _ := progress["id"].(string) id, _ := progress["id"].(string)
timeStr := time.Now().Format("2006/01/02 15:04:05")
progressStr := fmt.Sprintf("%s %s [%s] --- %.2f%%", timeStr, status, id, 100.0) progressStr := fmt.Sprintf("%s %s [%s] --- %.2f%%", timeStr, status, id, 100.0)
_ = setLog(id, progressStr, task) _ = setLog(id, progressStr, task)
} }
@ -312,7 +312,6 @@ func (c Client) BuildImageWithProcessAndOptions(task *task.Task, tar io.ReadClos
} else { } else {
progressStr = fmt.Sprintf("%s %s [%s] --- %.2f%%", timeStr, status, id, current) progressStr = fmt.Sprintf("%s %s [%s] --- %.2f%%", timeStr, status, id, current)
} }
_ = setLog(id, progressStr, task) _ = setLog(id, progressStr, task)
case "Pull complete", "Download complete", "Verifying Checksum": case "Pull complete", "Download complete", "Verifying Checksum":
id, _ := progress["id"].(string) id, _ := progress["id"].(string)

View file

@ -629,6 +629,7 @@ export namespace Website {
databaseID: number; databaseID: number;
websiteID: number; websiteID: number;
from: string; from: string;
databaseName: number;
} }
export interface ChangeDatabase { export interface ChangeDatabase {

View file

@ -1,11 +1,10 @@
<template> <template>
<el-dialog <el-dialog
v-model="open" v-model="open"
:destroy-on-close="true"
:close-on-click-modal="false" :close-on-click-modal="false"
:close-on-press-escape="false" :close-on-press-escape="false"
:show-close="showClose" :show-close="showClose"
:before-close="handleClose" @close="handleClose"
:width="width" :width="width"
> >
<div> <div>
@ -44,7 +43,6 @@ const config = reactive({
}); });
const open = ref(false); const open = ref(false);
const showTail = ref(true); const showTail = ref(true);
const emit = defineEmits(['close']);
const openWithTaskID = (id: string, tail: boolean) => { const openWithTaskID = (id: string, tail: boolean) => {
config.taskID = id; config.taskID = id;
@ -64,9 +62,10 @@ const openWithResourceID = (taskType: string, taskOperate: string, resourceID: n
open.value = true; open.value = true;
}; };
const em = defineEmits(['close']);
const handleClose = () => { const handleClose = () => {
em('close', true);
open.value = false; open.value = false;
emit('close', true);
bus.emit('refreshTask', true); bus.emit('refreshTask', true);
}; };

View file

@ -273,19 +273,46 @@
<table> <table>
<tbody> <tbody>
<tr v-if="defaultLink != ''"> <tr v-if="defaultLink != ''">
<td> <td v-if="installed.httpPort > 0">
<el-button <el-button
type="primary" type="primary"
link link
@click=" @click="
toLink( toLink(
defaultLink + 'http://' +
defaultLink +
':' + ':' +
installed.httpPort, installed.httpPort,
) )
" "
> >
{{ defaultLink + ':' + installed.httpPort }} {{
'http://' +
defaultLink +
':' +
installed.httpPort
}}
</el-button>
</td>
<td v-if="installed.httpsPort > 0">
<el-button
type="primary"
link
@click="
toLink(
'https://' +
defaultLink +
':' +
installed.httpsPort,
)
"
>
{{
'https://' +
defaultLink +
':' +
installed.httpsPort
}}
</el-button> </el-button>
</td> </td>
</tr> </tr>

View file

@ -2,14 +2,7 @@
<DrawerPro v-model="drawerVisible" :header="$t('app.defaultWebDomain')" @close="handleClose" size="small"> <DrawerPro v-model="drawerVisible" :header="$t('app.defaultWebDomain')" @close="handleClose" size="small">
<el-form ref="formRef" label-position="top" :model="form" :rules="rules" @submit.prevent v-loading="loading"> <el-form ref="formRef" label-position="top" :model="form" :rules="rules" @submit.prevent v-loading="loading">
<el-form-item :label="$t('app.defaultWebDomain')" prop="defaultDomain"> <el-form-item :label="$t('app.defaultWebDomain')" prop="defaultDomain">
<el-input v-model="form.defaultDomain"> <el-input v-model="form.defaultDomain"></el-input>
<template #prepend>
<el-select v-model="protocol" placeholder="Select" class="p-w-100">
<el-option label="HTTP" value="http://" />
<el-option label="HTTPS" value="https://" />
</el-select>
</template>
</el-input>
<span class="input-help">{{ $t('app.defaultWebDomainHepler') }}</span> <span class="input-help">{{ $t('app.defaultWebDomainHepler') }}</span>
</el-form-item> </el-form-item>
</el-form> </el-form>
@ -36,18 +29,15 @@ const form = reactive({
defaultDomain: '', defaultDomain: '',
}); });
const rules = reactive({ const rules = reactive({
defaultDomain: [Rules.requiredInput], defaultDomain: [Rules.requiredInput, Rules.ipV4V6OrDomain],
}); });
const formRef = ref<FormInstance>(); const formRef = ref<FormInstance>();
const protocol = ref('http://');
interface DialogProps { interface DialogProps {
protocol: string;
domain: string; domain: string;
} }
const acceptParams = (config: DialogProps): void => { const acceptParams = (config: DialogProps): void => {
form.defaultDomain = config.domain; form.defaultDomain = config.domain;
protocol.value = config.protocol;
drawerVisible.value = true; drawerVisible.value = true;
}; };
@ -64,12 +54,8 @@ const submit = async () => {
} }
loading.value = true; loading.value = true;
try { try {
let defaultDomain = '';
if (form.defaultDomain) {
defaultDomain = protocol.value + form.defaultDomain;
}
const req = { const req = {
defaultDomain: defaultDomain, defaultDomain: form.defaultDomain,
}; };
await updateAppStoreConfig(req); await updateAppStoreConfig(req);
MsgSuccess(i18n.global.t('commons.msg.updateSuccess')); MsgSuccess(i18n.global.t('commons.msg.updateSuccess'));

View file

@ -14,12 +14,6 @@
<el-col :xs="24" :sm="20" :md="15" :lg="12" :xl="12"> <el-col :xs="24" :sm="20" :md="15" :lg="12" :xl="12">
<el-form-item :label="$t('app.defaultWebDomain')" prop="defaultDomain"> <el-form-item :label="$t('app.defaultWebDomain')" prop="defaultDomain">
<el-input v-model="config.defaultDomain" disabled> <el-input v-model="config.defaultDomain" disabled>
<template #prepend>
<el-select v-model="protocol" placeholder="Select" class="p-w-100" disabled>
<el-option label="HTTP" value="http://" />
<el-option label="HTTPS" value="https://" />
</el-select>
</template>
<template #append> <template #append>
<el-button @click="setDefaultDomain()" icon="Setting"> <el-button @click="setDefaultDomain()" icon="Setting">
{{ $t('commons.button.set') }} {{ $t('commons.button.set') }}
@ -54,35 +48,15 @@ const config = ref({
}); });
const loading = ref(false); const loading = ref(false);
const configForm = ref(); const configForm = ref();
const protocol = ref('http://');
const domainRef = ref(); const domainRef = ref();
const useCustomApp = ref(false); const useCustomApp = ref(false);
function getUrl(url: string) {
const regex = /^(https?:\/\/)(.*)/;
const match = url.match(regex);
if (match) {
const protocol = match[1];
const remainder = match[2];
return {
protocol: protocol,
remainder: remainder,
};
} else {
return null;
}
}
const search = async () => { const search = async () => {
loading.value = true; loading.value = true;
try { try {
const res = await getAppStoreConfig(); const res = await getAppStoreConfig();
if (res.data.defaultDomain != '') { if (res.data.defaultDomain != '') {
const url = getUrl(res.data.defaultDomain); config.value.defaultDomain = res.data.defaultDomain;
if (url) {
config.value.defaultDomain = url.remainder;
protocol.value = url.protocol;
}
} }
} catch (error) { } catch (error) {
} finally { } finally {
@ -93,7 +67,6 @@ const search = async () => {
const setDefaultDomain = () => { const setDefaultDomain = () => {
domainRef.value.acceptParams({ domainRef.value.acceptParams({
domain: config.value.defaultDomain, domain: config.value.defaultDomain,
protocol: protocol.value,
}); });
}; };

View file

@ -24,7 +24,7 @@
<div class="flex justify-between items-center"> <div class="flex justify-between items-center">
<span>{{ item.name }}</span> <span>{{ item.name }}</span>
<div> <div>
<el-tag>{{ item.type }}</el-tag> <el-tag>{{ item.databaseName }}</el-tag>
<el-tag class="ml-1"> <el-tag class="ml-1">
{{ item.from === 'local' ? $t('commons.table.local') : $t('database.remote') }} {{ item.from === 'local' ? $t('commons.table.local') : $t('database.remote') }}
</el-tag> </el-tag>
@ -79,16 +79,11 @@ const listDatabases = async () => {
try { try {
const res = await getWebsiteDatabase(); const res = await getWebsiteDatabase();
databases.value = res.data; databases.value = res.data;
if (databases.value.length > 0) { if (databases.value.length > 0 && website.value.dbID > 0) {
if (website.value.dbID > 0) { for (let i = 0; i < databases.value.length; i++) {
for (let i = 0; i < databases.value.length; i++) { if (databases.value[i].id === website.value.dbID && databases.value[i].type === website.value.dbType) {
if ( req.db = databases.value[i].id + databases.value[i].type;
databases.value[i].id === website.value.dbID && break;
databases.value[i].type === website.value.dbType
) {
req.db = databases.value[i].id + databases.value[i].type;
break;
}
} }
} }
} }