cicy-desktop 2.1.226 → 2.1.227
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/package.json +1 -1
- package/src/backends/local-teams.js +32 -7
package/package.json
CHANGED
|
@@ -64,6 +64,7 @@ const CACHE_MS = 4000; // small dedupe so rapid renderer polls don't fan-out
|
|
|
64
64
|
|
|
65
65
|
let _cache = null;
|
|
66
66
|
let _cacheUntil = 0;
|
|
67
|
+
let _lastCustomPull = 0; // 节流:list({refresh}) 顺带 pull 自定义团队,最多每 20s 一次
|
|
67
68
|
|
|
68
69
|
function readGlobal() {
|
|
69
70
|
try {
|
|
@@ -204,6 +205,12 @@ async function probeLiveness(baseUrl, token) {
|
|
|
204
205
|
|
|
205
206
|
async function list({ refresh = false } = {}) {
|
|
206
207
|
if (!refresh && _cache && Date.now() < _cacheUntil) return _cache;
|
|
208
|
+
// 首页刷新时顺带拉一次云端自定义团队(节流 20s):别的设备加的 / 改址的 custom 团队,刷新
|
|
209
|
+
// 首页就能反映,不必重启。pull 内部 reconcile(增 + 改址),已同步的不动;登出则 no-op。
|
|
210
|
+
if (refresh && Date.now() - _lastCustomPull > 20000) {
|
|
211
|
+
_lastCustomPull = Date.now();
|
|
212
|
+
try { await pullCustomTeams(); } catch {}
|
|
213
|
+
}
|
|
207
214
|
const nodes = readNodes();
|
|
208
215
|
const avatars = readAvatars();
|
|
209
216
|
const slugs = Object.keys(nodes);
|
|
@@ -551,24 +558,42 @@ async function pullCustomTeams() {
|
|
|
551
558
|
const list = await cc.listTeams();
|
|
552
559
|
if (!list || !list.ok || !Array.isArray(list.teams)) return;
|
|
553
560
|
const nodes = readNodes();
|
|
561
|
+
// stripUrl:剥 query/hash 后归一 —— 只用于「本地是否已有这个地址」的去重(手动加、没记
|
|
562
|
+
// cloud_team_id 的情况)。norm:保留 query(含 ?token=)、只去尾斜杠 —— 用于判断云端 URL
|
|
563
|
+
// 相对本地是否**真的变了**(token 变化也要能测出,不能被 stripUrl 抹掉)。
|
|
554
564
|
const stripUrl = (u) => { let s = String(u || "").trim(); try { const x = new URL(s); x.search = ""; x.hash = ""; s = x.toString(); } catch {} return normaliseUrl(s.replace(/\/$/, "")); };
|
|
565
|
+
const norm = (u) => String(u || "").trim().replace(/\/$/, "");
|
|
555
566
|
const have = new Set(Object.values(nodes).map((n) => stripUrl(n?.base_url)).filter(Boolean));
|
|
556
|
-
// cloud_team_id
|
|
557
|
-
|
|
558
|
-
const
|
|
559
|
-
let
|
|
567
|
+
// cloud_team_id(String 归一)→ 本地节点 id,用于命中已有团队做 URL reconcile。
|
|
568
|
+
const byCloudId = {};
|
|
569
|
+
for (const [k, v] of Object.entries(nodes)) { if (v?.cloud_team_id != null) byCloudId[String(v.cloud_team_id)] = k; }
|
|
570
|
+
let added = 0, updated = 0;
|
|
560
571
|
for (const t of list.teams) {
|
|
561
572
|
if (t.kind !== "custom") continue;
|
|
562
573
|
const host = String(t.host_url || t.hostUrl || "").trim();
|
|
563
574
|
if (!host) continue;
|
|
564
575
|
const tid = t.teamId || t.id || null;
|
|
565
|
-
|
|
576
|
+
const localId = tid != null ? byCloudId[String(tid)] : null;
|
|
577
|
+
if (localId) {
|
|
578
|
+
// 已有此团队(按 cloud_team_id 命中)。云端权威:host_url 变了(含加/换 ?token=)就把
|
|
579
|
+
// 本地 base_url 更新过来 —— 这才是「改 URL 跨设备同步」的下行环节(原来只增不改 = 白改)。
|
|
580
|
+
// 本地改动会经 Fix A(updateTeam 改址即同步)先上行到云端,所以云端总是最新,不会误回滚。
|
|
581
|
+
const cur = nodes[localId] || {};
|
|
582
|
+
if (norm(cur.base_url) !== norm(host)) {
|
|
583
|
+
await writeNodes((nds) => { if (nds[localId]) { nds[localId].base_url = host; nds[localId].updated_at = new Date().toISOString(); } return nds; });
|
|
584
|
+
updated++;
|
|
585
|
+
log.info(`[local-teams] custom team ${localId} url ← cloud (teamId=${tid})`);
|
|
586
|
+
}
|
|
587
|
+
continue;
|
|
588
|
+
}
|
|
589
|
+
if (have.has(stripUrl(host))) continue; // 本地手动加过同地址(还没记 cloud_team_id)→ 跳过
|
|
566
590
|
try {
|
|
567
591
|
const r = await addTeam({ base_url: host, name: t.title || t.name || host, cloud_team_id: tid });
|
|
568
|
-
if (r && r.ok) {
|
|
592
|
+
if (r && r.ok) { added++; log.info(`[local-teams] materialized custom team ${host} (cloud teamId=${tid})`); }
|
|
569
593
|
} catch (e) { log.warn(`[local-teams] materialize custom ${host} failed: ${e.message}`); }
|
|
570
594
|
}
|
|
571
|
-
|
|
595
|
+
// pull 改了本地 → 作废 list 缓存,首页下次 poll 立刻拿到新数据(不必重启)。
|
|
596
|
+
if (added || updated) { _cache = null; _cacheUntil = 0; log.info(`[local-teams] pull custom: +${added} added, ${updated} url-updated`); }
|
|
572
597
|
} catch (e) { log.warn(`[local-teams] pullCustomTeams failed: ${e.message}`); }
|
|
573
598
|
}
|
|
574
599
|
|