diff --git a/src/components/Admin/RemoveMusicCache.tsx b/src/components/Admin/RemoveMusicCache.tsx index 82e29b2..1eaaf7b 100644 --- a/src/components/Admin/RemoveMusicCache.tsx +++ b/src/components/Admin/RemoveMusicCache.tsx @@ -15,7 +15,6 @@ import cleanCacheRequest from "@/server/api/admin/netease/clean"; // Interface import { MouseEvent, ChangeEvent } from "react"; - // Components function RemoveMusicCache() { const { loading, run } = useRequest( @@ -23,10 +22,7 @@ function RemoveMusicCache() { query: params }), { - manual: true, - onSuccess: (data) => { - console.log(data); - } + manual: true } ); diff --git a/src/server/api/ip.ts b/src/server/api/ip.ts new file mode 100644 index 0000000..70a5270 --- /dev/null +++ b/src/server/api/ip.ts @@ -0,0 +1,33 @@ +import { Api, Get, Query, useContext, useInject } from "@midwayjs/hooks"; +import { RedisService } from "@midwayjs/redis"; + +import fetch from "isomorphic-unfetch"; + +export default Api( + Get(), + Query<{ ip?: string }>(), + async () => { + const ctx = useContext(); + const client = await useInject(RedisService); + + // 增加使用数量 + await client.incr("api-next:stat:ip"); + + const ip = ctx.query.ip || ctx.ip.replace(/::\S+:/, ""); + + const response = await fetch(`http://ip-api.com/json/${ip}?lang=zh-CN`, { + headers: { + "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36" + } + }); + const json = await response.json(); + + delete json.status; + + return { + code: 1, + msg: "Success", + data: json + }; + } +); diff --git a/src/server/utils/netease.ts b/src/server/utils/netease.ts index 74d85a9..d086103 100644 --- a/src/server/utils/netease.ts +++ b/src/server/utils/netease.ts @@ -45,7 +45,7 @@ export const parseSongData = async (item: any) => { return { id: item.id, title: item.name, - artist: item.artists ?. [0].name || "", + artist: item.artists ? item.artists.map((artist: any) => artist.name).join(" / ") : "", alias: item.transName || (Array.isArray(item.alias) ? (item.alias[0] || "") : ""), album: item.album.name || "", cover: `${item.album.picUrl.replace("http://", "https://")}?param=250y250"`,