refactor(hifi): update HiFi.ts to add trackManifests route and refactor

This commit is contained in:
Daniel 2026-03-23 13:42:03 -05:00
parent 21cbfcdbf4
commit 2440939f4b
7 changed files with 497 additions and 256 deletions

View file

@ -24,6 +24,7 @@
"client-zip": "^2.5.0",
"cookie-session": "^2.1.1",
"eventemitter3": "^5.0.4",
"events": "^3.3.0",
"fuse.js": "^7.1.0",
"hls.js": "^1.6.15",
"jose": "^6.2.0",
@ -949,6 +950,8 @@
"eventemitter3": ["eventemitter3@5.0.4", "", {}, "sha512-mlsTRyGaPBjPedk6Bvw+aqbsXDtoAyAzm5MO7JgU+yVRyMQ5O8bD4Kcci7BS85f93veegeCPkL8R4GLClnjLFw=="],
"events": ["events@3.3.0", "", {}, "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q=="],
"events-universal": ["events-universal@1.0.1", "", { "dependencies": { "bare-events": "^2.7.0" } }, "sha512-LUd5euvbMLpwOF8m6ivPCbhQeSiYVNb8Vs0fQ8QjXo0JTkEHpz8pxdQf0gStltaPpw0Cca8b39KxvK9cfKRiAw=="],
"expand-template": ["expand-template@2.0.3", "", {}, "sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg=="],

File diff suppressed because it is too large Load diff

View file

@ -56,7 +56,14 @@ export class LosslessAPI {
async fetchWithRetry(relativePath, options = {}) {
const type = options.type || 'api';
const instanceRoutes = ['/track', '/album/similar', '/artist/similar', '/video', '/recommendations'];
const instanceRoutes = [
'/track',
'/album/similar',
'/artist/similar',
'/video',
'/recommendations',
'/trackManifests',
];
if (window.allTidal == true || !instanceRoutes.some((route) => relativePath.startsWith(route))) {
try {
@ -64,7 +71,7 @@ export class LosslessAPI {
console.log(relativePath);
}
return await HiFiClient.instance.queryResponse(relativePath);
return await HiFiClient.instance.query(relativePath);
} catch (err) {
console.warn(
`Direct fetch failed for ${relativePath}. Falling back to configured API instances...`,

View file

@ -399,7 +399,22 @@ document.addEventListener('DOMContentLoaded', async () => {
initAnalytics();
new ThemeStore();
await HiFiClient.initialize();
await HiFiClient.initialize({
storage: [
localStorage,
...(import.meta.env.DEV
? [
{
setItem: (key, value) => console.debug(`HiFiClient storage set: ${key} = ${value}`),
removeItem: (key) => console.debug(`HiFiClient storage remove: ${key}`),
},
]
: []),
],
token: localStorage.getItem('hifi_token') || undefined,
tokenExpiry: parseInt(localStorage.getItem('hifi_token_expiry') || '0'),
});
await MusicAPI.initialize(apiSettings);
const audioPlayer = document.getElementById('audio-player');

View file

@ -72,6 +72,7 @@
"client-zip": "^2.5.0",
"cookie-session": "^2.1.1",
"eventemitter3": "^5.0.4",
"events": "^3.3.0",
"fuse.js": "^7.1.0",
"hls.js": "^1.6.15",
"jose": "^6.2.0",

View file

@ -1,7 +1,7 @@
import { HiFiClient } from './js/HiFi.ts';
async function test() {
const client = new HiFiClient();
const res = await client.queryResponse('/search/?q=alskdjfalksjdfld&limit=5');
const res = await client.query('/search/?q=alskdjfalksjdfld&limit=5');
const json = await res.json();
console.log(JSON.stringify(json.data || {}));
}

View file

@ -21,6 +21,7 @@ export default defineConfig(({ mode }) => {
'!simpleicons': '/node_modules/simple-icons/icons',
'!': '/node_modules',
events: '/node_modules/events/events.js',
pocketbase: '/node_modules/pocketbase/dist/pocketbase.es.js',
stream: path.resolve(__dirname, 'stream-stub.js'), // Stub for stream module
},