refactor(hifi): update HiFi.ts to add trackManifests route and refactor
This commit is contained in:
parent
21cbfcdbf4
commit
2440939f4b
7 changed files with 497 additions and 256 deletions
3
bun.lock
3
bun.lock
|
|
@ -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=="],
|
||||
|
|
|
|||
718
js/HiFi.ts
718
js/HiFi.ts
File diff suppressed because it is too large
Load diff
11
js/api.js
11
js/api.js
|
|
@ -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...`,
|
||||
|
|
|
|||
17
js/app.js
17
js/app.js
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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 || {}));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue