Skip to content

Commit c6df20e

Browse files
feat: support sync 404 html page to websites (#11513)
Refs #11489
1 parent 6f9a132 commit c6df20e

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

agent/app/dto/request/website.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ type WebsiteHtmlReq struct {
310310
type WebsiteHtmlUpdate struct {
311311
Type string `json:"type" validate:"required"`
312312
Content string `json:"content" validate:"required"`
313+
Sync bool `json:"sync"`
313314
}
314315

315316
type WebsiteLBCreate struct {

agent/app/service/website.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2028,6 +2028,15 @@ func (w WebsiteService) UpdateDefaultHtml(req request.WebsiteHtmlUpdate) error {
20282028
switch req.Type {
20292029
case "404":
20302030
resourcePath = path.Join(defaultPath, "404.html")
2031+
if req.Sync {
2032+
websites, _ := websiteRepo.GetBy(repo.WithTypes([]string{constant.Static, constant.Runtime}))
2033+
for _, website := range websites {
2034+
filePath := path.Join(GetSitePath(website, SiteIndexDir), "404.html")
2035+
if fileOp.Stat(filePath) {
2036+
_ = fileOp.SaveFile(filePath, req.Content, constant.DirPerm)
2037+
}
2038+
}
2039+
}
20312040
case "php":
20322041
resourcePath = path.Join(defaultPath, "index.php")
20332042
case "index":

frontend/src/api/interface/website.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ export namespace Website {
612612
export interface WebsiteHtmlUpdate {
613613
type: string;
614614
content: string;
615+
sync: boolean;
615616
}
616617

617618
export interface NginxUpstream {

frontend/src/views/website/website/html/index.vue

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
<template>
22
<DrawerPro v-model="open" :header="$t('website.defaultHtml')" @close="handleClose" size="normal">
3-
<el-select v-model="type" class="w-full" @change="get()" v-loading="loading">
3+
<el-select v-model="req.type" class="w-full" @change="get()" v-loading="loading">
44
<el-option :value="'404'" :label="$t('website.website404')"></el-option>
55
<el-option :value="'domain404'" :label="$t('website.domain404')"></el-option>
66
<el-option :value="'index'" :label="$t('website.indexHtml')"></el-option>
77
<el-option :value="'php'" :label="$t('website.indexPHP')"></el-option>
88
<el-option :value="'stop'" :label="$t('website.stopHtml')"></el-option>
99
</el-select>
1010
<div class="mt-1.5">
11-
<el-text v-if="type == '404'" type="info">
11+
<el-text v-if="req.type == '404'" type="info">
1212
{{ $t('website.website404Helper') }}
1313
</el-text>
1414
</div>
15+
<div class="mt-1.5">
16+
<el-checkbox v-model="req.sync">{{ $t('同步到 PHP 和静态网站') }}</el-checkbox>
17+
</div>
1518
<div ref="htmlRef" class="default-html"></div>
19+
1620
<template #footer>
1721
<span class="dialog-footer">
1822
<el-button @click="handleClose" :disabled="loading">{{ $t('commons.button.cancel') }}</el-button>
@@ -37,12 +41,15 @@ import { oneDark } from '@codemirror/theme-one-dark';
3741
let open = ref(false);
3842
let loading = ref(false);
3943
const content = ref('');
40-
const type = ref('404');
4144
const view = ref();
4245
const htmlRef = ref();
46+
const req = reactive({
47+
type: '404',
48+
sync: false,
49+
});
4350
4451
const acceptParams = () => {
45-
type.value = '404';
52+
req.type = '404';
4653
get();
4754
open.value = true;
4855
};
@@ -52,7 +59,7 @@ const handleClose = () => {
5259
};
5360
5461
const get = async () => {
55-
const res = await getDefaultHtml(type.value);
62+
const res = await getDefaultHtml(req.type);
5663
content.value = res.data.content;
5764
initEditor();
5865
};
@@ -62,7 +69,7 @@ const initEditor = () => {
6269
view.value.destroy();
6370
}
6471
let extensions = [basicSetup, oneDark];
65-
if (type.value === 'php') {
72+
if (req.type === 'php') {
6673
extensions.push(php());
6774
} else {
6875
extensions.push(html());
@@ -83,7 +90,7 @@ const submit = async () => {
8390
loading.value = true;
8491
try {
8592
const content = view.value.state.doc.toString();
86-
await updateDefaultHtml({ type: type.value, content: content });
93+
await updateDefaultHtml({ type: req.type, content: content, sync: req.sync });
8794
MsgSuccess(i18n.global.t('commons.msg.updateSuccess'));
8895
} catch (error) {
8996
} finally {
@@ -97,6 +104,5 @@ defineExpose({ acceptParams });
97104
.default-html {
98105
width: 100%;
99106
min-height: 300px;
100-
margin-top: 10px;
101107
}
102108
</style>

0 commit comments

Comments
 (0)