Something went wrong. Try again.
A music player that connects to your cloud/distributed storage. forked from tokono.ma/diffuse
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495import * as IDB from "idb-keyval";
import { IDB_PREFIX } from "./constants.js";import { BroadcastedOutputElement, outputManager } from "../../common.js";import { defineElement } from "~/common/element.js";
/** * @import {OutputElement, OutputManager, OutputWorkerActions} from "../../types.d.ts" * @import {SupportedDataTypes} from "./types.d.ts" */
////////////////////////////////////////////// ELEMENT////////////////////////////////////////////
/** * @implements {OutputElement<SupportedDataTypes>} */class IndexedDBOutput extends BroadcastedOutputElement { static NAME = "diffuse/output/polymorphic/indexed-db"; static WORKER_URL = "components/output/polymorphic/indexed-db/worker.js";
#manager;
constructor() { super();
/** @type {OutputManager<SupportedDataTypes>} */ this.#manager = outputManager({ facets: { empty: () => undefined, get: () => this.#get("facets"), put: (data) => this.#put("facets", data), }, init: () => this.whenConnected(), playlistItems: { empty: () => undefined, get: () => this.#get("playlistItems"), put: (data) => this.#put("playlistItems", data), }, settings: { empty: () => undefined, get: () => this.#get("settings"), put: (data) => this.#put("settings", data), }, tracks: { empty: () => undefined, get: () => this.#get("tracks"), put: (data) => this.#put("tracks", data), }, });
this.facets = this.#manager.facets; this.playlistItems = this.#manager.playlistItems; this.settings = this.#manager.settings; this.tracks = this.#manager.tracks;
this.ready = () => true; }
// LIFECYCLE
/** @override */ connectedCallback() { this.replicateSavedData(this.#manager); super.connectedCallback(); }
// GET & PUT
/** @param {string} name */ #get = (name) => IDB.get(`${IDB_PREFIX}/${this.#cat(name)}`);
/** @param {string} name; @param {any} data */ #put = (name, data) => IDB.set(`${IDB_PREFIX}/${this.#cat(name)}`, data);
// 🛠️
/** @param {string} name */ #cat(name) { return `${this.namespace?.length ? this.namespace + "/" : ""}${name}`; }}
export default IndexedDBOutput;
////////////////////////////////////////////// REGISTER////////////////////////////////////////////
export const CLASS = IndexedDBOutput;export const NAME = "dop-indexed-db";
defineElement(NAME, IndexedDBOutput);