From b658a01a9523200aa16a6a19b6acb64ebdbf8fe3 Mon Sep 17 00:00:00 2001 From: codex Date: Sun, 1 Nov 2026 21:47:41 +0800 Subject: [PATCH] fix(ui): silence successful user copy actions --- web/public/cloud/detail.js | 4 +-- web/public/cloud/instances.js | 1 - web/public/cloud/invoice-detail-runtime.js | 2 -- web/public/cloud/runtime.js | 7 ++--- web/public/theme/venix/js/user-home.js | 3 +- web/resources/views/venix/layout_assets.tpl | 2 +- web/tests/AdminBillingApiContractTest.php | 2 +- web/tests/CloudAssetVersionContractTest.php | 2 +- web/tests/UserCopyFeedbackContractTest.mjs | 35 +++++++++++++++++++++ 9 files changed, 44 insertions(+), 14 deletions(-) create mode 100644 web/tests/UserCopyFeedbackContractTest.mjs diff --git a/web/public/cloud/detail.js b/web/public/cloud/detail.js index 2dd24a06..0912f16c 100644 --- a/web/public/cloud/detail.js +++ b/web/public/cloud/detail.js @@ -2935,7 +2935,7 @@ function bindInstanceSettings(vmId) { byId('vm-detail-generated-password-copy')?.addEventListener('click', async () => { const value = byId('vm-detail-generated-password')?.textContent || ''; if (!value) return; - try { await copyText(value); toast('新密码已复制,请妥善保存。', 'success'); } + try { await copyText(value); } catch (error) { toast(error.message, 'error'); } }); byId('vm-detail-generated-password-close')?.addEventListener('click', clearGeneratedPassword); @@ -2994,7 +2994,7 @@ export async function initialize() { if (!byId('vm-settings-section-rescue')?.hidden) await loadRescue(vmId, true).catch(() => null); }); byId('vm-detail-ip-copy')?.addEventListener('click', async () => { - try { await copyText(vmIp(selectedVm())); toast('公网 IP 已复制。'); } + try { await copyText(vmIp(selectedVm())); } catch (error) { toast(error.message, 'error'); } }); byId('vm-detail-password-reveal')?.addEventListener('click', () => credential()); diff --git a/web/public/cloud/instances.js b/web/public/cloud/instances.js index db254ed0..99792ac6 100644 --- a/web/public/cloud/instances.js +++ b/web/public/cloud/instances.js @@ -721,7 +721,6 @@ function bindEvents() { const button = event.target.closest?.('[data-copy-value]'); if (!button) return; void copyText(button.dataset.copyValue || '') - .then(() => toast(`${button.dataset.copyLabel || '内容'}已复制。`, 'success')) .catch(error => toast(error?.message || '复制失败。', 'error')); }); window.addEventListener('pagehide', () => { diff --git a/web/public/cloud/invoice-detail-runtime.js b/web/public/cloud/invoice-detail-runtime.js index a75aa1ac..636a4327 100644 --- a/web/public/cloud/invoice-detail-runtime.js +++ b/web/public/cloud/invoice-detail-runtime.js @@ -744,7 +744,6 @@ function renderOnlinePayment(container, payment) { box.append(actionButton('复制收款地址', async () => { try { await copyText(qrValue); - toast('USDT 收款地址已复制。', 'success'); } catch (error) { toast(error.message, 'error'); } @@ -764,7 +763,6 @@ function renderOnlinePayment(container, payment) { box.append(actionButton('复制支付信息', async () => { try { await copyText(qrValue); - toast('支付信息已复制。', 'success'); } catch (error) { toast(error.message, 'error'); } diff --git a/web/public/cloud/runtime.js b/web/public/cloud/runtime.js index 2ca09e1b..c81a9e50 100644 --- a/web/public/cloud/runtime.js +++ b/web/public/cloud/runtime.js @@ -537,7 +537,7 @@ async function credential(copy = false) { const vm = selectedVm(); if (!vm?.can_view_credential || !vm.password_available) return; if (!copy && state.credentialVisible) return clearCredential(); const id = vm.api_id; - try { const result = await api(`${vmPath(vm)}/credential`, { method: 'POST' }); if (selectedVm()?.api_id !== id || state.view !== 'detail') return; if (!result?.password) throw new Error('没有可查看的初始密码。'); if (copy) { await copyText(result.password); toast('初始密码已复制。', 'success'); } else { state.credentialPassword = result.password; state.credentialVisible = true; text('vm-detail-root-password', result.password); byId('vm-detail-password-reveal').setAttribute('aria-pressed', 'true'); clearTimeout(state.credentialTimer); state.credentialTimer = setTimeout(clearCredential, 30000); } } catch (error) { toast(error.message, 'error'); } + try { const result = await api(`${vmPath(vm)}/credential`, { method: 'POST' }); if (selectedVm()?.api_id !== id || state.view !== 'detail') return; if (!result?.password) throw new Error('没有可查看的初始密码。'); if (copy) { await copyText(result.password); } else { state.credentialPassword = result.password; state.credentialVisible = true; text('vm-detail-root-password', result.password); byId('vm-detail-password-reveal').setAttribute('aria-pressed', 'true'); clearTimeout(state.credentialTimer); state.credentialTimer = setTimeout(clearCredential, 30000); } } catch (error) { toast(error.message, 'error'); } } async function loadKeys() { state.sshKeys = items(await api('/api/v1/ssh-keys')); @@ -1179,7 +1179,7 @@ async function openReinstall(vm, bootstrap = null) { copyName.disabled = !currentName; copyName.onclick = async () => { if (!currentName) return; - try { await copyText(currentName); toast('虚拟机名称已复制。', 'success'); } + try { await copyText(currentName); } catch (error) { toast(error.message, 'error'); } }; } @@ -1191,7 +1191,7 @@ async function openReinstall(vm, bootstrap = null) { if (passwordCardCopy) { passwordCardCopy.onclick = async () => { if (!state.reinstallPassword) return; - try { await copyText(state.reinstallPassword); toast('重装密码已复制,请妥善保存。', 'success'); } + try { await copyText(state.reinstallPassword); } catch (error) { toast(error.message, 'error'); } }; } @@ -1400,7 +1400,6 @@ function makeCopyIconButton(value, label) { button.addEventListener("click", async () => { try { await copyText(value); - toast(`${label}已复制。`, "success"); } catch (error) { toast(error.message, "error"); } diff --git a/web/public/theme/venix/js/user-home.js b/web/public/theme/venix/js/user-home.js index 48ed7cdd..c2fa41cb 100644 --- a/web/public/theme/venix/js/user-home.js +++ b/web/public/theme/venix/js/user-home.js @@ -317,8 +317,7 @@ if (!button) return; event.preventDefault(); copyText(button.getAttribute("data-copy")).then(function (ok) { - - alertModal(ok ? "已复制到剪贴板" : "复制失败,请手动复制", ok ? "success" : "error"); + if (!ok) alertModal("复制失败,请手动复制", "error"); }).catch(function () { alertModal("复制失败,请手动复制", "error"); }); diff --git a/web/resources/views/venix/layout_assets.tpl b/web/resources/views/venix/layout_assets.tpl index f4b184a3..0c512f59 100644 --- a/web/resources/views/venix/layout_assets.tpl +++ b/web/resources/views/venix/layout_assets.tpl @@ -1,2 +1,2 @@ {* Shared Venix CSS/JS cache key. Increment whenever a shared browser asset changes. *} -{assign var=venix_asset_version value='2026110125' scope='global'} +{assign var=venix_asset_version value='2026110126' scope='global'} diff --git a/web/tests/AdminBillingApiContractTest.php b/web/tests/AdminBillingApiContractTest.php index 725b7c55..253fb1fd 100644 --- a/web/tests/AdminBillingApiContractTest.php +++ b/web/tests/AdminBillingApiContractTest.php @@ -329,7 +329,7 @@ $assert(str_contains($invoicePresentation, && !str_contains($invoicePresentation, 'match (strtolower($status))'), 'User invoice statuses must translate catalog tones, not rebuild semantics.'); $assert(str_contains($layoutAssets, - "venix_asset_version value='2026110125'") + "venix_asset_version value='2026110126'") && str_contains($template, '/cloud/admin-billing.js?v={$venix_asset_version}'), 'Administrator billing asset changes must advance the shared cache key.'); diff --git a/web/tests/CloudAssetVersionContractTest.php b/web/tests/CloudAssetVersionContractTest.php index d7fed397..a927a8ed 100644 --- a/web/tests/CloudAssetVersionContractTest.php +++ b/web/tests/CloudAssetVersionContractTest.php @@ -15,7 +15,7 @@ $assert = static function (bool $condition, string $message): void { }; $assert(is_string($assets) - && str_contains($assets, "venix_asset_version value='2026110125'") + && str_contains($assets, "venix_asset_version value='2026110126'") && is_string($cloudShell) && str_contains($cloudShell, '/cloud/app.js?v={$venix_asset_version}'), 'The cloud application entry must use the shared Venix asset version.'); diff --git a/web/tests/UserCopyFeedbackContractTest.mjs b/web/tests/UserCopyFeedbackContractTest.mjs new file mode 100644 index 00000000..c02a9b25 --- /dev/null +++ b/web/tests/UserCopyFeedbackContractTest.mjs @@ -0,0 +1,35 @@ +import assert from 'node:assert/strict'; +import { readFile } from 'node:fs/promises'; + +const root = new URL('../', import.meta.url); +const sources = new Map(await Promise.all([ + 'public/cloud/runtime.js', + 'public/cloud/instances.js', + 'public/cloud/detail.js', + 'public/cloud/invoice-detail-runtime.js', + 'public/theme/venix/js/user-home.js', +].map(async path => [path, await readFile(new URL(path, root), 'utf8')]))); + +for (const [path, source] of sources) { + assert.doesNotMatch(source, /已复制|复制成功|已复制到剪贴板/, + `${path} still displays a success message after copying.`); +} + +const runtime = sources.get('public/cloud/runtime.js'); +const instances = sources.get('public/cloud/instances.js'); +const detail = sources.get('public/cloud/detail.js'); +const invoice = sources.get('public/cloud/invoice-detail-runtime.js'); +const account = sources.get('public/theme/venix/js/user-home.js'); + +assert.match(runtime, /浏览器无法复制,请手动选择文本/, + 'Shared VM copy failures no longer explain how to recover.'); +assert.match(instances, /复制失败|浏览器无法复制/, + 'Instance-list copy failures no longer notify the user.'); +assert.match(detail, /copyText\([^)]+\)[\s\S]{0,120}catch \(error\) \{ toast\(error\.message, 'error'\); \}/, + 'Instance-detail copy failures are no longer surfaced.'); +assert.match(invoice, /浏览器无法复制,请手动选择文本/, + 'Invoice copy failures no longer explain how to recover.'); +assert.match(account, /复制失败,请手动复制/, + 'Account-page copy failures are no longer surfaced.'); + +console.log('User copy actions stay silent on success and visible on failure.');