mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
fix: music proxy
This commit is contained in:
@@ -24,6 +24,14 @@ export default class WebUIManager {
|
|||||||
return data.data.Credential
|
return data.data.Credential
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async proxy<T>(url = '') {
|
||||||
|
const data = await serverRequest.get<ServerResponse<string>>(
|
||||||
|
'/base/proxy?url=' + encodeURIComponent(url)
|
||||||
|
)
|
||||||
|
data.data.data = JSON.parse(data.data.data)
|
||||||
|
return data.data as ServerResponse<T>
|
||||||
|
}
|
||||||
|
|
||||||
public static async getPackageInfo() {
|
public static async getPackageInfo() {
|
||||||
const { data } =
|
const { data } =
|
||||||
await serverRequest.get<ServerResponse<PackageInfo>>('/base/PackageInfo')
|
await serverRequest.get<ServerResponse<PackageInfo>>('/base/PackageInfo')
|
||||||
|
@@ -6,17 +6,17 @@ import type {
|
|||||||
Music163URLResponse
|
Music163URLResponse
|
||||||
} from '@/types/music'
|
} from '@/types/music'
|
||||||
|
|
||||||
import { request } from './request'
|
import WebUIManager from '@/controllers/webui_manager'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取网易云音乐歌单
|
* 获取网易云音乐歌单
|
||||||
* @param id 歌单id
|
* @param id 歌单id
|
||||||
* @returns 歌单信息
|
* @returns 歌单信息
|
||||||
*/
|
*/
|
||||||
export const get163MusicList = async (id: string) => {
|
export const get163MusicList = async (id: string) => {
|
||||||
const res = await request.get<Music163ListResponse>(
|
let res = await WebUIManager.proxy<Music163ListResponse>('https://wavesgame.top/playlist/track/all?id=' + id);
|
||||||
`https://wavesgame.top/playlist/track/all?id=${id}`
|
// const res = await request.get<Music163ListResponse>(
|
||||||
)
|
// `https://wavesgame.top/playlist/track/all?id=${id}`
|
||||||
|
// )
|
||||||
if (res?.data?.code !== 200) {
|
if (res?.data?.code !== 200) {
|
||||||
throw new Error('获取歌曲列表失败')
|
throw new Error('获取歌曲列表失败')
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ export const getSongsURL = async (ids: number[]) => {
|
|||||||
}, [] as number[][])
|
}, [] as number[][])
|
||||||
const res = await Promise.all(
|
const res = await Promise.all(
|
||||||
_ids.map(async (id) => {
|
_ids.map(async (id) => {
|
||||||
const res = await request.get<Music163URLResponse>(
|
const res = await WebUIManager.proxy<Music163URLResponse>(
|
||||||
`https://wavesgame.top/song/url?id=${id.join(',')}`
|
`https://wavesgame.top/song/url?id=${id.join(',')}`
|
||||||
)
|
)
|
||||||
if (res?.data?.code !== 200) {
|
if (res?.data?.code !== 200) {
|
||||||
|
14
src/webui/src/api/Proxy.ts
Normal file
14
src/webui/src/api/Proxy.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import { RequestHandler } from "express";
|
||||||
|
import { RequestUtil } from "@/common/request";
|
||||||
|
import { sendError, sendSuccess } from "../utils/response";
|
||||||
|
|
||||||
|
export const GetProxyHandler: RequestHandler = async (req, res) => {
|
||||||
|
let { url } = req.query;
|
||||||
|
if (url && typeof url === "string") {
|
||||||
|
url = decodeURIComponent(url);
|
||||||
|
const responseText = await RequestUtil.HttpGetText(url);
|
||||||
|
res.send(sendSuccess(res, responseText));
|
||||||
|
} else {
|
||||||
|
res.send(sendError(res, 'url参数不合法'));
|
||||||
|
}
|
||||||
|
};
|
@@ -1,11 +1,12 @@
|
|||||||
import { Router } from 'express';
|
import { Router } from 'express';
|
||||||
import { PackageInfoHandler, QQVersionHandler } from '../api/BaseInfo';
|
import { PackageInfoHandler, QQVersionHandler } from '../api/BaseInfo';
|
||||||
import { StatusRealTimeHandler } from "@webapi/api/Status";
|
import { StatusRealTimeHandler } from "@webapi/api/Status";
|
||||||
|
import { GetProxyHandler } from '../api/Proxy';
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
// router: 获取nc的package.json信息
|
// router: 获取nc的package.json信息
|
||||||
router.get('/QQVersion', QQVersionHandler);
|
router.get('/QQVersion', QQVersionHandler);
|
||||||
router.get('/PackageInfo', PackageInfoHandler);
|
router.get('/PackageInfo', PackageInfoHandler);
|
||||||
router.get('/GetSysStatusRealTime', StatusRealTimeHandler);
|
router.get('/GetSysStatusRealTime', StatusRealTimeHandler);
|
||||||
|
router.get('/proxy', GetProxyHandler);
|
||||||
export { router as BaseRouter };
|
export { router as BaseRouter };
|
||||||
|
Reference in New Issue
Block a user