fix(extension): 修复插件配置接口 404(controller 方法名 config 被 this.config 顶掉)

Egg 的 BaseContextClass 构造时会把 `this.config = app.config` 挂到实例上,
控制器里叫 `config()` 的动作会被这个实例属性覆盖:路由能匹配上,但
egg-router 拿到的不是函数,最终静默返回 404「接口不存在」。

- controller/web/extension.js:动作改名为 show()
- router.js:/api/web/extension/config 指向 controller.web.extension.show
- 插件:同步周期文案改为「每 5 分钟」,版本 1.1.1

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
liufumingren 2026-11-01 03:25:43 +08:00
parent fd433ee0fc
commit 3570c6ad5c
4 changed files with 11 additions and 6 deletions

View File

@ -14,8 +14,13 @@ const { Controller } = require('egg');
* - 响应 `Cache-Control: no-cache`:配置改了要能马上生效,别被 nginx/浏览器缓存一小时。
*/
class WebExtensionController extends Controller {
/** GET /api/web/extension/config */
async config() {
/**
* GET /api/web/extension/config
*
* ⚠️ 方法不能叫 `config`:Egg 的 BaseContextClass 会给实例挂 `this.config = app.config`,
* 同名方法会被这个实例属性顶掉(路由能匹配上,但拿到的不是函数 → 静默 404)。
*/
async show() {
const { ctx, app } = this;
const expected = (app.config.extension && app.config.extension.appKey) || '';

View File

@ -84,7 +84,7 @@ module.exports = (app) => {
// ---------- Chrome 插件读取(公开只读,无令牌) ----------
// 只下发:前缀 + 生成好的正则 + 生效站点 + 跳转模板 + 安装包地址;不含任何账号/业务数据。
// 生产若配了 CORS_ORIGINS,记得把 `chrome-extension://<扩展ID>` 加进去(默认 `*` 不用管)。
router.get('/api/web/extension/config', controller.web.extension.config);
router.get('/api/web/extension/config', controller.web.extension.show);
// ---------- 主体(租户):不输主体 id,靠「当前用户是否是成员」判定 ----------
// 除这几个以外的业务接口都要额外带 `X-Subject-Id`(middleware/subjectAuth)

View File

@ -1,8 +1,8 @@
{
"manifest_version": 3,
"name": "云仓视频溯源 · 单号注入",
"version": "1.1.0",
"description": "在第三方 WMS / 后台页面里识别单号,就地加工成可点击的溯源入口;识别前缀与生效站点由管理员在后台统一维护,插件每小时自动同步。",
"version": "1.1.1",
"description": "在第三方 WMS / 后台页面里识别单号,就地加工成可点击的溯源入口;识别前缀与生效站点由管理员在后台统一维护,插件每 5 分钟自动同步。",
"minimum_chrome_version": "96",
"icons": {

View File

@ -118,7 +118,7 @@
<h2>同步状态</h2>
<div class="row"><span class="label">配置来源</span><span id="source" class="muted">—</span></div>
<div class="row"><span class="label">上次同步</span><span id="last-sync" class="muted">—</span></div>
<div class="row"><span class="label">自动同步</span><span class="muted">每小时一次(插件启动时也会同步)</span></div>
<div class="row"><span class="label">自动同步</span><span class="muted">每 5 分钟一次(插件启动时也会同步)</span></div>
<div class="row" id="error-row" style="display:none">
<span class="label">上次错误</span><span id="sync-error" class="err"></span>
</div>