feat(shell): 插件密码加密、失败熔断与客户端自动更新(v1.11.3)
- 插件配置中 format=password 字段改为 AES-256-GCM 密文落盘(本机密钥,历史明文自动迁移) - 同一插件连续失败 3 次自动禁用(仅统计进程启动后失败),升级自动解除 - 检测到新版本后台下载,空闲窗口提前提示并自动重启升级,设置页可配安全窗口
This commit is contained in:
@@ -30,16 +30,25 @@
|
||||
<!-- 壳子更新提示:已就绪重启更新 / 下载失败重试 / 发现新版本可下载(下载进度改用弹窗) -->
|
||||
<div v-if="updBarVisible" class="update-bar">
|
||||
<template v-if="shellUpdate.downloaded">
|
||||
<span class="upd-txt">发现新版本 <b>v{{ shellUpdate.new }}</b><em v-if="shellUpdate.notes">{{ shellUpdate.notes }}</em></span>
|
||||
<el-button size="small" type="primary" round :loading="updating" @click="doShellUpdate">重启更新</el-button>
|
||||
<span class="upd-txt">
|
||||
新版本 <b>v{{ shellUpdate.new }}</b> 已就绪
|
||||
<em v-if="shellUpdate.auto_update && shellUpdate.auto_notice_pending">即将自动重启升级…</em>
|
||||
<em v-else-if="shellUpdate.auto_update">等待空闲时自动升级(无任务且近期无定时任务)</em>
|
||||
<em v-else-if="shellUpdate.notes">{{ shellUpdate.notes }}</em>
|
||||
</span>
|
||||
<el-button size="small" type="primary" round :loading="updating" @click="doShellUpdate">立即升级</el-button>
|
||||
</template>
|
||||
<template v-else-if="updDl.status === 'failed'">
|
||||
<span class="upd-txt">新版本下载失败<em>{{ updDl.error }}</em></span>
|
||||
<el-button size="small" type="primary" round :loading="downloading" @click="onShellDownload">重试</el-button>
|
||||
</template>
|
||||
<template v-else-if="shellUpdate.available">
|
||||
<span class="upd-txt">发现新版本 <b>v{{ shellUpdate.latest }}</b><em v-if="shellUpdate.notes">{{ shellUpdate.notes }}</em></span>
|
||||
<div class="upd-actions">
|
||||
<span class="upd-txt">
|
||||
发现新版本 <b>v{{ shellUpdate.latest }}</b>
|
||||
<em v-if="shellUpdate.auto_update">正在自动下载…</em>
|
||||
<em v-else-if="shellUpdate.notes">{{ shellUpdate.notes }}</em>
|
||||
</span>
|
||||
<div v-if="!shellUpdate.auto_update" class="upd-actions">
|
||||
<el-button size="small" type="primary" round :loading="downloading" @click="onShellDownload">立即下载</el-button>
|
||||
<el-button size="small" round @click="shellDismissed = true">暂不</el-button>
|
||||
</div>
|
||||
|
||||
@@ -37,6 +37,11 @@ export async function rollbackPlugin(id) {
|
||||
return j(`/api/plugins/rollback/${encodeURIComponent(id)}`, { method: 'POST' })
|
||||
}
|
||||
|
||||
// ===== 插件失败熔断:连续失败自动禁用后,人工恢复 =====
|
||||
export async function resetPluginHealth(id) {
|
||||
return j(`/api/plugins/${encodeURIComponent(id)}/health/reset`, { method: 'POST' })
|
||||
}
|
||||
|
||||
// ===== 场景配置方案(多配置,SQLite 存储) =====
|
||||
export async function listPluginConfigs(pluginId) {
|
||||
return j(`/api/plugin-configs?plugin_id=${encodeURIComponent(pluginId)}`)
|
||||
|
||||
@@ -57,8 +57,8 @@
|
||||
<div class="cmp-ops">
|
||||
<el-button size="small" :loading="shellChecking" @click="onShellCheck()">检查</el-button>
|
||||
<el-button v-if="shellUpdate.downloaded" size="small" type="primary" :loading="updating"
|
||||
@click="doShellUpdate">重启更新</el-button>
|
||||
<el-button v-else-if="shellUpdate.available" size="small" type="primary" :loading="downloading"
|
||||
@click="doShellUpdate">{{ shellUpdate.auto_update ? '立即升级' : '重启更新' }}</el-button>
|
||||
<el-button v-else-if="shellUpdate.available && !shellUpdate.auto_update" size="small" type="primary" :loading="downloading"
|
||||
@click="onShellDownload">下载更新</el-button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -408,8 +408,9 @@ async function onSyncPlugins() {
|
||||
// ===== 状态标签 =====
|
||||
const shellTagText = computed(() => {
|
||||
const s = shellUpdate.value
|
||||
if (s.downloaded) return '待重启生效'
|
||||
if (s.available) return '有新版本'
|
||||
if (s.auto_notice_pending) return '即将自动升级'
|
||||
if (s.downloaded) return s.auto_update ? '等待空闲升级' : '待重启生效'
|
||||
if (s.available) return s.auto_update ? '自动下载中' : '有新版本'
|
||||
if (s.current) return '已是最新'
|
||||
return '未打包'
|
||||
})
|
||||
|
||||
@@ -61,6 +61,21 @@
|
||||
<button class="b-close" @click="closeBanner" title="关闭">✕</button>
|
||||
</section>
|
||||
|
||||
<!-- 失败熔断:连续失败已自动禁用,给排查信息与恢复入口(升级插件也会自动解除) -->
|
||||
<section v-if="plugin.health && plugin.health.tripped" class="banner err health-banner">
|
||||
<span class="b-ic">⊘</span>
|
||||
<div class="b-body">
|
||||
<b>该场景连续失败 {{ plugin.health.fails }} 次,已自动停止执行</b>
|
||||
<span>最近错误:{{ plugin.health.error || '未知' }} 排查后点「恢复」重新启用;插件升级到新版本也会自动解除</span>
|
||||
</div>
|
||||
<button class="btn" :disabled="restoringHealth" @click="doResetHealth">
|
||||
{{ restoringHealth ? '恢复中…' : '恢复' }}
|
||||
</button>
|
||||
</section>
|
||||
<div v-else-if="plugin.health && plugin.health.fails" class="health-hint">
|
||||
连续失败 {{ plugin.health.fails }}/{{ plugin.health.threshold }} 次,达到 {{ plugin.health.threshold }} 次将自动禁用
|
||||
</div>
|
||||
|
||||
<!-- 运行备注:账号 × 插件 唯一,本机保存并回传中心机;执行时随本次运行记录上报
|
||||
备注可能较长(多行),列表只放一行摘要,查看/编辑统一走弹窗 -->
|
||||
<div class="note-bar">
|
||||
@@ -198,13 +213,15 @@ import { Refresh, ArrowLeft, ArrowRight } from '@element-plus/icons-vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { store } from '../store'
|
||||
import { getRun, fetchRuns, fetchMeta, listRollbacks, rollbackPlugin, fetchQueue,
|
||||
fetchPluginNotes, savePluginNote } from '../api'
|
||||
fetchPluginNotes, savePluginNote, resetPluginHealth } from '../api'
|
||||
import { usePluginSync } from '../composables/usePluginSync'
|
||||
import LogPanel from './LogPanel.vue'
|
||||
import RunIndicator from './RunIndicator.vue'
|
||||
import PageHead from './PageHead.vue'
|
||||
import { durText, fmtTime, cleanDesc, splitDesc, pluginChannelTag, fmtMemMb } from '../utils/format'
|
||||
import { pluginTimeoutInfo, runTimeoutState } from '../utils/timeout'
|
||||
|
||||
const { refreshMeta } = usePluginSync()
|
||||
const plugin = computed(() => store.plugins.find((p) => p.id === store.selectedId) || null)
|
||||
// 单次执行超时:插件声明值优先,未声明跟随设置页(与运行侧 runTimeoutFor 同口径)
|
||||
const tmo = computed(() => pluginTimeoutInfo(plugin.value, runTimeoutState.effective))
|
||||
@@ -583,6 +600,22 @@ async function doRollback() {
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 失败熔断恢复 =====
|
||||
const restoringHealth = ref(false)
|
||||
async function doResetHealth() {
|
||||
if (!plugin.value || restoringHealth.value) return
|
||||
restoringHealth.value = true
|
||||
try {
|
||||
await resetPluginHealth(plugin.value.id)
|
||||
await refreshMeta() // 重新拉 /api/meta:health 状态与插件清单同步刷新
|
||||
ElMessage.success('已恢复,可以重新执行')
|
||||
} catch (e) {
|
||||
ElMessage.error('恢复失败:' + (e.message || e))
|
||||
} finally {
|
||||
restoringHealth.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 完成时拉取后端摘要填充横幅(触发源无关:插件界面/定时任务触发的运行同样回填)
|
||||
watch(
|
||||
() => store.lastResult,
|
||||
@@ -618,6 +651,15 @@ function closeBanner() {
|
||||
padding: 0 24px 18px;
|
||||
}
|
||||
.banner { margin: 14px 0 12px; }
|
||||
/* 失败熔断:横幅文字允许换行(结果横幅默认单行省略,熔断要展示最近错误) */
|
||||
.health-banner { margin: 14px 0 0; }
|
||||
.health-banner .b-body span { white-space: normal; }
|
||||
.health-hint {
|
||||
margin: 12px 0 0; padding: 8px var(--space-3);
|
||||
font: 400 11.5px/1.6 var(--f-cn); color: var(--warn-ink);
|
||||
background: var(--warn-soft); border: 1px solid var(--warn-line);
|
||||
border-radius: var(--r-card);
|
||||
}
|
||||
|
||||
/* ---------- 页头内的场景身份 ---------- */
|
||||
.p-name { display: inline-flex; align-items: center; gap: var(--space-2); }
|
||||
|
||||
@@ -41,6 +41,10 @@
|
||||
<span class="sc-tags">
|
||||
<em class="sc-tag ver">v{{ plugin.version }}</em>
|
||||
<em v-if="chan" class="sc-tag chan" :class="chan.kind" :title="chan.title">{{ chan.text }}</em>
|
||||
<em v-if="plugin.health && plugin.health.tripped" class="sc-tag health"
|
||||
:title="`连续失败 ${plugin.health.fails} 次已自动禁用,点击进入运行台恢复`">
|
||||
已自动禁用
|
||||
</em>
|
||||
<em v-if="plugin.update_available" class="sc-tag upd" title="云端有新版本,点左栏「插件同步」可升级">
|
||||
↑ v{{ plugin.cloud_version }}
|
||||
</em>
|
||||
@@ -269,6 +273,8 @@ const running = computed(() => store.running && store.selectedId === props.plugi
|
||||
.sc-tag.chan.test { color: var(--warn-ink); background: var(--warn-soft); border-color: var(--warn-line); }
|
||||
.sc-tag.chan.prod { color: var(--good-ink); background: var(--good-soft); border-color: var(--good-line); }
|
||||
.sc-tag.upd { color: var(--brand-ink); background: var(--brand-soft); border-color: var(--brand-track); font-family: var(--f-num); }
|
||||
/* 失败熔断:连续失败已被自动禁用,红色醒目,点击进运行台恢复 */
|
||||
.sc-tag.health { color: var(--danger-ink); background: var(--danger-soft); border-color: var(--danger-line); }
|
||||
.sc-tag.plat { flex-shrink: 1; min-width: 0; }
|
||||
.sc-tag.plat .tx { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
|
||||
.sc-tag.plat .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--t5); flex-shrink: 0; }
|
||||
|
||||
@@ -42,6 +42,13 @@
|
||||
{{ form.close_behavior === 'tray' ? '常驻' : '退出' }}
|
||||
</em>
|
||||
</div>
|
||||
<div class="ov-cell">
|
||||
<span class="ov-k">自动更新</span>
|
||||
<b class="ov-v">{{ form.autoShellUpdate ? `空闲自动升级` : '已关闭' }}</b>
|
||||
<em class="ov-tag" :class="{ on: form.autoShellUpdate }">
|
||||
{{ form.autoShellUpdate ? `${form.autoUpdateSafeMin} 分钟窗口` : '手动' }}
|
||||
</em>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 启动与关闭 -->
|
||||
@@ -86,6 +93,45 @@
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 自动更新 -->
|
||||
<section class="card blk">
|
||||
<header class="blk-head">
|
||||
<span class="blk-ico"><el-icon><Refresh /></el-icon></span>
|
||||
<div class="blk-txt">
|
||||
<h3>客户端自动更新</h3>
|
||||
<p>发现新版后台自动下载,等空闲时自动重启安装,无需手动操作。</p>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="blk-body">
|
||||
<div class="row">
|
||||
<div class="k">
|
||||
<b>自动更新</b>
|
||||
<span>开启后:检测到新版自动下载 → 无任务、队列空、用户空闲且近期无定时任务时,提前 30 秒提醒并自动重启升级</span>
|
||||
</div>
|
||||
<div class="ctl">
|
||||
<span class="state" :class="{ on: form.autoShellUpdate }">{{ form.autoShellUpdate ? '已开启' : '已关闭' }}</span>
|
||||
<el-switch :model-value="!!form.autoShellUpdate" :disabled="saving" @change="onAutoUpdate" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="k">
|
||||
<b>定时任务安全窗口</b>
|
||||
<span>未来这段时间内有定时任务就不触发自动升级,避免任务被跳过(定时任务错过不补跑)</span>
|
||||
</div>
|
||||
<div class="ctl">
|
||||
<div class="num">
|
||||
<el-input-number v-model="form.autoUpdateSafeMin" :min="1" :max="60" :step="5"
|
||||
size="small" controls-position="right" :disabled="saving || !form.autoShellUpdate"
|
||||
@change="onSafeWindow" />
|
||||
<span class="unit">分钟</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p class="hint">升级前 30 秒会弹提示;升级过程约 1~2 分钟,完成后客户端自动重新打开。关闭窗口默认收托盘,不影响自动升级。</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 执行限制 -->
|
||||
<section class="card blk">
|
||||
<header class="blk-head">
|
||||
@@ -281,6 +327,7 @@ const s = ref({
|
||||
version: '', data_dir: '', settings_file: '',
|
||||
autostart: null,
|
||||
close_behavior: 'tray',
|
||||
auto_shell_update: 'on', auto_update_safe_min: 10,
|
||||
run_timeout_sec: 21600, run_timeout_override: null, run_timeout_default: 21600,
|
||||
run_max_mem_mb: 4096, run_max_mem_override: null, run_max_mem_default: 4096,
|
||||
log_max_mb: 10, log_keep: 3, log_max_mb_override: null, log_keep_override: null,
|
||||
@@ -288,7 +335,7 @@ const s = ref({
|
||||
})
|
||||
|
||||
// 表单只放"可编辑值",与快照单向同步(保存后用服务端返回值回填,避免本地与后端不一致)
|
||||
const form = reactive({ autostart: false, close_behavior: 'tray', timeoutMin: 360, memMb: 4096, logMaxMb: 10, logKeep: 3 })
|
||||
const form = reactive({ autostart: false, close_behavior: 'tray', autoShellUpdate: true, autoUpdateSafeMin: 10, timeoutMin: 360, memMb: 4096, logMaxMb: 10, logKeep: 3 })
|
||||
|
||||
const about = ref({})
|
||||
const clOpen = ref(false)
|
||||
@@ -333,6 +380,8 @@ function applySnapshot(r) {
|
||||
applyRunTimeout(r.run_timeout_sec)
|
||||
form.autostart = !!r.autostart
|
||||
form.close_behavior = r.close_behavior || 'tray'
|
||||
form.autoShellUpdate = r.auto_shell_update !== 'off'
|
||||
form.autoUpdateSafeMin = Number(r.auto_update_safe_min) || 10
|
||||
form.timeoutMin = Math.round((Number(r.run_timeout_sec) || 0) / 60)
|
||||
const mem = Number(r.run_max_mem_mb)
|
||||
form.memMb = Number.isFinite(mem) && mem >= 0 ? mem : 4096
|
||||
@@ -402,6 +451,17 @@ function onCloseBehavior(v) {
|
||||
put({ close_behavior: v }, v === 'quit' ? '关闭窗口将直接退出程序' : '关闭窗口将收到托盘继续运行')
|
||||
}
|
||||
|
||||
// ===== 自动更新 =====
|
||||
function onAutoUpdate(v) {
|
||||
put({ auto_shell_update: v ? 'on' : 'off' }, v ? '已开启自动更新(空闲时自动升级)' : '已关闭自动更新')
|
||||
}
|
||||
function onSafeWindow(v) {
|
||||
if (blank(v)) { form.autoUpdateSafeMin = Number(s.value.auto_update_safe_min) || 10; return }
|
||||
const min = Math.max(1, Math.round(Number(v) || 10))
|
||||
form.autoUpdateSafeMin = min
|
||||
put({ auto_update_safe_min: min }, `定时任务安全窗口已设为 ${min} 分钟`)
|
||||
}
|
||||
|
||||
// ===== 执行限制 =====
|
||||
// el-input-number 清空时给 null:不能当成 0(超时/内存里 0 是"不限"的强语义),回填当前生效值
|
||||
function blank(v) {
|
||||
|
||||
@@ -13,6 +13,22 @@ let _singleton = null
|
||||
export function useShellUpdate() {
|
||||
if (_singleton) return _singleton
|
||||
|
||||
// 下载完成提示去重:后端自动下载时前端没走 beginDownload(inFlight 恒 false),
|
||||
// useDownloadJob 的跃迁检测会漏报;用 onTick 兜底,同一版本只提示一次。
|
||||
let _notifiedVersion = ''
|
||||
|
||||
function notifyDownloaded(s) {
|
||||
if (!s.downloaded || !s.new || _notifiedVersion === s.new) return
|
||||
_notifiedVersion = s.new
|
||||
if (s.auto_update) {
|
||||
ElMessage.success(`新版本 v${s.new} 已下载完成,将在空闲时自动重启升级(可到设置关闭自动更新)`)
|
||||
log('INFO', `客户端新版本 v${s.new} 已就绪,等待空闲窗口自动升级`)
|
||||
} else {
|
||||
ElMessage.success(`新版本 v${s.new} 已下载完成,点击顶部「重启更新」完成升级`)
|
||||
log('INFO', `客户端新版本 v${s.new} 已就绪,可重启更新`)
|
||||
}
|
||||
}
|
||||
|
||||
const shellJob = useDownloadJob({
|
||||
fetchStatus: getShellStatus,
|
||||
enabled: () => !!store.current, // 状态接口需登录;未登录/登出后暂停,避免持续打 401
|
||||
@@ -21,11 +37,11 @@ export function useShellUpdate() {
|
||||
isDownloading: (s) => s.dl?.status === 'downloading',
|
||||
isCompleted: (s) => !!s.downloaded,
|
||||
onCompleted: (s) => {
|
||||
// 内网直链下载很快(80MB 秒下),延迟收窗让人看清 100% 完成态,再转顶部「重启更新」条
|
||||
// 内网直链下载很快(80MB 秒下),延迟收窗让人看清 100% 完成态,再转顶部更新条
|
||||
setTimeout(() => { shellJob.dialog.value = false }, 1500)
|
||||
ElMessage.success(`新版本 v${s.new} 已下载完成,点击顶部「重启更新」完成升级`)
|
||||
log('INFO', `客户端新版本 v${s.new} 已就绪,可重启更新`)
|
||||
notifyDownloaded(s)
|
||||
},
|
||||
onTick: (s) => { if (s.downloaded) notifyDownloaded(s) }, // 自动下载兜底
|
||||
onFailed: (s) => ElMessage.warning('新版本下载失败:' + (s.dl?.error || '')),
|
||||
})
|
||||
|
||||
@@ -86,11 +102,15 @@ export function useShellUpdate() {
|
||||
return
|
||||
}
|
||||
if (s.available) {
|
||||
ElMessageBox.confirm(
|
||||
`发现新版本 v${s.latest},是否立即下载?${s.notes ? '\n\n更新说明:' + s.notes : ''}`,
|
||||
'发现新版本',
|
||||
{ confirmButtonText: '立即下载', cancelButtonText: '稍后再说', type: 'info' }
|
||||
).then(() => onShellDownload()).catch(() => {})
|
||||
if (s.auto_update) {
|
||||
ElMessage.info(`发现新版本 v${s.latest},已开始自动下载,空闲时将自动升级`)
|
||||
} else {
|
||||
ElMessageBox.confirm(
|
||||
`发现新版本 v${s.latest},是否立即下载?${s.notes ? '\n\n更新说明:' + s.notes : ''}`,
|
||||
'发现新版本',
|
||||
{ confirmButtonText: '立即下载', cancelButtonText: '稍后再说', type: 'info' }
|
||||
).then(() => onShellDownload()).catch(() => {})
|
||||
}
|
||||
} else {
|
||||
ElMessage.info(`已是最新版本 v${s.current}`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user