mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 13:27:08 +00:00
fix: query song add fallback
This commit is contained in:
parent
7635781695
commit
3561f7c99d
1 changed files with 18 additions and 11 deletions
|
|
@ -57,20 +57,27 @@ export class SunoClient {
|
|||
let ids = createData?.clips?.map(clip => clip.id)
|
||||
let queryUrl = `https://studio-api.suno.ai/api/feed/?ids=${ids[0]}%2C${ids[1]}`
|
||||
let allDone = false; let songs = []
|
||||
while (!allDone) {
|
||||
let queryRes = await newFetch(queryUrl, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${sess}`
|
||||
let timeout = 60
|
||||
while (timeout > 0 && !allDone) {
|
||||
try {
|
||||
let queryRes = await newFetch(queryUrl, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${sess}`
|
||||
}
|
||||
})
|
||||
if (queryRes.status !== 200) {
|
||||
logger.error(await queryRes.text())
|
||||
console.error('Failed to query song')
|
||||
}
|
||||
})
|
||||
if (queryRes.status !== 200) {
|
||||
throw new Error('Failed to query song')
|
||||
let queryData = await queryRes.json()
|
||||
logger.debug(queryData)
|
||||
allDone = queryData.every(clip => clip.status === 'complete')
|
||||
songs = queryData
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
let queryData = await queryRes.json()
|
||||
logger.debug(queryData)
|
||||
allDone = queryData.every(clip => clip.status === 'complete')
|
||||
songs = queryData
|
||||
await common.sleep(1000)
|
||||
timeout--
|
||||
}
|
||||
return songs
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue