Podcast: resume where you left off, synced between devices (shared progress store with audiobooks)
build-container / build (push) Successful in 9m26s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
nmemmertandClaude Sonnet 5.5 committed 2026-10-22 15:37:51 -04:00
1 parent aa2133ed9a
commit b3494b9720
5 files changed
+61 -16

No files matched your search

+2 -9
View File
@@ -5,7 +5,6 @@
// (the account in Settings), or with the shared secret link (AUDIOBOOKS_LOGIN_LINK). The player keeps the positions.
// No password or link ever reaches the browser.
const { Readable } = require('stream');
const fs = require('fs'), path = require('path');
const settings = require('./settings');
const users = require('./users');
@@ -46,14 +45,8 @@ async function direct(path, init = {}) {
return r;
}
// Listening positions kept by the hub (direct mode): one file per person, the newest time wins for each book.
const progFile = () => path.join(users.dir(), 'audiobook-progress.json');
const progLoad = () => { try { return JSON.parse(fs.readFileSync(progFile(), 'utf8')); } catch { return {}; } };
function progMerge(body) {
const mine = progLoad();
for (const [k, v] of Object.entries(body || {})) if (v && typeof v === 'object' && (v.t || 0) >= ((mine[k] || {}).t || 0)) mine[k] = { pos: +v.pos || 0, dur: +v.dur || 0, t: +v.t || 0 };
const f = progFile(), tmp = f + '.tmp'; fs.writeFileSync(tmp, JSON.stringify(mine), { mode: 0o600 }); fs.renameSync(tmp, f); return mine;
}
// Listening positions kept by the hub (direct mode)
const prog = require('./progress')('audiobook-progress.json'), progLoad = prog.load, progMerge = prog.merge;
async function upstream(me, path, init = {}, retry = true) {
if (OA) return direct(path, init);