fix: suppress VAD debug logs, spotify no-device graceful, filter tool names from response
Some checks failed
Deploy / deploy (push) Failing after 45s
Some checks failed
Deploy / deploy (push) Failing after 45s
This commit is contained in:
@@ -15,29 +15,41 @@ async function spotifyFetch(path: string, method = 'GET', body?: any) {
|
||||
if (res.status === 204) return { success: true }
|
||||
if (!res.ok) {
|
||||
const err = await res.text()
|
||||
// Специальная обработка: нет активного устройства
|
||||
if (res.status === 404 && err.includes('NO_ACTIVE_DEVICE')) {
|
||||
throw Object.assign(new Error('NO_ACTIVE_DEVICE'), { code: 'NO_ACTIVE_DEVICE' })
|
||||
}
|
||||
throw new Error(`Spotify API ${res.status}: ${err}`)
|
||||
}
|
||||
return res.json().catch(() => ({ success: true }))
|
||||
}
|
||||
|
||||
export async function GET() {
|
||||
// Get current playback state
|
||||
const data = await spotifyFetch('/me/player')
|
||||
if (!data || !data.item) return NextResponse.json({ playing: false })
|
||||
return NextResponse.json({
|
||||
playing: data.is_playing,
|
||||
track: data.item.name,
|
||||
artist: data.item.artists?.map((a: any) => a.name).join(', '),
|
||||
album: data.item.album?.name,
|
||||
volume: data.volume_percent,
|
||||
device: data.device?.name,
|
||||
})
|
||||
try {
|
||||
// Get current playback state
|
||||
const data = await spotifyFetch('/me/player')
|
||||
if (!data || !data.item) return NextResponse.json({ playing: false })
|
||||
return NextResponse.json({
|
||||
playing: data.is_playing,
|
||||
track: data.item.name,
|
||||
artist: data.item.artists?.map((a: any) => a.name).join(', '),
|
||||
album: data.item.album?.name,
|
||||
volume: data.volume_percent,
|
||||
device: data.device?.name,
|
||||
})
|
||||
} catch (e: any) {
|
||||
if (e?.code === 'NO_ACTIVE_DEVICE' || e?.message === 'NO_ACTIVE_DEVICE') {
|
||||
return NextResponse.json({ error: 'no_active_device', message: 'Нет активного устройства Spotify. Открой Spotify на телефоне или ноутбуке.' }, { status: 200 })
|
||||
}
|
||||
return NextResponse.json({ error: String(e?.message || e) }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const body = await req.json()
|
||||
const { action, query, volume } = body
|
||||
|
||||
try {
|
||||
switch (action) {
|
||||
case 'play':
|
||||
if (query) {
|
||||
@@ -75,4 +87,10 @@ export async function POST(req: NextRequest) {
|
||||
default:
|
||||
return NextResponse.json({ error: 'unknown action' }, { status: 400 })
|
||||
}
|
||||
} catch (e: any) {
|
||||
if (e?.code === 'NO_ACTIVE_DEVICE' || e?.message === 'NO_ACTIVE_DEVICE') {
|
||||
return NextResponse.json({ error: 'no_active_device', message: 'Нет активного устройства Spotify. Открой Spotify на телефоне или ноутбуке.' }, { status: 200 })
|
||||
}
|
||||
return NextResponse.json({ error: String(e?.message || e) }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user