feat: add extension test environment configuration

This commit is contained in:
Caoweijie
2026-09-11 18:00:29 +08:00
parent f2817e7baf
commit 2c8e7a5435
4 changed files with 27 additions and 4 deletions
+14
View File
@@ -43,6 +43,20 @@ V9.3.0 将采集、七角色分析、证据追溯和最终报告统一为一条
## 本地运行
### 浏览器扩展环境
在 `extension/auth.js` 中修改 `SANSHENG_ENV` 选择环境,默认为 `dev`。
| 环境 | SANSHENG_ENV | 接口前缀 | PC 端地址 |
| --- | --- | --- | --- |
| 开发 | `dev` | `http://localhost:19174` | `http://localhost:5173` |
| 测试 | `test` | `https://qa-api.sanshengai.net` | `https://qa.sanshengai.net` |
| 生产 | `prod` | `https://api.sanshengai.net` | `https://www.sanshengai.net` |
切换后,在浏览器扩展管理页重新加载 `extension` 目录的扩展,并退出登录后重新登录。`extension/manifest.json` 已包含上述环境的域名权限。已有 `release` 发布包使用其自身配置。
### 本地分析服务
双击 `start-tmall-ai.command`,或在 `server` 目录运行:
```bash
+9 -2
View File
@@ -1,6 +1,13 @@
// 切换环境后,在浏览器扩展管理页重新加载扩展并重新登录。
const SANSHENG_ENV='dev'; // dev | test | prod
const SANSHENG_ENVIRONMENTS={
dev:{apiBase:'http://localhost:19174',pcBase:'http://localhost:5173'},
test:{apiBase:'https://qa-api.sanshengai.net',pcBase:'https://qa.sanshengai.net'},
prod:{apiBase:'https://api.sanshengai.net',pcBase:'https://www.sanshengai.net'}
};
if(!Object.prototype.hasOwnProperty.call(SANSHENG_ENVIRONMENTS,SANSHENG_ENV))throw new Error(`未知扩展环境:${SANSHENG_ENV}`);
const SANSHENG_AUTH_CONFIG={
apiBase:'http://localhost:19174',
pcBase:'http://localhost:5173',
...SANSHENG_ENVIRONMENTS[SANSHENG_ENV],
clientId:'sansheng-product-analysis-extension',
scope:'product.analysis',
callbackPath:'/extension/authorize'
+2 -2
View File
@@ -21,8 +21,8 @@ async function submitProductAnalysis(raw){
try{
response=await sanshengExtensionAuth.fetch('/v1/product-analysis/tasks',{method:'POST',headers:{'Content-Type':'application/json','Idempotency-Key':raw.collection.clientRequestId},body:JSON.stringify({platform:raw?.meta?.platform||'taobao',productId:String(raw?.product?.itemId||''),analysisMode:raw?.collection?.analysisMode==='current_snapshot'?'quick':(raw?.collection?.reviewCollectionMode||'standard'),userInstruction:'',clientRequestId:raw.collection.clientRequestId,snapshot:raw,source:'chrome-extension'}),signal:controller.signal});
}catch(error){
if(error?.name==='AbortError')throw new Error('Web API 响应超时,请确认开发 API 已启动后重试');
throw new Error('无法连接 Web API,请确认 http://localhost:19174 已启动');
if(error?.name==='AbortError')throw new Error('Web API 响应超时,请确认当前环境 API 可用后重试');
throw new Error(`无法连接 Web API,请确认 ${sanshengExtensionAuth.config.apiBase} 可用`);
}finally{clearTimeout(timeout)}
const result=await response.json().catch(()=>null);
const code=result?.Code??result?.code;
+2
View File
@@ -17,6 +17,8 @@
"https://*.alicdn.com/*",
"https://api.sanshengai.net/*",
"https://www.sanshengai.net/*",
"https://qa-api.sanshengai.net/*",
"https://qa.sanshengai.net/*",
"http://localhost:19174/*",
"http://localhost:5173/*"
],