一分钟搭建影视站,支持Docker等部署方式
fix(live): 订阅同步缺席即摘除直播源归属引用,远端删除不再残留陈旧计数
bestZwei9227538a6f2d
diff --git a/README.md b/README.mdindex 645bc31..745c55e 100644--- a/README.md+++ b/README.md@@ -183,7 +183,7 @@ PASSWORD=your-password npm start # 监听 8080- **订阅**:设置 → 源管理 → 数据源订阅 → 填入订阅地址 → 「订阅」,导入的点播源自动勾选、直播源自动启用,均带「订阅」标识,条目上显示「点播 N · 直播 M」;- **同步**:订阅条目上的 **⟳** 手动强制同步,整体替换该订阅名下的点播源与直播源;-- **管理边界**:订阅源以远端列表为准,单独编辑会在下次同步时被覆盖,单独移除会在重新同步时恢复;如需调整请改远端列表,或直接删除整个订阅。删除订阅时点播源全部移除;直播源为**多归属共享**——同一 M3U 可被多个订阅引用(名称/EPG 以首次导入为准),删除只移除自己的引用,仅当不再被任何订阅引用时才移除该源,**收藏的频道始终保留**;+- **管理边界**:订阅源以远端列表为准,单独编辑会在下次同步时被覆盖,单独移除会在重新同步时恢复;如需调整请改远端列表,或直接删除整个订阅。删除订阅时点播源全部移除;直播源为**多归属共享**——同一 M3U 可被多个订阅引用(名称/EPG 以首次导入为准),删除订阅或远端列表中移除该源后再同步,都只摘除本订阅的引用,仅当不再被任何订阅引用时才移除该源,手动添加的源不受同步影响,**收藏的频道始终保留**;- **导出分享**:设置 → 源管理 → 数据源订阅 → 「导出数据源」,把当前全部点播源与直播源(预置 + 手动 + 订阅,按 URL 去重)导出为上述 JSON;也可用「发布为链接」,把当前**已勾选启用**的源一键上传到公开粘贴板(paste.rs,失败自动降级 0x0.st),直接返回可填入订阅框的 URL,无需自备托管。注意:发布的内容**公开可读**,且每次发布生成新链接、不支持覆盖更新,需长期稳定请用导出 + 自行托管。> 订阅由服务端拉取(经过 SSRF 校验),因此订阅地址无需配置 CORS。完整说明见 [数据源文档](https://github.com/bestZwei/LibreTV-Next/wiki/Data-Sources)。diff --git a/src/lib/store.test.ts b/src/lib/store.test.tsindex 9b3eb37..e2c38d2 100644--- a/src/lib/store.test.ts+++ b/src/lib/store.test.ts@@ -164,6 +164,32 @@ describe('订阅同步的 store 语义', () => {expect(store().liveSubscriptions[0].fromSubscriptions).toEqual([]);});+ it('同步缺席即摘除归属:共享源降级为其他订阅的引用,双方都缺席才移除', () => {+ const shared = 'https://live.example.com/shared.m3u';+ store().applySubscriptionLive('https://a.example.com/list.json', [{ name: '共享', url: shared }]);+ store().applySubscriptionLive('https://b.example.com/list.json', [{ name: '共享', url: shared }]);+ useAppStore.setState({ liveSelectedUrls: [shared] });++ // A 的远端列表删掉了共享源:摘除 A 的引用,源保留给 B,A 的计数归 0+ expect(store().applySubscriptionLive('https://a.example.com/list.json', [])).toBe(0);+ expect(store().liveSubscriptions).toHaveLength(1);+ expect(store().liveSubscriptions[0].fromSubscriptions).toEqual(['https://b.example.com/list.json']);+ expect(store().liveSelectedUrls).toContain(shared);++ // B 也删掉后无人引用,源随同步移除并清理启用状态+ expect(store().applySubscriptionLive('https://b.example.com/list.json', [])).toBe(0);+ expect(store().liveSubscriptions).toHaveLength(0);+ expect(store().liveSelectedUrls).not.toContain(shared);+ });++ it('手动添加的直播源缺席同步时不被移除', () => {+ const m1 = 'https://live.example.com/1.m3u';+ store().addLiveSubscription(m1, '手动');+ store().applySubscriptionLive('https://a.example.com/list.json', []);+ expect(store().liveSubscriptions).toHaveLength(1);+ expect(store().liveSubscriptions[0].url).toBe(m1);+ });+it('删除订阅:共享的直播源保留给其他订阅,独占的才移除', () => {const shared = 'https://live.example.com/shared.m3u';const exclusive = 'https://live.example.com/exclusive.m3u';diff --git a/src/lib/store.ts b/src/lib/store.tsindex 188bedb..346721f 100644--- a/src/lib/store.ts+++ b/src/lib/store.ts@@ -477,13 +477,20 @@ export const useAppStore = create<AppState>()(nextByUrl.set(s.url, { ...current, fromSubscriptions: [...current.fromSubscriptions, subUrl] });}}- // 不在本次列表中的条目原样保留;仅当被本订阅唯一持有且本次消失时才移除+ // 不在本次列表中的条目:摘除本订阅的归属引用(远端已删即不再持有)——+ // 摘除后仍被其他订阅引用的降级为其引用;不再被任何订阅引用的订阅源随本次同步移除;+ // 手动添加的源(无订阅归属)由用户完全掌控,不受同步影响for (const s of existing) {if (nextByUrl.has(s.url)) continue;- if (s.fromSubscriptions.includes(subUrl) && s.fromSubscriptions.length === 1) {- orphanUrls.add(s.url);- } else {+ if (!s.fromSubscriptions.includes(subUrl)) {nextByUrl.set(s.url, s);+ continue;+ }+ const rest = s.fromSubscriptions.filter((u) => u !== subUrl);+ if (rest.length > 0) {+ nextByUrl.set(s.url, { ...s, fromSubscriptions: rest });+ } else {+ orphanUrls.add(s.url);}}