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

fix: don't make opensubsonic servers download the whole audio file

+41 -3
+20
src/components/input/opensubsonic/class.js
··· 1 + import { SubsonicAPI } from "subsonic-api"; 2 + 3 + export class SubsonicAPIWithoutFetch extends SubsonicAPI { 4 + /** 5 + * @param {import("./types.d.ts").SubsonicConfig} config 6 + */ 7 + constructor(config) { 8 + super({ 9 + ...config, 10 + fetch: async (path, params) => { 11 + if (path.toString().includes("/rest/stream.view")) { 12 + return await fetch(path, { ...params, method: "HEAD" }); 13 + } else { 14 + return await fetch(path, params); 15 + } 16 + }, 17 + }); 18 + this.config = config; 19 + } 20 + }
+2 -2
src/components/input/opensubsonic/common.js
··· 1 - import { SubsonicAPI } from "subsonic-api"; 2 1 import * as URI from "uri-js"; 3 2 import QS from "query-string"; 4 3 5 4 import { SCHEME } from "./constants.js"; 5 + import { SubsonicAPIWithoutFetch } from "./class.js"; 6 6 7 7 /** 8 8 * @import {Child} from "subsonic-api" ··· 65 65 * @param {Server} server 66 66 */ 67 67 export function createClient(server) { 68 - return new SubsonicAPI({ 68 + return new SubsonicAPIWithoutFetch({ 69 69 url: `http${server.tls ? "s" : ""}://${server.host}`, 70 70 auth: server.apiKey ? { apiKey: URI.unescapeComponent(server.apiKey) } : { 71 71 username: URI.unescapeComponent(server.username || ""),
+18
src/components/input/opensubsonic/types.d.ts
··· 6 6 tls: boolean; 7 7 username?: string; 8 8 }; 9 + 10 + export interface SubsonicConfig { 11 + /** The base URL of the Subsonic server, e.g., https://demo.navidrome.org. */ 12 + url: string; 13 + 14 + /** The authentication details to use when connecting to the server. */ 15 + auth: 16 + | { 17 + username: string; 18 + password: string; 19 + apiKey?: never; 20 + } 21 + | { 22 + username?: never; 23 + password?: never; 24 + apiKey: string; 25 + }; 26 + }
+1 -1
src/components/input/opensubsonic/worker.js
··· 265 265 // const expiresAtSeconds = Math.round(Date.now() / 1000) + expiresInSeconds; 266 266 267 267 const url = await client 268 - .download({ 268 + .stream({ 269 269 id: songId, 270 270 format: "raw", 271 271 })