A music player that connects to your cloud/distributed storage.

fix: atproto tracks.put

+12 -6
+12 -6
src/components/output/raw/atproto/element.js
··· 8 8 9 9 import { computed, signal } from "~/common/signal.js"; 10 10 import { BroadcastedOutputElement, outputManager } from "../../common.js"; 11 - import * as Output from "~/common/output.js"; 12 11 13 12 import { 14 13 clearStoredSession, ··· 20 19 } from "./oauth.js"; 21 20 22 21 /** 23 - * @import {TrackBundle} from "~/definitions/types.d.ts" 22 + * @import {Track, TrackBundle} from "~/definitions/types.d.ts" 24 23 * @import {OutputManager} from "../../types.d.ts" 25 24 * @import {ATProtoOutputElement} from "./types.d.ts" 26 25 */ ··· 63 62 constructor() { 64 63 super(); 65 64 65 + /** @type {Track[] | null} */ 66 + let lastPersistedTracks = null; 67 + 66 68 /** @type {OutputManager} */ 67 69 this.#manager = outputManager({ 68 70 facets: { ··· 82 84 "sh.diffuse.output.trackBundle", 83 85 ); 84 86 85 - return bundles.flatMap((bundle) => bundle.tracks ?? []); 87 + const tracks = bundles.flatMap((bundle) => bundle.tracks ?? []); 88 + lastPersistedTracks = tracks; 89 + 90 + return tracks; 86 91 }, 87 92 put: async (data) => { 88 - const current = await Output.data(this.#manager.tracks); 89 - const hashCurrent = xxh32r(encode(current)); 93 + const hashCurrent = xxh32r(encode(lastPersistedTracks ?? [])); 90 94 const hashNew = xxh32r(encode(data)); 91 95 92 96 if (hashCurrent === hashNew) { ··· 104 108 }); 105 109 } 106 110 107 - return this.#putRecords("sh.diffuse.output.trackBundle", bundles, { 111 + await this.#putRecords("sh.diffuse.output.trackBundle", bundles, { 108 112 upsertBatchSize: 1, 109 113 }); 114 + 115 + lastPersistedTracks = data; 110 116 }, 111 117 }, 112 118 });