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

Configure Feed

Select the types of activity you want to include in your feed.

at v4 59 lines 1.7 kB view raw
1import { musicMetadataTags } from "~/components/metadata/common.js"; 2import { ostiary, rpc, workerProxy } from "~/common/worker.js"; 3 4/** 5 * @import {Extraction} from "~/components/metadata/audio-file/types.d.ts" 6 * @import {ActionsWithTunnel, ProxiedActions} from "~/common/worker.d.ts" 7 * @import {InputActions} from "~/components/input/types.d.ts" 8 * @import {Actions} from "~/components/artwork/types.d.ts" 9 */ 10 11//////////////////////////////////////////// 12// ACTIONS 13//////////////////////////////////////////// 14 15/** 16 * @type {ActionsWithTunnel<Actions>['get']} 17 */ 18export async function get({ data: track, ports }) { 19 /** @type {ProxiedActions<InputActions>} */ 20 const input = workerProxy(() => { 21 ports.input.start(); 22 return ports.input; 23 }); 24 25 const resGet = await input.resolve({ method: "GET", uri: track.uri }); 26 if (!resGet) return null; 27 28 const resHead = "stream" in resGet 29 ? undefined 30 : await input.resolve({ method: "HEAD", uri: track.uri }); 31 32 const meta = await musicMetadataTags({ 33 includeArtwork: true, 34 stream: "stream" in resGet ? resGet.stream : undefined, 35 mimeType: "stream" in resGet ? resGet.mimeType : undefined, 36 urls: "url" in resGet 37 ? { 38 get: resGet.url, 39 head: resHead && "url" in resHead ? resHead.url : resGet.url, 40 } 41 : undefined, 42 }).catch(/** @param {Error} err */ (err) => { 43 console.error("music-metadata error", err); 44 return /** @type {Extraction} */ ({}); 45 }); 46 47 const pictures = meta.artwork ?? []; 48 if (!pictures.length) return null; 49 50 return pictures[0].data; 51} 52 53//////////////////////////////////////////// 54// ⚡️ 55//////////////////////////////////////////// 56 57ostiary((context) => { 58 rpc(context, { get }); 59});