Fixed podcast sync

This commit is contained in:
ab committed 2026-11-22 17:11:37 +02:00
1 parent 441316f78f
commit 319f0bcba7
21 files changed
+1067 -276

No files matched your search

+15
View File
@@ -0,0 +1,15 @@
CREATE TABLE furumusic__fed_device_identity (
user_id BIGINT PRIMARY KEY, device_id TEXT NOT NULL, group_id TEXT NOT NULL,
device_name TEXT NOT NULL, local_seq BIGINT DEFAULT 0, last_hlc_ms BIGINT DEFAULT 0,
local_seeded_at_ms BIGINT NOT NULL DEFAULT 1
);
CREATE TABLE furumusic__fed_sync_ops (
user_id BIGINT, op_id TEXT, origin_device_id TEXT, seq BIGINT, kind TEXT,
payload_json JSONB, hlc_ms BIGINT, received_at_ms BIGINT, tombstone BOOLEAN,
PRIMARY KEY(user_id,op_id)
);
CREATE TABLE furumusic__fed_sync_vector (
user_id BIGINT, device_id TEXT, max_seq BIGINT, PRIMARY KEY(user_id,device_id)
);
INSERT INTO furumusic__fed_device_identity(user_id,device_id,group_id,device_name)
VALUES(1,'web_test_one','group_test','one'),(2,'web_test_two','group_test','two');
+19 -3
View File
@@ -4,12 +4,12 @@ const {test} = require('node:test');
const vm = require('node:vm');
const source = readFileSync(`${__dirname}/../templates/player/podcast_scripts.html`, 'utf8').replace(/<\/?script>/g, '');
function setup(responder=()=>({})) {
const calls=[],stores={library:{view:'artists'},mobile:{closeLibrary(){}},player:{_playLocal(track,options){this.currentTrack=track;this.options=options;},seek(){}}};
const calls=[],stores={library:{view:'artists',_beginNavigation(){}},mobile:{closeLibrary(){}},player:{_playLocal(track,options){this.currentTrack=track;this.options=options;},seek(){}}};
vm.runInNewContext(source,{
document:{documentElement:{lang:'ru'},addEventListener(_,fn){fn();}},
Alpine:{store(name,value){if(value)stores[name]=value;return stores[name];}},
fetch:async(url,options)=>{const body=JSON.parse(options.body);calls.push(body);return {ok:true,json:async()=>responder(body)};},
confirm:()=>true,setInterval:()=>1,Date,Map,Set,Blob,navigator:{sendBeacon(){}},
confirm:()=>true,setInterval:()=>1,Date,Map,Set,Blob,location:{hash:''},navigator:{sendBeacon(){}},
});
return {store:stores.podcasts,stores,calls};
}
@@ -44,7 +44,7 @@ test('marking unplayed is an explicit reset and advances the active session gene
test('filtering combines season, title and played status without mixing podcasts with music',()=>{
const {store}=setup();store.episodes=[{...episode},{...episode,id:'other',completed:true},{...episode,id:'season3',metadata:{...episode.metadata,season:3}}];
store.filter='epis';store.season='2';store.unplayedOnly=true;assert.deepEqual(Array.from(store.filteredEpisodes(),e=>e.id),[episode.id]);
store.public=[{id:'a',url:'origin'}];store.hits=[{id:'a',url:'origin'},{id:'b',url:'other'}];assert.equal(store.publicCards().length,2);
store.public=[{id:'a',url:'origin'}];store.hits=[{id:'a',url:'origin'},{id:'b',url:'other'}];store.searched=true;assert.equal(store.publicCards().length,2);
});
test('private URL publication requires a separate confirmation; revocation does not republish',async()=>{
const {store,calls}=setup(body=>body.action==='share'&&!body.confirmed?{confirmation_required:true,urls:['https://example.test/feed?token=private']}:body.action==='list'?{mine:[],public:[]}:{ok:true});
@@ -68,3 +68,19 @@ test('new episodes do not create gaps in previously loaded pages',async()=>{
await store.loadEpisodes();assert.equal(store.episodes.length,203);
assert.equal(store.episodes[0].id,'new');assert.ok(store.episodes.some(e=>e.id==='episode-199'));
});
test('opening podcast navigation starts polling and search results open existing subscriptions',async()=>{
const podcast={id:'show',metadata:{title:'Show'},subscribed:true};
const {store,stores,calls}=setup(body=>body.action==='list'?{mine:[podcast],public:[]}:body.action==='episodes'?{episodes:[],has_more:false}:{});
await store.enter();assert.equal(store.poller,1);assert.equal(stores.library.view,'podcasts');
stores.library.view='search';await store.openResult(podcast);
assert.equal(stores.library.view,'podcasts');assert.equal(store.selected.id,'show');
assert.equal(calls.filter(c=>c.action==='add').length,0);
});
test('podcast search displays matching results instead of retaining unrelated public cards',async()=>{
const {store}=setup(()=>({hits:[{id:'matching',metadata:{title:'Found'}}]}));
store.public=[{id:'unrelated'}];store.query='космос';await store.search();
assert.deepEqual(Array.from(store.publicCards(),p=>p.id),['matching']);
store.resetSearch();assert.deepEqual(Array.from(store.publicCards(),p=>p.id),['unrelated']);
});
+14
View File
@@ -0,0 +1,14 @@
CREATE TABLE furumusic__artist(id BIGINT PRIMARY KEY,name TEXT,is_hidden BOOLEAN DEFAULT false,updated_at TEXT DEFAULT '2026-01-01');
CREATE TABLE furumusic__release(id BIGINT PRIMARY KEY,title TEXT,year INTEGER,is_hidden BOOLEAN DEFAULT false,updated_at TEXT DEFAULT '2026-01-01');
CREATE TABLE furumusic__track(id BIGINT PRIMARY KEY,title TEXT,title_sort TEXT,release_id BIGINT,disc_number INTEGER,track_number INTEGER,duration_seconds DOUBLE PRECISION,is_hidden BOOLEAN DEFAULT false,updated_at TEXT DEFAULT '2026-01-01');
CREATE TABLE furumusic__release_artist(release_id BIGINT,artist_id BIGINT);
CREATE TABLE furumusic__track_artist(track_id BIGINT,artist_id BIGINT,role TEXT DEFAULT 'main');
CREATE TABLE furumusic__user_followed_artist(user_id BIGINT,artist_id BIGINT);
CREATE TABLE furumusic__track_ref(local_track_id BIGINT,content_id TEXT);
CREATE TABLE furumusic__listen_event(content_id TEXT,qualified BOOLEAN,user_id BIGINT,listen_id TEXT);
CREATE TABLE furumusic__playlist_track(track_id BIGINT,playlist_id BIGINT);
INSERT INTO furumusic__artist(id,name) VALUES(1,'Алиса');
INSERT INTO furumusic__release(id,title) VALUES(1,'СОЛНЦЕ');
INSERT INTO furumusic__track(id,title,title_sort,release_id,duration_seconds) VALUES(1,'Ελληνικά ТРЕК','ελληνικά трек',1,123);
INSERT INTO furumusic__release_artist VALUES(1,1);
INSERT INTO furumusic__track_artist(track_id,artist_id) VALUES(1,1);