修复审查发现的认证配置邮件协议及前端问题
补齐安全运行时清理、配置候选恢复、泛域名证书事务提交、邮件副本与协议边界、插件隐私和安装回滚回归,并更新修复状态及待验收清单。
This commit is contained in:
1 parent
addfcea1cd
commit
6f79441585
71 files changed
+2853
-664
No files matched your search
@@ -118,6 +118,7 @@ const {
|
||||
upload,
|
||||
send,
|
||||
ruleFormRef,
|
||||
fileRef,
|
||||
fileChange,
|
||||
rules,
|
||||
ruleForm,
|
||||
|
||||
@@ -98,6 +98,7 @@
|
||||
import { usePage, CircleCheck, Switch, Delete, View, Folder, EpArrowDownBold, EditPen, Warning } from './List.js'
|
||||
|
||||
const {
|
||||
taskTableDataRef,
|
||||
groupStore,
|
||||
selectAll,
|
||||
data,
|
||||
|
||||
@@ -103,7 +103,7 @@
|
||||
:section="selectedSection"
|
||||
:config="formConfig"
|
||||
:errors="formErrors"
|
||||
:disabled="!canWrite || !!working"
|
||||
:disabled="!canWrite || !!working || !!pendingCandidate"
|
||||
@change="updateField"
|
||||
/>
|
||||
<p id="config-sensitive-hint" class="editor-hint">{{ sensitiveHint }}。</p>
|
||||
@@ -119,7 +119,7 @@
|
||||
type="password"
|
||||
show-password
|
||||
clearable
|
||||
:disabled="!canWrite || sectionLoading || !!working || !!sectionError"
|
||||
:disabled="!canWrite || sectionLoading || !!working || !!sectionError || !!pendingCandidate"
|
||||
:placeholder="secretField.placeholder"
|
||||
autocomplete="new-password"
|
||||
@update:model-value="updateSecret"
|
||||
@@ -127,21 +127,34 @@
|
||||
</div>
|
||||
|
||||
<div v-if="canWrite" class="editor-footer">
|
||||
<el-alert
|
||||
v-if="pendingCandidate"
|
||||
:title="`服务器存在待应用候选,代次 ${pendingCandidate.generation}。已锁定编辑;如需修改,请先取消候选。刷新页面不会丢失候选。`"
|
||||
type="warning"
|
||||
:closable="false"
|
||||
show-icon
|
||||
/>
|
||||
<el-checkbox v-model="confirmed" class="confirmation-check" :disabled="sectionLoading || !!working || !!sectionError">
|
||||
我已确认这是受控变更,并允许使用最近认证完成高风险配置操作
|
||||
</el-checkbox>
|
||||
<div class="action-row">
|
||||
<el-button :loading="working === 'validate'" :disabled="sectionLoading || !!working || !!sectionError" @click="validateConfig">
|
||||
<el-button :loading="working === 'validate'" :disabled="sectionLoading || !!working || !!sectionError || !!pendingCandidate" @click="validateConfig">
|
||||
只验证
|
||||
</el-button>
|
||||
<el-button type="primary" :loading="working === 'save'" :disabled="sectionLoading || !!working || !!sectionError" @click="saveConfig">
|
||||
<el-button type="primary" :loading="working === 'save'" :disabled="sectionLoading || !!working || !!sectionError || !!pendingCandidate" @click="saveConfig">
|
||||
保存候选配置
|
||||
</el-button>
|
||||
<el-button v-if="pendingCandidate && !pendingCandidate.sameSession" :disabled="!!working || !confirmed" @click="managePending('resume')">
|
||||
恢复候选到当前会话
|
||||
</el-button>
|
||||
<el-button v-if="pendingCandidate" type="warning" plain :disabled="!!working || pendingCandidate.committed" @click="managePending('cancel')">
|
||||
取消候选配置
|
||||
</el-button>
|
||||
<el-button type="success" plain :loading="working === 'apply'" :disabled="sectionLoading || !!working || !savedGeneration" @click="applyConfig">
|
||||
{{ savedGeneration ? `应用代次 ${savedGeneration}` : '应用配置' }}
|
||||
</el-button>
|
||||
</div>
|
||||
<p class="action-hint">保存不会立即生效;保存后若继续修改内容,需要重新保存才能应用。</p>
|
||||
<p class="action-hint">保存不会立即生效;需要继续修改时先取消候选。跨会话恢复或取消需要近期认证并勾选确认。</p>
|
||||
</div>
|
||||
<div v-if="validationResult" class="result-box" :class="validationResult.valid ? 'result-success' : 'result-error'" role="status">
|
||||
<strong>{{ validationResult.valid ? '验证通过' : '验证未通过' }}</strong>
|
||||
@@ -182,6 +195,8 @@ const {
|
||||
secretValue,
|
||||
confirmed,
|
||||
savedGeneration,
|
||||
pendingCandidate,
|
||||
managePending,
|
||||
validationResult,
|
||||
canWrite,
|
||||
refreshPage,
|
||||
|
||||
@@ -60,6 +60,7 @@ export function usePage(pageKey = 'base') {
|
||||
const secretValue = ref('')
|
||||
const confirmed = ref(false)
|
||||
const savedGeneration = ref(0)
|
||||
const pendingCandidate = ref(null)
|
||||
let savedInput = null
|
||||
const validationResult = ref(null)
|
||||
const backups = ref([])
|
||||
@@ -134,7 +135,8 @@ export function usePage(pageKey = 'base') {
|
||||
validationResult.value = null
|
||||
confirmed.value = false
|
||||
}
|
||||
const canEdit = () => !disposed && canWrite.value && !loading.value && !working.value && !sectionLoading.value && !sectionError.value
|
||||
const canOperate = () => !disposed && canWrite.value && !loading.value && !working.value && !sectionLoading.value && !sectionError.value && !availabilityError.value
|
||||
const canEdit = () => canOperate() && !pendingCandidate.value && !savedGeneration.value
|
||||
const updateField = (path, value) => {
|
||||
if (!canEdit()) return
|
||||
const updated = updateFormConfig(editorText.value, selectedSection.value, path, value)
|
||||
@@ -185,6 +187,50 @@ export function usePage(pageKey = 'base') {
|
||||
Object.assign(status, response.data || {})
|
||||
}
|
||||
|
||||
const loadPending = async () => {
|
||||
const response = await http.get('/api/v1/config/pending')
|
||||
if (disposed) return
|
||||
notifyResponseError(response, '候选配置读取失败')
|
||||
pendingCandidate.value = response.data || null
|
||||
savedGeneration.value = 0
|
||||
savedInput = null
|
||||
const pending = pendingCandidate.value
|
||||
const section = pending?.section === 'root' ? 'base' : pending?.section
|
||||
if (pending && section === selectedSection.value) {
|
||||
editorText.value = JSON.stringify(pending.payload, null, 2)
|
||||
secretValue.value = ''
|
||||
savedInput = { text: editorText.value, secret: '' }
|
||||
savedGeneration.value = pending.sameSession ? Number(pending.generation) : 0
|
||||
}
|
||||
}
|
||||
|
||||
const managePending = async action => {
|
||||
if (!canOperate() || !pendingCandidate.value) return
|
||||
working.value = action
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
action === 'cancel' ? '取消后保留当前生效配置,候选修改不会应用。确认取消吗?' : '恢复后将候选配置绑定到当前会话,请确认已核对候选内容。',
|
||||
action === 'cancel' ? '取消候选配置' : '恢复候选配置',
|
||||
{ type: 'warning', confirmButtonText: '确认', cancelButtonText: '返回' }
|
||||
)
|
||||
const response = await http.post('/api/v1/config/pending', {
|
||||
generation: pendingCandidate.value.generation,
|
||||
candidateId: pendingCandidate.value.candidateId,
|
||||
action,
|
||||
confirmation: { confirmed: confirmed.value, method: 'recent_auth' }
|
||||
})
|
||||
notifyResponseError(response, '候选配置操作失败')
|
||||
await loadStatus()
|
||||
await loadSection()
|
||||
await loadPending()
|
||||
ElMessage.success(action === 'cancel' ? '候选已取消,可以继续编辑' : '候选已恢复,请核对后应用')
|
||||
} catch (error) {
|
||||
if (error !== 'cancel' && error !== 'close') ElMessage.error(error.message || '候选配置操作失败')
|
||||
} finally {
|
||||
working.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
const loadSection = async () => {
|
||||
const requestId = ++sectionRequestId
|
||||
const section = selectedSection.value
|
||||
@@ -388,6 +434,7 @@ export function usePage(pageKey = 'base') {
|
||||
return
|
||||
}
|
||||
if (isConfigPage || (pageKey === 'migration' && canMigrate.value)) await loadSection()
|
||||
if (isConfigPage) await loadPending()
|
||||
if (pageKey === 'backups') await loadBackups()
|
||||
if (pageKey === 'audit') await loadAudit()
|
||||
} catch (error) {
|
||||
@@ -473,9 +520,11 @@ export function usePage(pageKey = 'base') {
|
||||
const response = await http.put(`/api/v1/config/${selectedSection.value}`, request)
|
||||
notifyResponseError(response, '配置保存失败')
|
||||
savedGeneration.value = response.data?.generation || 0
|
||||
pendingCandidate.value = { ...response.data, section: selectedSection.value, sameSession: true }
|
||||
savedInput = { text: editorText.value, secret: secretValue.value }
|
||||
validationResult.value = { valid: true, generation: savedGeneration.value, issues: [] }
|
||||
await loadStatus()
|
||||
await loadPending()
|
||||
ElMessage.success(`候选配置已保存,代次 ${savedGeneration.value} 等待应用`)
|
||||
} catch (error) {
|
||||
ElMessage.error(error.message || '配置保存失败')
|
||||
@@ -485,7 +534,7 @@ export function usePage(pageKey = 'base') {
|
||||
}
|
||||
|
||||
const applyConfig = async () => {
|
||||
if (!canEdit() || !savedGeneration.value) return
|
||||
if (!canOperate() || !savedGeneration.value) return
|
||||
if (!savedInput || savedInput.text !== editorText.value || savedInput.secret !== secretValue.value) {
|
||||
invalidateCandidate()
|
||||
ElMessage.warning('填写内容已变更,请重新保存候选配置后再应用')
|
||||
@@ -493,10 +542,14 @@ export function usePage(pageKey = 'base') {
|
||||
}
|
||||
working.value = 'apply'
|
||||
try {
|
||||
const response = await http.post(`/api/v1/config/${selectedSection.value}/apply`, { generation: savedGeneration.value })
|
||||
const response = await http.post(`/api/v1/config/${selectedSection.value}/apply`, {
|
||||
generation: savedGeneration.value,
|
||||
candidateId: pendingCandidate.value?.candidateId
|
||||
})
|
||||
notifyResponseError(response, '配置应用失败')
|
||||
savedGeneration.value = 0
|
||||
await Promise.all([loadStatus(), loadSection()])
|
||||
await loadPending()
|
||||
ElMessage.success('配置已应用')
|
||||
} catch (error) {
|
||||
ElMessage.error(error.message || '配置应用失败')
|
||||
@@ -551,7 +604,17 @@ export function usePage(pageKey = 'base') {
|
||||
working.value = format === 'csv' ? 'export-csv' : 'export'
|
||||
try {
|
||||
const response = await http.post('/api/v1/audits/config', { format, limit: 500 }, { responseType: 'blob' })
|
||||
const blob = response.data instanceof Blob ? response.data : new Blob([response.data], { type: format === 'csv' ? 'text/csv' : 'application/json' })
|
||||
if (!(response instanceof Blob)) {
|
||||
throw new Error(response?.errorMsg || '审计导出响应格式不正确')
|
||||
}
|
||||
// Blob 请求也可能返回 JSON 业务错误,不能把错误响应当作审计文件下载。
|
||||
if (response.type.includes('json') || format === 'json') {
|
||||
const payload = JSON.parse(await response.text())
|
||||
if (payload && !Array.isArray(payload) && Object.hasOwn(payload, 'errorNo') && payload.errorNo !== 0) {
|
||||
throw new Error(payload.errorMsg || '审计导出失败')
|
||||
}
|
||||
}
|
||||
const blob = response
|
||||
const url = URL.createObjectURL(blob)
|
||||
const anchor = document.createElement('a')
|
||||
anchor.href = url
|
||||
@@ -604,7 +667,7 @@ export function usePage(pageKey = 'base') {
|
||||
loading, availabilityError, working, status, stateLabel, stateTagType, sectionOptions: sections,
|
||||
selectedSection, currentSection, sectionLoading, editorText, formConfig, formErrors, updateField, updateSecret,
|
||||
sectionError, sensitiveHint, secretField, secretValue,
|
||||
confirmed, savedGeneration, validationResult, canWrite, canRollback, canAudit, canExportAudit,
|
||||
confirmed, savedGeneration, pendingCandidate, managePending, validationResult, canWrite, canRollback, canAudit, canExportAudit,
|
||||
backupsLoading, backupsError, backups, rollbackGeneration, rollbackConfirmed, rollbackPreview,
|
||||
auditLoading, auditError, auditItems, loadAll, loadSection, validateConfig, saveConfig, applyConfig,
|
||||
loadBackups, previewRollback, executeRollback, loadAudit, exportAudit, formatTime,
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
<el-tabs class="custom-tabs">
|
||||
<el-tab-pane v-for="entry in pluginEntries" :key="entry.src" :label="entry.name">
|
||||
<SpamBlockSettings v-if="entry.logicalID === 'spam_block'" />
|
||||
<TelegramSettings v-else-if="entry.logicalID === 'telegram_push'" />
|
||||
<div v-else class="iframe-wrapper">
|
||||
<iframe
|
||||
:src="entry.src"
|
||||
@@ -33,6 +34,7 @@
|
||||
<script setup>
|
||||
import { usePage } from './PluginSettings.js'
|
||||
import SpamBlockSettings from './SpamBlockSettings/SpamBlockSettings.vue'
|
||||
import TelegramSettings from './TelegramSettings/TelegramSettings.vue'
|
||||
|
||||
const {
|
||||
lang,
|
||||
|
||||
+51
-6
@@ -1,5 +1,5 @@
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { http } from '@/utils/axios'
|
||||
import { useGlobalStatusStore } from '@/stores/useGlobalStatusStore'
|
||||
|
||||
@@ -18,6 +18,8 @@ export function useSpamBlockSettings() {
|
||||
const errorMessage = ref('')
|
||||
const confirmed = ref(false)
|
||||
const savedGeneration = ref(0)
|
||||
const pendingCandidate = ref(null)
|
||||
let savedInput = ''
|
||||
const activeGeneration = ref(0)
|
||||
const validationResult = ref(null)
|
||||
const pluginsPayload = ref(null)
|
||||
@@ -42,15 +44,24 @@ export function useSpamBlockSettings() {
|
||||
loading.value = true
|
||||
errorMessage.value = ''
|
||||
try {
|
||||
const [statusResponse, pluginsResponse] = await Promise.all([
|
||||
const [statusResponse, pluginsResponse, pendingResponse] = await Promise.all([
|
||||
http.get('/api/v1/config/status'),
|
||||
http.get('/api/v1/config/plugins')
|
||||
http.get('/api/v1/config/plugins'),
|
||||
http.get('/api/v1/config/pending')
|
||||
])
|
||||
notifyResponseError(statusResponse, '配置状态读取失败')
|
||||
notifyResponseError(pluginsResponse, '插件配置读取失败')
|
||||
notifyResponseError(pendingResponse, '候选配置读取失败')
|
||||
pendingCandidate.value = pendingResponse.data || null
|
||||
savedGeneration.value = 0
|
||||
activeGeneration.value = Number(statusResponse.data?.activeGeneration || 0)
|
||||
pluginsPayload.value = pluginsResponse.data || null
|
||||
if (pendingCandidate.value?.section === 'plugins') {
|
||||
pluginsPayload.value = pendingCandidate.value.payload
|
||||
if (pendingCandidate.value.sameSession) savedGeneration.value = Number(pendingCandidate.value.generation)
|
||||
}
|
||||
applySettings(pluginsPayload.value?.plugins?.spam_block?.settings)
|
||||
savedInput = JSON.stringify(settings)
|
||||
} catch (error) {
|
||||
errorMessage.value = error.message || '垃圾邮件插件配置读取失败'
|
||||
} finally {
|
||||
@@ -66,6 +77,7 @@ export function useSpamBlockSettings() {
|
||||
Object.values(payload.plugins).forEach(plugin => {
|
||||
if (isObject(plugin)) {
|
||||
delete plugin.secretStatus
|
||||
delete plugin.settingsConfigured
|
||||
}
|
||||
})
|
||||
if (!isObject(payload.plugins.spam_block)) {
|
||||
@@ -89,6 +101,7 @@ export function useSpamBlockSettings() {
|
||||
})
|
||||
|
||||
const validate = async () => {
|
||||
if (!canWrite() || loading.value || working.value || errorMessage.value || pendingCandidate.value) return
|
||||
working.value = 'validate'
|
||||
try {
|
||||
const response = await http.post('/api/v1/config/plugins/validate', buildRequest())
|
||||
@@ -105,12 +118,16 @@ export function useSpamBlockSettings() {
|
||||
}
|
||||
|
||||
const save = async () => {
|
||||
if (!canWrite() || loading.value || working.value || errorMessage.value || pendingCandidate.value) return
|
||||
working.value = 'save'
|
||||
try {
|
||||
const response = await http.put('/api/v1/config/plugins', buildRequest())
|
||||
notifyResponseError(response, '插件配置保存失败')
|
||||
savedGeneration.value = Number(response.data?.generation || 0)
|
||||
pendingCandidate.value = { ...response.data, section: 'plugins', sameSession: true }
|
||||
savedInput = JSON.stringify(settings)
|
||||
validationResult.value = { valid: true, generation: savedGeneration.value, issues: [] }
|
||||
await load()
|
||||
ElMessage.success(`垃圾邮件插件配置已保存,代次 ${savedGeneration.value} 等待应用`)
|
||||
} catch (error) {
|
||||
ElMessage.error(error.message || '插件配置保存失败')
|
||||
@@ -120,10 +137,17 @@ export function useSpamBlockSettings() {
|
||||
}
|
||||
|
||||
const apply = async () => {
|
||||
if (!savedGeneration.value) return
|
||||
if (!canWrite() || loading.value || working.value || !savedGeneration.value) return
|
||||
if (savedInput !== JSON.stringify(settings)) {
|
||||
ElMessage.warning('填写内容与候选不一致,请刷新查看候选,或先取消候选再修改')
|
||||
return
|
||||
}
|
||||
working.value = 'apply'
|
||||
try {
|
||||
const response = await http.post('/api/v1/config/plugins/apply', { generation: savedGeneration.value })
|
||||
const response = await http.post('/api/v1/config/plugins/apply', {
|
||||
generation: savedGeneration.value,
|
||||
candidateId: pendingCandidate.value?.candidateId
|
||||
})
|
||||
notifyResponseError(response, '插件配置应用失败')
|
||||
savedGeneration.value = 0
|
||||
await load()
|
||||
@@ -135,6 +159,25 @@ export function useSpamBlockSettings() {
|
||||
}
|
||||
}
|
||||
|
||||
const managePending = async action => {
|
||||
if (!canWrite() || loading.value || working.value || !pendingCandidate.value) return
|
||||
working.value = action
|
||||
try {
|
||||
await ElMessageBox.confirm(action === 'cancel' ? '取消候选后不会影响当前生效配置,确认继续吗?' : '确认将已保存候选恢复到当前会话吗?', '管理候选配置', { type: 'warning', confirmButtonText: '确认', cancelButtonText: '返回' })
|
||||
const response = await http.post('/api/v1/config/pending', {
|
||||
generation: pendingCandidate.value.generation, action,
|
||||
candidateId: pendingCandidate.value.candidateId,
|
||||
confirmation: { confirmed: confirmed.value, method: 'recent_auth' }
|
||||
})
|
||||
notifyResponseError(response, '候选配置操作失败')
|
||||
await load()
|
||||
} catch (error) {
|
||||
if (error !== 'cancel' && error !== 'close') ElMessage.error(error.message || '候选配置操作失败')
|
||||
} finally {
|
||||
working.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
|
||||
return {
|
||||
@@ -143,6 +186,8 @@ export function useSpamBlockSettings() {
|
||||
errorMessage,
|
||||
confirmed,
|
||||
savedGeneration,
|
||||
pendingCandidate,
|
||||
managePending,
|
||||
validationResult,
|
||||
settings,
|
||||
canWrite,
|
||||
@@ -151,4 +196,4 @@ export function useSpamBlockSettings() {
|
||||
save,
|
||||
apply
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
-8
@@ -6,7 +6,7 @@
|
||||
<h4>垃圾邮件拦截</h4>
|
||||
<p>配置模型接口和识别阈值,配置会通过统一配置管理器校验后再应用。</p>
|
||||
</div>
|
||||
<el-button size="small" plain :loading="loading" @click="load">刷新</el-button>
|
||||
<el-button size="small" plain :loading="loading" :disabled="!!working" @click="load">刷新</el-button>
|
||||
</div>
|
||||
|
||||
<el-alert
|
||||
@@ -25,11 +25,12 @@
|
||||
show-icon
|
||||
/>
|
||||
|
||||
<el-alert v-if="pendingCandidate" title="存在待应用候选,编辑已锁定。刷新可恢复候选,需要修改时请先取消。" type="warning" :closable="false" show-icon />
|
||||
<el-form label-position="top" class="spam-form">
|
||||
<el-form-item label="模型 API 接口地址">
|
||||
<el-input
|
||||
v-model="settings.url"
|
||||
:disabled="!canWrite()"
|
||||
:disabled="!canWrite() || !!working || !!pendingCandidate || loading"
|
||||
placeholder="例如:https://model.example.com/v1/predict"
|
||||
clearable
|
||||
/>
|
||||
@@ -38,7 +39,7 @@
|
||||
<el-form-item label="请求超时时间(毫秒)">
|
||||
<el-input-number
|
||||
v-model="settings.timeout"
|
||||
:disabled="!canWrite()"
|
||||
:disabled="!canWrite() || !!working || !!pendingCandidate || loading"
|
||||
:min="100"
|
||||
:max="120000"
|
||||
:step="100"
|
||||
@@ -48,7 +49,7 @@
|
||||
<el-form-item label="识别阈值">
|
||||
<el-input-number
|
||||
v-model="settings.threshold"
|
||||
:disabled="!canWrite()"
|
||||
:disabled="!canWrite() || !!working || !!pendingCandidate || loading"
|
||||
:min="0"
|
||||
:max="100"
|
||||
:step="0.01"
|
||||
@@ -63,11 +64,13 @@
|
||||
我已确认这是受控变更,并允许使用最近认证完成高风险配置操作
|
||||
</el-checkbox>
|
||||
<div class="spam-actions">
|
||||
<el-button :loading="working === 'validate'" :disabled="!canWrite()" @click="validate">只验证</el-button>
|
||||
<el-button type="primary" :loading="working === 'save'" :disabled="!canWrite()" @click="save">保存候选配置</el-button>
|
||||
<el-button type="success" plain :loading="working === 'apply'" :disabled="!canWrite() || !savedGeneration" @click="apply">
|
||||
<el-button :loading="working === 'validate'" :disabled="!canWrite() || !!working || !!pendingCandidate || loading" @click="validate">只验证</el-button>
|
||||
<el-button type="primary" :loading="working === 'save'" :disabled="!canWrite() || !!working || !!pendingCandidate || loading" @click="save">保存候选配置</el-button>
|
||||
<el-button type="success" plain :loading="working === 'apply'" :disabled="!canWrite() || !savedGeneration || !!working || loading" @click="apply">
|
||||
应用{{ savedGeneration ? `代次 ${savedGeneration}` : '' }}
|
||||
</el-button>
|
||||
<el-button v-if="canWrite() && pendingCandidate && !pendingCandidate.sameSession" :disabled="!!working || !confirmed" @click="managePending('resume')">恢复候选到当前会话</el-button>
|
||||
<el-button v-if="canWrite() && pendingCandidate" type="warning" plain :disabled="!!working || pendingCandidate.committed" @click="managePending('cancel')">取消候选配置</el-button>
|
||||
</div>
|
||||
<div v-if="validationResult" class="spam-result" :class="validationResult.valid ? 'is-success' : 'is-error'">
|
||||
<strong>{{ validationResult.valid ? '验证通过' : '验证未通过' }}</strong>
|
||||
@@ -89,6 +92,8 @@ const {
|
||||
errorMessage,
|
||||
confirmed,
|
||||
savedGeneration,
|
||||
pendingCandidate,
|
||||
managePending,
|
||||
validationResult,
|
||||
settings,
|
||||
canWrite,
|
||||
@@ -99,4 +104,4 @@ const {
|
||||
} = useSpamBlockSettings()
|
||||
</script>
|
||||
|
||||
<style scoped src="./SpamBlockSettings.css"></style>
|
||||
<style scoped src="./SpamBlockSettings.css"></style>
|
||||
@@ -0,0 +1,43 @@
|
||||
.telegram-settings {
|
||||
max-width: 760px;
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.telegram-header {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.telegram-header h4 {
|
||||
margin: 0 0 8px;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.telegram-header p,
|
||||
.telegram-hint {
|
||||
color: var(--el-text-color-secondary);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.telegram-header a {
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
|
||||
.telegram-settings .el-alert {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.telegram-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.telegram-actions .el-button {
|
||||
margin-left: 0;
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
import { computed, onMounted, onBeforeUnmount, reactive, ref } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { http } from '@/utils/axios'
|
||||
|
||||
const endpoint = '/api/v1/plugin/settings/telegram_push'
|
||||
const defaults = {
|
||||
chatId: '',
|
||||
showContent: false,
|
||||
spoilerContent: false,
|
||||
sendAttachments: false,
|
||||
disableLinkPreview: true
|
||||
}
|
||||
|
||||
export function useTelegramSettings() {
|
||||
const settings = reactive({ ...defaults })
|
||||
const version = ref(0)
|
||||
const ready = ref(false)
|
||||
const working = ref('')
|
||||
const errorMessage = ref('')
|
||||
const botUsername = ref('')
|
||||
let disposed = false
|
||||
const botLink = computed(() => /^[a-zA-Z0-9_]{5,32}$/.test(botUsername.value)
|
||||
? `https://t.me/${botUsername.value}` : '')
|
||||
|
||||
const checkResponse = (response, fallback) => {
|
||||
if (!response || response.errorNo !== 0) throw new Error(response?.errorMsg || fallback)
|
||||
return response.data
|
||||
}
|
||||
const acceptSettings = data => {
|
||||
if (!data?.settings || !Number.isSafeInteger(data.version) || data.version < 0) {
|
||||
throw new Error('插件设置响应不完整,请重新加载')
|
||||
}
|
||||
for (const key of Object.keys(defaults)) {
|
||||
settings[key] = key === 'chatId' ? String(data.settings[key] || '') : data.settings[key] === true
|
||||
}
|
||||
version.value = data.version
|
||||
ready.value = true
|
||||
}
|
||||
const load = async () => {
|
||||
if (working.value || disposed) return
|
||||
working.value = 'load'
|
||||
ready.value = false
|
||||
errorMessage.value = ''
|
||||
try {
|
||||
const response = await http.get(`${endpoint}/user`)
|
||||
if (disposed) return
|
||||
acceptSettings(checkResponse(response, '读取 Telegram 设置失败'))
|
||||
try {
|
||||
const info = checkResponse(await http.get(`${endpoint}/bot`), '读取机器人信息失败')
|
||||
if (!disposed) botUsername.value = info?.username || ''
|
||||
} catch {
|
||||
// 机器人不可用不应阻止用户停用通知或调整本人设置。
|
||||
botUsername.value = ''
|
||||
}
|
||||
} catch (error) {
|
||||
if (!disposed) errorMessage.value = error.message || '读取 Telegram 设置失败'
|
||||
} finally {
|
||||
working.value = ''
|
||||
}
|
||||
}
|
||||
const submit = async action => {
|
||||
if (!ready.value || working.value || disposed) return
|
||||
const chatId = settings.chatId.trim()
|
||||
if ((chatId && !/^-?[1-9][0-9]{0,18}$/.test(chatId)) || (action === 'test' && !chatId)) {
|
||||
errorMessage.value = '请输入有效的 Telegram 聊天 ID;留空可保存为停用状态'
|
||||
return
|
||||
}
|
||||
working.value = action
|
||||
errorMessage.value = ''
|
||||
// 仅发送本人可维护的白名单字段,不接收插件 HTML 提供的路由或身份。
|
||||
const payload = { settings: { ...settings, chatId }, version: version.value }
|
||||
try {
|
||||
const response = action === 'test'
|
||||
? await http.post(`${endpoint}/test`, payload)
|
||||
: await http.put(`${endpoint}/user`, payload)
|
||||
if (disposed) return
|
||||
const data = checkResponse(response, action === 'test' ? '发送测试消息失败' : '保存 Telegram 设置失败')
|
||||
if (action !== 'test') acceptSettings(data)
|
||||
ElMessage.success(action === 'test' ? '测试消息已发送' : 'Telegram 设置已保存')
|
||||
} catch (error) {
|
||||
if (!disposed) errorMessage.value = error.message || 'Telegram 操作失败'
|
||||
} finally {
|
||||
working.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
onBeforeUnmount(() => { disposed = true })
|
||||
return { settings, version, ready, working, errorMessage, botLink, load, submit }
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<template>
|
||||
<section class="telegram-settings" aria-label="Telegram 推送设置">
|
||||
<header class="telegram-header">
|
||||
<div>
|
||||
<h4>Telegram 推送设置</h4>
|
||||
<p>只配置当前账户的邮件通知,聊天 ID 留空可停用推送。</p>
|
||||
</div>
|
||||
<a v-if="botLink" :href="botLink" target="_blank" rel="noopener noreferrer">联系机器人</a>
|
||||
</header>
|
||||
<el-alert v-if="errorMessage" :title="errorMessage" type="error" :closable="false" show-icon />
|
||||
<el-form :model="settings" label-position="top" :disabled="!ready || !!working">
|
||||
<el-form-item label="Telegram 聊天 ID">
|
||||
<el-input v-model="settings.chatId" placeholder="填写聊天 ID,留空停用" maxlength="20" />
|
||||
</el-form-item>
|
||||
<el-form-item label="显示邮件内容">
|
||||
<el-switch v-model="settings.showContent" />
|
||||
</el-form-item>
|
||||
<el-form-item label="隐藏正文,点击后显示">
|
||||
<el-switch v-model="settings.spoilerContent" :disabled="!settings.showContent" />
|
||||
</el-form-item>
|
||||
<el-form-item label="发送附件">
|
||||
<el-switch v-model="settings.sendAttachments" />
|
||||
</el-form-item>
|
||||
<el-form-item label="禁用链接预览">
|
||||
<el-switch v-model="settings.disableLinkPreview" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<p class="telegram-hint">启用正文或附件后,相应内容会发送到 Telegram,请确认聊天对象和隐私需求。</p>
|
||||
<footer class="telegram-actions">
|
||||
<el-button :disabled="!!working" @click="load">重新加载</el-button>
|
||||
<el-button :disabled="!ready || !!working || !settings.chatId.trim()" @click="submit('test')">发送测试消息</el-button>
|
||||
<el-button type="primary" :disabled="!ready || !!working" @click="submit('save')">保存设置</el-button>
|
||||
</footer>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { useTelegramSettings } from './TelegramSettings.js'
|
||||
|
||||
const { settings, ready, working, errorMessage, botLink, load, submit } = useTelegramSettings()
|
||||
</script>
|
||||
|
||||
<style scoped src="./TelegramSettings.css"></style>
|
||||
@@ -53,7 +53,7 @@ export function usePage() {
|
||||
|
||||
reflushGroupInfos()
|
||||
|
||||
const addRuleForm = reactive({
|
||||
const newRuleForm = () => ({
|
||||
"id": 0,
|
||||
"name": "",
|
||||
"sort": 0,
|
||||
@@ -61,6 +61,15 @@ export function usePage() {
|
||||
"action": "",
|
||||
"params": ""
|
||||
})
|
||||
const addRuleForm = reactive(newRuleForm())
|
||||
const createRule = () => {
|
||||
Object.assign(addRuleForm, newRuleForm())
|
||||
dialogVisible.value = true
|
||||
}
|
||||
const cancelRule = () => {
|
||||
dialogVisible.value = false
|
||||
Object.assign(addRuleForm, newRuleForm())
|
||||
}
|
||||
|
||||
const delRule = function (id) {
|
||||
http.post("/api/v1/rule/del", {"id": id}).then((res) => {
|
||||
@@ -76,7 +85,7 @@ export function usePage() {
|
||||
const editRule = function (ruleInfo) {
|
||||
addRuleForm.id = ruleInfo.id
|
||||
addRuleForm.name = ruleInfo.name
|
||||
addRuleForm.rules = ruleInfo.rules || []
|
||||
addRuleForm.rules = (ruleInfo.rules || []).map(rule => ({ ...rule }))
|
||||
addRuleForm.action = ruleInfo.action
|
||||
addRuleForm.params = ruleInfo.params
|
||||
addRuleForm.sort = ruleInfo.sort
|
||||
@@ -108,13 +117,7 @@ export function usePage() {
|
||||
})
|
||||
} else {
|
||||
init()
|
||||
dialogVisible.value = false
|
||||
addRuleForm.id = 0
|
||||
addRuleForm.name = ""
|
||||
addRuleForm.sort = 0
|
||||
addRuleForm.rules = [{"field": "", "type": "", "rule": ""}]
|
||||
addRuleForm.action = ""
|
||||
addRuleForm.params = ""
|
||||
cancelRule()
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -146,6 +149,8 @@ export function usePage() {
|
||||
addRuleForm,
|
||||
delRule,
|
||||
editRule,
|
||||
createRule,
|
||||
cancelRule,
|
||||
removeRuleLine,
|
||||
addRule,
|
||||
submitRule,
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<template #default="scope">
|
||||
<div class="row-actions">
|
||||
<el-button size="small" type="primary" :icon="Edit" circle text @click="editRule(scope.row)"/>
|
||||
<el-popconfirm confirm-button-text="Yes" cancel-button-text="No" :icon="InfoFilled"
|
||||
<el-popconfirm confirm-button-text="确认" cancel-button-text="取消" :icon="InfoFilled"
|
||||
@confirm="delRule(scope.row.id)" icon-color="#ef4444" :title="lang.del_rule_confirm">
|
||||
<template #reference>
|
||||
<el-button size="small" type="danger" :icon="Delete" circle text/>
|
||||
@@ -32,17 +32,17 @@
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<el-button type="primary" @click="dialogVisible = true" class="add-btn">
|
||||
<el-button type="primary" @click="createRule" class="add-btn">
|
||||
<el-icon><Plus /></el-icon> {{ lang.new_rule }}
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<el-dialog v-model="dialogVisible" :title="addRuleForm.id > 0 ? 'Edit Rule' : lang.new_rule" width="700px" class="premium-dialog">
|
||||
<el-dialog v-model="dialogVisible" :title="addRuleForm.id > 0 ? '编辑规则' : lang.new_rule" width="700px" class="premium-dialog">
|
||||
<div class="dialog-content">
|
||||
<el-form :model="addRuleForm" label-position="top">
|
||||
<div class="form-row">
|
||||
<el-form-item :label="lang.rule_name" class="flex-grow">
|
||||
<el-input v-model="addRuleForm.name" placeholder="Rule Name"/>
|
||||
<el-input v-model="addRuleForm.name" placeholder="规则名称"/>
|
||||
</el-form-item>
|
||||
<el-form-item :label="lang.rule_priority" class="w-32">
|
||||
<el-input v-model="addRuleForm.sort" type="number" oninput="value=value.replace(/[^\-\d]/g, '')"/>
|
||||
@@ -50,11 +50,11 @@
|
||||
</div>
|
||||
|
||||
<el-divider class="custom-divider"/>
|
||||
<div class="section-title">{{ lang.rule_desc }} (Conditions)</div>
|
||||
<div class="section-title">{{ lang.rule_desc }}(匹配条件)</div>
|
||||
|
||||
<div class="rules-list">
|
||||
<div v-for="(rule, index) in addRuleForm.rules" :key="index" class="rule-line">
|
||||
<el-select v-model="rule.field" placeholder="Field" class="w-32">
|
||||
<el-select v-model="rule.field" placeholder="邮件字段" class="w-32">
|
||||
<el-option key="From" :label="lang.from" value="From"/>
|
||||
<el-option key="Subject" :label="lang.subject" value="Subject"/>
|
||||
<el-option key="To" :label="lang.to" value="To"/>
|
||||
@@ -97,7 +97,7 @@
|
||||
</div>
|
||||
<template #footer>
|
||||
<span class="dialog-footer">
|
||||
<el-button @click="dialogVisible = false">{{ lang.cancel }}</el-button>
|
||||
<el-button @click="cancelRule">{{ lang.cancel }}</el-button>
|
||||
<el-button type="primary" @click="submitRule()">
|
||||
{{ lang.submit }}
|
||||
</el-button>
|
||||
@@ -116,6 +116,8 @@ const {
|
||||
ActionName,
|
||||
Edit,
|
||||
editRule,
|
||||
createRule,
|
||||
cancelRule,
|
||||
InfoFilled,
|
||||
delRule,
|
||||
Delete,
|
||||
|
||||
@@ -56,6 +56,7 @@ export function usePage() {
|
||||
let lastNotificationKey = ''
|
||||
let lastNotificationAt = 0
|
||||
const bindForm = reactive({ email: '', type: 'backup', challengeId: '', bindingId: 0, code: '' })
|
||||
let bindingChallenge = null
|
||||
|
||||
const ruleForm = reactive({ current_pwd: '', new_pwd: '', new_pwd2: '' })
|
||||
const rules = reactive({
|
||||
@@ -210,32 +211,45 @@ export function usePage() {
|
||||
}
|
||||
|
||||
const bindExternalEmail = async () => {
|
||||
if (externalLoading.value) return
|
||||
if (!bindForm.email.trim()) {
|
||||
notify('请输入外部安全邮箱')
|
||||
return
|
||||
}
|
||||
externalLoading.value = true
|
||||
try {
|
||||
const res = await http.post('/api/v1/security/external-email/bind', { email: bindForm.email.trim(), type: bindForm.type })
|
||||
if (res.errorNo !== 0) throw new Error(res.errorMsg || '外部邮箱绑定失败')
|
||||
bindForm.challengeId = res.data.challenge_id
|
||||
bindForm.bindingId = res.data.id
|
||||
const prompt = await ElMessageBox.prompt(`验证码已发送到 ${res.data.email},请输入验证码`, '验证外部邮箱', {
|
||||
const email = bindForm.email.trim()
|
||||
const type = bindForm.type
|
||||
if (!bindingChallenge || bindingChallenge.email !== email || bindingChallenge.type !== type) {
|
||||
bindingChallenge = null
|
||||
bindForm.challengeId = ''
|
||||
bindForm.bindingId = 0
|
||||
const res = await http.post('/api/v1/security/external-email/bind', { email, type })
|
||||
if (res.errorNo !== 0) throw new Error(res.errorMsg || '外部邮箱绑定失败')
|
||||
if (!res.data?.challenge_id || !res.data?.id) throw new Error('外部邮箱验证信息不完整')
|
||||
bindingChallenge = { email, type, maskedEmail: res.data.email, id: res.data.id, challengeId: res.data.challenge_id }
|
||||
bindForm.challengeId = bindingChallenge.challengeId
|
||||
bindForm.bindingId = bindingChallenge.id
|
||||
}
|
||||
const challenge = bindingChallenge
|
||||
const prompt = await ElMessageBox.prompt(`验证码已发送到 ${challenge.maskedEmail},请输入验证码`, '验证外部邮箱', {
|
||||
confirmButtonText: '验证', cancelButtonText: '取消', inputPlaceholder: '请输入验证码',
|
||||
})
|
||||
bindForm.code = String(prompt.value).trim()
|
||||
const verified = await http.post('/api/v1/security/external-email/verify', {
|
||||
id: bindForm.challengeId, binding_id: bindForm.bindingId, email: bindForm.email.trim(), code: bindForm.code,
|
||||
id: challenge.challengeId, binding_id: challenge.id, email: challenge.email, code: bindForm.code,
|
||||
})
|
||||
if (verified.errorNo !== 0) throw new Error(verified.errorMsg || '外部邮箱验证失败')
|
||||
bindForm.email = ''
|
||||
bindForm.challengeId = ''
|
||||
bindForm.bindingId = 0
|
||||
bindingChallenge = null
|
||||
await loadSecurityData()
|
||||
notify('外部安全邮箱绑定成功', 'success')
|
||||
} catch (error) {
|
||||
if (error !== 'cancel' && error !== 'close') notify(error?.message || '外部邮箱绑定失败')
|
||||
} finally {
|
||||
bindForm.code = ''
|
||||
externalLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ export function usePage() {
|
||||
}
|
||||
|
||||
const setProtocolEnabled = async (item, enabled) => {
|
||||
if (protocolLoading.value || item.enabled === enabled) return
|
||||
const previous = item.enabled
|
||||
item.enabled = enabled
|
||||
protocolLoading.value = true
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
<div class="protocol-actions">
|
||||
<el-switch
|
||||
v-model="item.enabled"
|
||||
:model-value="item.enabled"
|
||||
:loading="protocolLoading"
|
||||
active-text="开启"
|
||||
inactive-text="关闭"
|
||||
|
||||
Reference in new issue
Block a user