z
This commit is contained in:
parent
2942669f53
commit
2cad1aa1b3
2 changed files with 81 additions and 21 deletions
42
lib/api.ts
42
lib/api.ts
|
|
@ -12,25 +12,25 @@ let apiBaseUrl = "https://qqdl.site/api"
|
||||||
|
|
||||||
export const setApiBaseUrl = (url: string) => {
|
export const setApiBaseUrl = (url: string) => {
|
||||||
apiBaseUrl = url
|
apiBaseUrl = url
|
||||||
console.log("[v0] API base URL set to:", url)
|
console.log("API base URL set to:", url)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getApiBaseUrl = () => apiBaseUrl
|
export const getApiBaseUrl = () => apiBaseUrl
|
||||||
|
|
||||||
export const searchMusic = async (query: string): Promise<Album[]> => {
|
export const searchMusic = async (query: string): Promise<Album[]> => {
|
||||||
const url = `${apiBaseUrl}/get-music?q=${encodeURIComponent(query)}&offset=0&type=track`
|
const url = `${apiBaseUrl}/get-music?q=${encodeURIComponent(query)}&offset=0&type=track`
|
||||||
console.log("[v0] Searching music:", url)
|
console.log("Searching music:", url)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(url)
|
const response = await fetch(url)
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
console.error("[v0] Search failed with status:", response.status, response.statusText)
|
console.error("Search failed with status:", response.status, response.statusText)
|
||||||
throw new Error(`Failed to search music: ${response.status}`)
|
throw new Error(`Failed to search music: ${response.status}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const data: SearchResponse = await response.json()
|
const data: SearchResponse = await response.json()
|
||||||
console.log("[v0] Search response success:", data.success, "Albums found:", data.data?.albums?.items?.length || 0)
|
console.log("Search response success:", data.success, "Albums found:", data.data?.albums?.items?.length || 0)
|
||||||
|
|
||||||
if (!data.success) {
|
if (!data.success) {
|
||||||
throw new Error("Search failed")
|
throw new Error("Search failed")
|
||||||
|
|
@ -38,20 +38,20 @@ export const searchMusic = async (query: string): Promise<Album[]> => {
|
||||||
|
|
||||||
return data.data.albums.items
|
return data.data.albums.items
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("[v0] Search error:", error)
|
console.error("Search error:", error)
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getAlbumDetails = async (albumId: string): Promise<AlbumDetails> => {
|
export const getAlbumDetails = async (albumId: string): Promise<AlbumDetails> => {
|
||||||
const url = `${apiBaseUrl}/get-album?album_id=${albumId}`
|
const url = `${apiBaseUrl}/get-album?album_id=${albumId}`
|
||||||
console.log("[v0] Fetching album:", url)
|
console.log("Fetching album:", url)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(url)
|
const response = await fetch(url)
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
console.error("[v0] Album fetch failed with status:", response.status, response.statusText)
|
console.error("Album fetch failed with status:", response.status, response.statusText)
|
||||||
throw new Error(`Failed to fetch album details: ${response.status}`)
|
throw new Error(`Failed to fetch album details: ${response.status}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -61,23 +61,23 @@ export const getAlbumDetails = async (albumId: string): Promise<AlbumDetails> =>
|
||||||
throw new Error("Failed to load album")
|
throw new Error("Failed to load album")
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("[v0] Album loaded:", data.data.title, "Tracks:", data.data.tracks.items.length)
|
console.log("Album loaded:", data.data.title, "Tracks:", data.data.tracks.items.length)
|
||||||
return data.data
|
return data.data
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("[v0] Album fetch error:", error)
|
console.error("Album fetch error:", error)
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getArtistDetails = async (artistId: number) => {
|
export const getArtistDetails = async (artistId: number) => {
|
||||||
const url = `${apiBaseUrl}/get-artist?artist_id=${artistId}`
|
const url = `${apiBaseUrl}/get-artist?artist_id=${artistId}`
|
||||||
console.log("[v0] Fetching artist:", url)
|
console.log("Fetching artist:", url)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(url)
|
const response = await fetch(url)
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
console.error("[v0] Artist fetch failed with status:", response.status, response.statusText)
|
console.error("Artist fetch failed with status:", response.status, response.statusText)
|
||||||
throw new Error(`Failed to fetch artist details: ${response.status}`)
|
throw new Error(`Failed to fetch artist details: ${response.status}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,22 +87,22 @@ export const getArtistDetails = async (artistId: number) => {
|
||||||
throw new Error("Failed to load artist")
|
throw new Error("Failed to load artist")
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("[v0] Artist loaded:", data.data.artist.name.display)
|
console.log("Artist loaded:", data.data.artist.name.display)
|
||||||
return data.data.artist
|
return data.data.artist
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("[v0] Artist fetch error:", error)
|
console.error("Artist fetch error:", error)
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getTrackStreamUrl = async (trackId: string): Promise<string> => {
|
export const getTrackStreamUrl = async (trackId: string): Promise<string> => {
|
||||||
const url = `${apiBaseUrl}/download-music?track_id=${trackId}`
|
const url = `${apiBaseUrl}/download-music?track_id=${trackId}`
|
||||||
console.log("[v0] Fetching stream URL for track:", trackId, "from:", url)
|
console.log("Fetching stream URL for track:", trackId, "from:", url)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(url)
|
const response = await fetch(url)
|
||||||
|
|
||||||
console.log("[v0] Stream URL fetch response:", {
|
console.log("Stream URL fetch response:", {
|
||||||
status: response.status,
|
status: response.status,
|
||||||
statusText: response.statusText,
|
statusText: response.statusText,
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -113,12 +113,12 @@ export const getTrackStreamUrl = async (trackId: string): Promise<string> => {
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
console.error("[v0] Stream URL fetch failed with status:", response.status, response.statusText)
|
console.error("Stream URL fetch failed with status:", response.status, response.statusText)
|
||||||
throw new Error(`Failed to fetch stream URL: ${response.status}`)
|
throw new Error(`Failed to fetch stream URL: ${response.status}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const data: StreamResponse = await response.json()
|
const data: StreamResponse = await response.json()
|
||||||
console.log("[v0] Stream URL response:", {
|
console.log("Stream URL response:", {
|
||||||
success: data.success,
|
success: data.success,
|
||||||
hasUrl: !!data.data?.url,
|
hasUrl: !!data.data?.url,
|
||||||
urlLength: data.data?.url?.length,
|
urlLength: data.data?.url?.length,
|
||||||
|
|
@ -131,20 +131,20 @@ export const getTrackStreamUrl = async (trackId: string): Promise<string> => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const testResponse = await fetch(data.data.url, { method: "HEAD" })
|
const testResponse = await fetch(data.data.url, { method: "HEAD" })
|
||||||
console.log("[v0] Stream URL accessibility test:", {
|
console.log("Stream URL accessibility test:", {
|
||||||
status: testResponse.status,
|
status: testResponse.status,
|
||||||
statusText: testResponse.statusText,
|
statusText: testResponse.statusText,
|
||||||
contentType: testResponse.headers.get("content-type"),
|
contentType: testResponse.headers.get("content-type"),
|
||||||
cors: testResponse.headers.get("access-control-allow-origin"),
|
cors: testResponse.headers.get("access-control-allow-origin"),
|
||||||
})
|
})
|
||||||
} catch (testError) {
|
} catch (testError) {
|
||||||
console.error("[v0] Stream URL accessibility test failed:", testError)
|
console.error("Stream URL accessibility test failed:", testError)
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("[v0] Stream URL obtained successfully")
|
console.log("Stream URL obtained successfully")
|
||||||
return data.data.url
|
return data.data.url
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("[v0] Stream URL fetch error:", error)
|
console.error("Stream URL fetch error:", error)
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
60
package-lock.json
generated
60
package-lock.json
generated
|
|
@ -1923,6 +1923,66 @@
|
||||||
"node": ">=14.0.0"
|
"node": ">=14.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/@emnapi/core": {
|
||||||
|
"version": "1.4.5",
|
||||||
|
"dev": true,
|
||||||
|
"inBundle": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@emnapi/wasi-threads": "1.0.4",
|
||||||
|
"tslib": "^2.4.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/@emnapi/runtime": {
|
||||||
|
"version": "1.4.5",
|
||||||
|
"dev": true,
|
||||||
|
"inBundle": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"dependencies": {
|
||||||
|
"tslib": "^2.4.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/@emnapi/wasi-threads": {
|
||||||
|
"version": "1.0.4",
|
||||||
|
"dev": true,
|
||||||
|
"inBundle": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"dependencies": {
|
||||||
|
"tslib": "^2.4.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/@napi-rs/wasm-runtime": {
|
||||||
|
"version": "0.2.12",
|
||||||
|
"dev": true,
|
||||||
|
"inBundle": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@emnapi/core": "^1.4.3",
|
||||||
|
"@emnapi/runtime": "^1.4.3",
|
||||||
|
"@tybys/wasm-util": "^0.10.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/@tybys/wasm-util": {
|
||||||
|
"version": "0.10.0",
|
||||||
|
"dev": true,
|
||||||
|
"inBundle": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"dependencies": {
|
||||||
|
"tslib": "^2.4.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/tslib": {
|
||||||
|
"version": "2.8.0",
|
||||||
|
"dev": true,
|
||||||
|
"inBundle": true,
|
||||||
|
"license": "0BSD",
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
"node_modules/@tailwindcss/oxide-win32-arm64-msvc": {
|
"node_modules/@tailwindcss/oxide-win32-arm64-msvc": {
|
||||||
"version": "4.1.13",
|
"version": "4.1.13",
|
||||||
"resolved": "https://registry.npmjs.org/@tailwindcss/oxide-win32-arm64-msvc/-/oxide-win32-arm64-msvc-4.1.13.tgz",
|
"resolved": "https://registry.npmjs.org/@tailwindcss/oxide-win32-arm64-msvc/-/oxide-win32-arm64-msvc-4.1.13.tgz",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue