Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions agent/app/dto/request/website.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ type WebsiteHtmlReq struct {
type WebsiteHtmlUpdate struct {
Type string `json:"type" validate:"required"`
Content string `json:"content" validate:"required"`
Sync bool `json:"sync"`
}

type WebsiteLBCreate struct {
Expand Down
9 changes: 9 additions & 0 deletions agent/app/service/website.go
Original file line number Diff line number Diff line change
Expand Up @@ -2028,6 +2028,15 @@ func (w WebsiteService) UpdateDefaultHtml(req request.WebsiteHtmlUpdate) error {
switch req.Type {
case "404":
resourcePath = path.Join(defaultPath, "404.html")
if req.Sync {
websites, _ := websiteRepo.GetBy(repo.WithTypes([]string{constant.Static, constant.Runtime}))
for _, website := range websites {
filePath := path.Join(GetSitePath(website, SiteIndexDir), "404.html")
if fileOp.Stat(filePath) {
_ = fileOp.SaveFile(filePath, req.Content, constant.DirPerm)
}
}
}
case "php":
resourcePath = path.Join(defaultPath, "index.php")
case "index":
Expand Down
1 change: 1 addition & 0 deletions frontend/src/api/interface/website.ts
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ export namespace Website {
export interface WebsiteHtmlUpdate {
type: string;
content: string;
sync: boolean;
}

export interface NginxUpstream {
Expand Down
22 changes: 14 additions & 8 deletions frontend/src/views/website/website/html/index.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
<template>
<DrawerPro v-model="open" :header="$t('website.defaultHtml')" @close="handleClose" size="normal">
<el-select v-model="type" class="w-full" @change="get()" v-loading="loading">
<el-select v-model="req.type" class="w-full" @change="get()" v-loading="loading">
<el-option :value="'404'" :label="$t('website.website404')"></el-option>
<el-option :value="'domain404'" :label="$t('website.domain404')"></el-option>
<el-option :value="'index'" :label="$t('website.indexHtml')"></el-option>
<el-option :value="'php'" :label="$t('website.indexPHP')"></el-option>
<el-option :value="'stop'" :label="$t('website.stopHtml')"></el-option>
</el-select>
<div class="mt-1.5">
<el-text v-if="type == '404'" type="info">
<el-text v-if="req.type == '404'" type="info">
{{ $t('website.website404Helper') }}
</el-text>
</div>
<div class="mt-1.5">
<el-checkbox v-model="req.sync">{{ $t('同步到 PHP 和静态网站') }}</el-checkbox>
</div>
<div ref="htmlRef" class="default-html"></div>

<template #footer>
<span class="dialog-footer">
<el-button @click="handleClose" :disabled="loading">{{ $t('commons.button.cancel') }}</el-button>
Expand All @@ -37,12 +41,15 @@ import { oneDark } from '@codemirror/theme-one-dark';
let open = ref(false);
let loading = ref(false);
const content = ref('');
const type = ref('404');
const view = ref();
const htmlRef = ref();
const req = reactive({
type: '404',
sync: false,
});

const acceptParams = () => {
type.value = '404';
req.type = '404';
get();
open.value = true;
};
Expand All @@ -52,7 +59,7 @@ const handleClose = () => {
};

const get = async () => {
const res = await getDefaultHtml(type.value);
const res = await getDefaultHtml(req.type);
content.value = res.data.content;
initEditor();
};
Expand All @@ -62,7 +69,7 @@ const initEditor = () => {
view.value.destroy();
}
let extensions = [basicSetup, oneDark];
if (type.value === 'php') {
if (req.type === 'php') {
extensions.push(php());
} else {
extensions.push(html());
Expand All @@ -83,7 +90,7 @@ const submit = async () => {
loading.value = true;
try {
const content = view.value.state.doc.toString();
await updateDefaultHtml({ type: type.value, content: content });
await updateDefaultHtml({ type: req.type, content: content, sync: req.sync });
MsgSuccess(i18n.global.t('commons.msg.updateSuccess'));
} catch (error) {
} finally {
Expand All @@ -97,6 +104,5 @@ defineExpose({ acceptParams });
.default-html {
width: 100%;
min-height: 300px;
margin-top: 10px;
}
</style>
Loading