Merge pull request #401 from DanTheMan827/hifi-update
Refactor HiFi.ts and add trackManifests route
This commit is contained in:
commit
7f61e723da
7 changed files with 497 additions and 262 deletions
3
bun.lock
3
bun.lock
|
|
@ -24,6 +24,7 @@
|
||||||
"client-zip": "^2.5.0",
|
"client-zip": "^2.5.0",
|
||||||
"cookie-session": "^2.1.1",
|
"cookie-session": "^2.1.1",
|
||||||
"eventemitter3": "^5.0.4",
|
"eventemitter3": "^5.0.4",
|
||||||
|
"events": "^3.3.0",
|
||||||
"fuse.js": "^7.1.0",
|
"fuse.js": "^7.1.0",
|
||||||
"hls.js": "^1.6.15",
|
"hls.js": "^1.6.15",
|
||||||
"jose": "^6.2.0",
|
"jose": "^6.2.0",
|
||||||
|
|
@ -949,6 +950,8 @@
|
||||||
|
|
||||||
"eventemitter3": ["eventemitter3@5.0.4", "", {}, "sha512-mlsTRyGaPBjPedk6Bvw+aqbsXDtoAyAzm5MO7JgU+yVRyMQ5O8bD4Kcci7BS85f93veegeCPkL8R4GLClnjLFw=="],
|
"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=="],
|
"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=="],
|
"expand-template": ["expand-template@2.0.3", "", {}, "sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg=="],
|
||||||
|
|
|
||||||
724
js/HiFi.ts
724
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 = {}) {
|
async fetchWithRetry(relativePath, options = {}) {
|
||||||
const type = options.type || 'api';
|
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))) {
|
if (window.allTidal == true || !instanceRoutes.some((route) => relativePath.startsWith(route))) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -64,7 +71,7 @@ export class LosslessAPI {
|
||||||
console.log(relativePath);
|
console.log(relativePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await HiFiClient.instance.queryResponse(relativePath);
|
return await HiFiClient.instance.query(relativePath);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn(
|
console.warn(
|
||||||
`Direct fetch failed for ${relativePath}. Falling back to configured API instances...`,
|
`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();
|
initAnalytics();
|
||||||
|
|
||||||
new ThemeStore();
|
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);
|
await MusicAPI.initialize(apiSettings);
|
||||||
|
|
||||||
const audioPlayer = document.getElementById('audio-player');
|
const audioPlayer = document.getElementById('audio-player');
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,7 @@
|
||||||
"client-zip": "^2.5.0",
|
"client-zip": "^2.5.0",
|
||||||
"cookie-session": "^2.1.1",
|
"cookie-session": "^2.1.1",
|
||||||
"eventemitter3": "^5.0.4",
|
"eventemitter3": "^5.0.4",
|
||||||
|
"events": "^3.3.0",
|
||||||
"fuse.js": "^7.1.0",
|
"fuse.js": "^7.1.0",
|
||||||
"hls.js": "^1.6.15",
|
"hls.js": "^1.6.15",
|
||||||
"jose": "^6.2.0",
|
"jose": "^6.2.0",
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { HiFiClient } from './js/HiFi.ts';
|
import { HiFiClient } from './js/HiFi.ts';
|
||||||
async function test() {
|
async function test() {
|
||||||
const client = new HiFiClient();
|
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();
|
const json = await res.json();
|
||||||
console.log(JSON.stringify(json.data || {}));
|
console.log(JSON.stringify(json.data || {}));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ export default defineConfig(({ mode }) => {
|
||||||
'!simpleicons': '/node_modules/simple-icons/icons',
|
'!simpleicons': '/node_modules/simple-icons/icons',
|
||||||
'!': '/node_modules',
|
'!': '/node_modules',
|
||||||
|
|
||||||
|
events: '/node_modules/events/events.js',
|
||||||
pocketbase: '/node_modules/pocketbase/dist/pocketbase.es.js',
|
pocketbase: '/node_modules/pocketbase/dist/pocketbase.es.js',
|
||||||
stream: path.resolve(__dirname, 'stream-stub.js'), // Stub for stream module
|
stream: path.resolve(__dirname, 'stream-stub.js'), // Stub for stream module
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue