feat(phase-4): 外观专利/货源两个提交入口加建单前密钥门禁(B72-02)
服务端建单口 `UserApiSecretService#requireSubmitSecret` 已经拒缺密钥的单,但界面要等
用户上传完 Excel、点了提交才看到那句中文——白跑一趟昂贵动作。本笔把同一句话提到提交前,
形状照 `ensureBrandCheckProxyReady()` 的先例(`ElMessageBox.alert` +关窗 reject 由
`.then(()=>{},()=>{})` 收尾,不新增 catch)。
三条边界,都是把它写成"能拦但拦错东西"的风险点:
- **前置排在一切昂贵动作之前**:`parseFiles()` 里早于 `parsing.value = true`、早于
`parseAppearancePatent(`/`parseSimilarAsin(` 建单调用(铁律 27 边界 b)。
- **unknown 放行**:`getApiSecretGateState()==='unknown'` 是"从未成功拉到服务端数据",
网络抖动不等于未配置,拦人就是把上游抖动说成用户没配——与商标代理前置同口径。
- **文案与服务端同源**:模块名取服务端下发的 `moduleLabel`(`listApiSecretModules()`),
句子逐字对齐 requireSubmitSecret,前端不再另起一份叫法;查的是本模块快照
(`getStoredApiSecretSnapshot(moduleKey)`),不拿全局完整性一档误伤另一个模块。
顺手摘掉两处「本地无明文不再阻断」的 console.log 死分支——日志不等于拦住用户。
`pushToPythonQueue()` 里同名那句不动:它启动的是已建好的单,不是建单入口。
判据:`tests/pre-submit-llm-key-gate.test.ts`(4 例,两个 Tab 共用同一份
`gateViolations()` 判据,反向自证喂进实现时用的同一把尺子:摘前置/挪到建单之后/
让 unknown 拦人/硬编模块名,各自报出自己那条违规)。node --test 4 passed;
`npm test` 全面 1007 passed/0 fail;`npm run test:mount` 55 passed;
`npx vue-tsc --noEmit` rc=0。该仓无入库 lint 脚本 ⇒ 以类型检查+测试为准,不伪造 lint 绿。
This commit is contained in:
@@ -135,7 +135,13 @@ import { checkParseResult, checkQueuePayload } from '@/shared/dispatch-guard'
|
||||
import { passGuard } from '@/shared/dispatch-guard-ui'
|
||||
import { formatDateTime } from '@/shared/utils/datetime'
|
||||
import { resultBuildFailed, taskStatusClass, taskStatusText } from '@/shared/utils/task-status-text'
|
||||
import { ensureBrandCheckProxy, getStoredApiSecret } from '@/shared/utils/api-secret-store'
|
||||
import {
|
||||
ensureBrandCheckProxy,
|
||||
getApiSecretGateState,
|
||||
getStoredApiSecret,
|
||||
getStoredApiSecretSnapshot,
|
||||
listApiSecretModules,
|
||||
} from '@/shared/utils/api-secret-store'
|
||||
|
||||
// ---- 文件选择 / 上传(公共组合式函数)----
|
||||
const {
|
||||
@@ -536,15 +542,42 @@ async function ensureBrandCheckProxyReady(): Promise<boolean> {
|
||||
return false
|
||||
}
|
||||
|
||||
/** 模块名取服务端下发的 label,前端不再另起一份叫法;默认清单里必有本模块,兜底句只为满足类型。 */
|
||||
function llmKeyModuleLabel(): string {
|
||||
return listApiSecretModules().find((info) => info.moduleKey === 'appearance-patent')?.moduleLabel || '对应模块密钥'
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建任务前确认这个模块的 LLM 密钥已配置:服务端建单口(UserApiSecretService#requireSubmitSecret)
|
||||
* 也会拒,但那时 Excel 已上传、单已建一半,用户白等一趟,所以把同一句话提到提交前说。
|
||||
* 门禁状态 unknown(从未成功拉到服务端数据)不拦——网络抖动不等于未配置,与 ensureBrandCheckProxy 同口径。
|
||||
*/
|
||||
async function ensureLlmApiKeyReady(): Promise<boolean> {
|
||||
if (getApiSecretGateState() === 'unknown') return true
|
||||
const snapshot = getStoredApiSecretSnapshot('appearance-patent')
|
||||
// exists + 检测通过才算配好;error(上游无法判定)按放行,与 computeApiSecretsComplete 同一判据
|
||||
const configured = (snapshot.exists && (snapshot.checkStatus === 'passed' || snapshot.checkStatus === 'error'))
|
||||
|| Boolean(effectiveLlmApiKey())
|
||||
if (configured) return true
|
||||
await ElMessageBox.alert(
|
||||
`该账号还没有配置${llmKeyModuleLabel()}:这一单要用它跑 LLM 检测,`
|
||||
+ '缺了只会得到一张没有检测结论的结果表。请先在「密钥设置」里填好并保存。',
|
||||
'未配置密钥,无法创建任务',
|
||||
{ type: 'warning', confirmButtonText: '知道了' },
|
||||
).then(
|
||||
// 关闭弹窗会以 reject 收尾,属正常交互而不是错误,不新增 catch 块
|
||||
() => undefined,
|
||||
() => undefined,
|
||||
)
|
||||
return false
|
||||
}
|
||||
|
||||
async function parseFiles() {
|
||||
if (!uploadedFiles.value.length) {
|
||||
ElMessage.warning('请先选择 Excel')
|
||||
return
|
||||
}
|
||||
if (!effectiveLlmApiKey()) {
|
||||
// 本地无明文不再阻断:密钥已服务端化,任务执行按用户 uid 兜底读取
|
||||
console.log('[appearance-patent] 本地无密钥明文,提交时由服务端按用户密钥兜底')
|
||||
}
|
||||
if (!(await ensureLlmApiKeyReady())) return
|
||||
parsing.value = true
|
||||
try {
|
||||
if (!(await ensureBrandCheckProxyReady())) {
|
||||
|
||||
@@ -132,7 +132,7 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
||||
import { userNotice } from '@/shared/utils/user-notice'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { retryClientTask } from '@/shared/api/task-retry'
|
||||
import AmazonToolPageShell from '@/pages/amazon/components/AmazonToolPageShell.vue';
|
||||
import FileUploadZone from '@/shared/components/FileUploadZone.vue'
|
||||
@@ -170,7 +170,12 @@ import { passGuard } from '@/shared/dispatch-guard-ui'
|
||||
import { getCollectRouting, type CollectChannel } from '@/shared/api/types/modules/collect-routing'
|
||||
import { formatDateTime } from '@/shared/utils/datetime'
|
||||
import { isCompletedTask, resultBuildFailed, taskStatusClass, taskStatusText } from '@/shared/utils/task-status-text'
|
||||
import { getStoredApiSecret } from '@/shared/utils/api-secret-store'
|
||||
import {
|
||||
getApiSecretGateState,
|
||||
getStoredApiSecret,
|
||||
getStoredApiSecretSnapshot,
|
||||
listApiSecretModules,
|
||||
} from '@/shared/utils/api-secret-store'
|
||||
|
||||
// ---- 文件选择 / 上传(公共组合式函数)----
|
||||
const {
|
||||
@@ -529,15 +534,42 @@ function toTaskSummary(result: SimilarAsinParseVo): TaskSummary {
|
||||
}
|
||||
}
|
||||
|
||||
/** 模块名取服务端下发的 label,前端不再另起一份叫法;默认清单里必有本模块,兜底句只为满足类型。 */
|
||||
function llmKeyModuleLabel(): string {
|
||||
return listApiSecretModules().find((info) => info.moduleKey === 'similar-asin')?.moduleLabel || '对应模块密钥'
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建任务前确认这个模块的 LLM 密钥已配置:服务端建单口(UserApiSecretService#requireSubmitSecret)
|
||||
* 也会拒,但那时 Excel 已上传、单已建一半,用户白等一趟,所以把同一句话提到提交前说。
|
||||
* 门禁状态 unknown(从未成功拉到服务端数据)不拦——网络抖动不等于未配置,与商标 Tab 的代理前置同口径。
|
||||
*/
|
||||
async function ensureLlmApiKeyReady(): Promise<boolean> {
|
||||
if (getApiSecretGateState() === 'unknown') return true
|
||||
const snapshot = getStoredApiSecretSnapshot('similar-asin')
|
||||
// exists + 检测通过才算配好;error(上游无法判定)按放行,与 computeApiSecretsComplete 同一判据
|
||||
const configured = (snapshot.exists && (snapshot.checkStatus === 'passed' || snapshot.checkStatus === 'error'))
|
||||
|| Boolean(effectiveLlmApiKey())
|
||||
if (configured) return true
|
||||
await ElMessageBox.alert(
|
||||
`该账号还没有配置${llmKeyModuleLabel()}:这一单要用它跑 LLM 检测,`
|
||||
+ '缺了只会得到一张没有检测结论的结果表。请先在「密钥设置」里填好并保存。',
|
||||
'未配置密钥,无法创建任务',
|
||||
{ type: 'warning', confirmButtonText: '知道了' },
|
||||
).then(
|
||||
// 关闭弹窗会以 reject 收尾,属正常交互而不是错误,不新增 catch 块
|
||||
() => undefined,
|
||||
() => undefined,
|
||||
)
|
||||
return false
|
||||
}
|
||||
|
||||
async function parseFiles() {
|
||||
if (!uploadedFiles.value.length) {
|
||||
ElMessage.warning('请先选择 Excel')
|
||||
return
|
||||
}
|
||||
if (!effectiveLlmApiKey()) {
|
||||
// 本地无明文不再阻断:密钥已服务端化,任务执行按用户 uid 兜底读取
|
||||
console.log('[similar-asin] 本地无密钥明文,提交时由服务端按用户密钥兜底')
|
||||
}
|
||||
if (!(await ensureLlmApiKeyReady())) return
|
||||
if (!getRequiredAlipriceCredentials()) return
|
||||
parsing.value = true
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user