@kne/fastify-app-manager 0.1.39 → 0.1.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -207,7 +207,7 @@ await fastify.listen({ port: 3000 });
207
207
  | `getOpenApiToken` | function | 否 | `null` | `async app => accessToken`,签发读取子应用 `/open-api.json` 的服务令牌;未配置时 `GET .../app/open-api` 返回 400。接 OIDC 时传 `appOidc.getOpenApiToken` |
208
208
  | `issueUserAccessToken` | function | 否 | `null` | `async ({ app, userId, tenantId }) => accessToken`,以登录用户身份签发子应用令牌;未配置时 `POST .../app/open-api/token` 返回 400。接 OIDC 时传 `appOidc.issueUserAccessToken` |
209
209
  | `resolveVersionFile` | function | 否 | `null` | `async ({ fileId, name, version, request }) => Buffer`,版本上传传 `fileId`(而非 multipart 文件)时调用,返回 zip 内容;未配置时传 `fileId` 返回 400。版本记录保存 `fileId`;这类版本只在当前部署时常驻磁盘,部署非当前版本或启动时当前版本目录缺失会再次调用以重建 |
210
- | `saveIconFile` | function | 否 | `null` | `async ({ buffer, filename, mimetype }) => fileId`,凭 installKey 关联外部应用(`POST .../app/link/import`)且未传 `icon` 时,平台从远程应用站点收集 favicon / apple-touch-icon / manifest 图标,按真实像素取最大的一张,经此回调存入宿主文件系统并返回文件 id,写入应用 `icon`。未配置则不抓取;抓取或保存失败只记告警,不阻断关联 |
210
+ | `saveIconFile` | function | 否 | `null` | `async ({ buffer, filename, mimetype }) => fileId`,凭 installKey 关联外部应用(`POST .../app/link/import`)且未传 `icon` 时,平台从远程应用站点收集 favicon / apple-touch-icon / manifest 图标(首页没声明时也会探测根路径的 `/manifest.json`、`/apple-touch-icon.png`),按真实像素取最大的一张,经此回调存入宿主文件系统并返回文件 id,写入应用 `icon`。未配置则不抓取;抓取或保存失败只记告警,不阻断关联 |
211
211
  | (宿主接入 `@kne/fastify-oidc`) | — | — | — | 关联外部应用激活或同步时,远程 `@kne/fastify-app-runtime` 回传 `tenantSyncUri`(远程为新版 fastify-oidc 的 standalone 应用)则把该应用以 `tenantMode: 'independent'`、`permissionRoot: true` 登记进 `fastify.oidc.services.app`:开通判断与权限去前缀按顶层 `<name>`,宿主租户变更推送给远程,远程把宿主租户同步为只读托管租户、镜像宿主用户;删除应用时(`appOidc.onAppRemoved`)标记移除该登记。已配对的关联应用在应用中心列表里的 `openUrl` 与 `entries[].url` 带 `oidc_iss={本平台 issuer}`,远程据此用本平台账号登录 |
212
212
  | `filterCenterApps` | function | 否 | `null` | `async ({ apps, request }) => apps`,登录用户的应用中心列表(`GET .../app/center/list`)返回前调用,宿主可据 `request` 裁剪(如按租户已开通权限隐藏被关闭的应用),返回保留的应用数组;返回非数组则不裁剪。公开列表(`center/public-list`)无登录态,不调用 |
213
213
  | `filterCenterMenus` | function | 否 | `null` | `async ({ menus, app, request }) => menus`,登录用户菜单列表(`GET .../app/center/menus`)按应用逐个调用,宿主可据 `request` 做用户级裁剪(如按权限码 `menu.permissionCode` 隐藏菜单),返回保留的菜单数组;返回非数组则不裁剪;裁空的应用不出现 |
@@ -131,8 +131,9 @@ const filenameOf = (url, mimetype) => {
131
131
  };
132
132
 
133
133
  /**
134
- * 从远程应用前端站点获取图标:首页 <link rel=icon/apple-touch-icon>、web manifest icons、/favicon.ico 全部作为候选,
135
- * 逐个下载后读真实像素尺寸,取最大的一张(站点没声明 sizes 也能比出大小);尺寸相同按 touch > icon > manifest > favicon.ico,普通图优先于 maskable。
134
+ * 从远程应用前端站点获取图标:首页 <link rel=icon/apple-touch-icon>、web manifest icons(首页没声明时探测 /manifest.json)、
135
+ * /apple-touch-icon.png、/favicon.ico 全部作为候选,
136
+ * 逐个下载后读真实像素尺寸,取最大的一张(站点没声明 sizes 也能比出大小);尺寸相同按 touch > icon > manifest > 约定路径 > favicon.ico,普通图优先于 maskable。
136
137
  * 只接受 image/* 且不超过 1MB 的响应(SPA 对未知路径回落 HTML 的会被丢弃)。
137
138
  * 失败返回 null,不抛错。
138
139
  */
@@ -148,24 +149,26 @@ const discoverRemoteIcon = async ({ baseUrl, timeoutMs = 5000, fetchImpl = fetch
148
149
 
149
150
  const candidates = [];
150
151
  const pageUrl = `${base}/`;
152
+ let declaredManifestUrl = null;
151
153
  try {
152
154
  const page = await request(pageUrl, 'text/html');
153
155
  if (page) {
154
156
  const { icons, manifestUrl } = parseHtmlIcons(await page.text(), pageUrl);
155
157
  candidates.push(...icons);
156
- if (manifestUrl) {
157
- try {
158
- const manifestRes = await request(manifestUrl, 'application/manifest+json,application/json');
159
- candidates.push(...parseManifestIcons(manifestRes ? await manifestRes.json() : null, manifestUrl));
160
- } catch (e) {
161
- // manifest 取不到不影响后续候选
162
- }
163
- }
158
+ declaredManifestUrl = manifestUrl;
164
159
  }
165
160
  } catch (e) {
166
- // 首页取不到,退回 /favicon.ico
161
+ // 首页取不到,仍按约定路径探测
162
+ }
163
+ // 首页没声明 manifest(老页面、或首页取不到)时按约定路径 /manifest.json 探测:站点常把 manifest 放在根路径却没在 HTML 里引用
164
+ const manifestUrl = declaredManifestUrl || `${base}/manifest.json`;
165
+ try {
166
+ const manifestRes = await request(manifestUrl, 'application/manifest+json,application/json');
167
+ candidates.push(...parseManifestIcons(manifestRes ? await manifestRes.json() : null, manifestUrl));
168
+ } catch (e) {
169
+ // manifest 取不到、或被 SPA 回落成 HTML 无法解析,不影响后续候选
167
170
  }
168
- candidates.push({ url: `${base}/favicon.ico`, size: 0 });
171
+ candidates.push({ url: `${base}/apple-touch-icon.png`, size: 0 }, { url: `${base}/favicon.ico`, size: 0 });
169
172
 
170
173
  const unique = [...new Map(candidates.map(item => [item.url, item])).values()].slice(0, MAX_CANDIDATES);
171
174
  const fetched = await Promise.all(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kne/fastify-app-manager",
3
- "version": "0.1.39",
3
+ "version": "0.1.40",
4
4
  "description": "Fastify 单机应用市场插件:版本上传、PM2 托管、路径/域名反代与日志 SSE",
5
5
  "main": "index.js",
6
6
  "scripts": {