Spaces:
Paused
Paused
File size: 1,534 Bytes
5ed446f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
import Providers from "../providers/index.js"
import { format as lyricFormat, get_url } from "../util.js"
export default async (ctx) => {
const p = new Providers()
const query = ctx.req.query()
const server = query.server || 'tencent'
const type = query.type || 'playlist'
const id = query.id || '7326220405'
if (!p.get_provider_list().includes(server) || !p.get(server).support_type.includes(type)) {
ctx.status(400)
return ctx.json({ status: 400, message: 'server 参数不合法', param: { server, type, id } })
}
let data = await p.get(server).handle(type, id)
if (type === 'url') {
let url = data
if (!url) {
ctx.status(403)
return ctx.json({ error: 'no url' })
}
if (url.startsWith('@'))
return ctx.text(url)
return ctx.redirect(url)
}
if (type === 'pic') {
return ctx.redirect(data)
}
if (type === 'lrc') {
return ctx.text(lyricFormat(data.lyric, data.tlyric || ''))
}
// json 类型数据填充api
return ctx.json(data.map(x => {
for (let i of ['url', 'pic', 'lrc']) {
const _ = String(x[i])
// 正常对象_均为id,以下例外不用填充:1.@开头/size为0=>qq音乐jsonp 2.已存在完整链接
if (!_.startsWith('@') && !_.startsWith('http') && _.length > 0) {
x[i] = `${get_url(ctx)}?server=${server}&type=${i}&id=${_}`
}
}
return x
}))
}
|