From a76c02aa4fb091b46b33929f27d84bea37c73ceb Mon Sep 17 00:00:00 2001 From: master1lan <278457198@qq.com> Date: Sun, 9 Apr 2023 10:49:42 +0800 Subject: [PATCH] =?UTF-8?q?:technologist:=20chore(custom):=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9eu=E9=83=BD=E5=9C=A8=E6=BA=9C=E4=BB=80=E4=B9=88?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/vite.dev.config.ts | 4 +-- src/utils/fetch/index.ts | 18 +++++++------ src/utils/fetch/tool.ts | 55 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 65 insertions(+), 12 deletions(-) diff --git a/config/vite.dev.config.ts b/config/vite.dev.config.ts index a223c11..5fce769 100644 --- a/config/vite.dev.config.ts +++ b/config/vite.dev.config.ts @@ -37,8 +37,8 @@ export default defineConfig({ target: "https://api.vtb.link/eoefans-api", changeOrigin: true, }, - "/eoefans-video-rank/v1": { - target: "https://api.eoefans.com", + "/vtb-rank/v1": { + target: "https://gateway.vtb.link", changeOrigin: true, }, }, diff --git a/src/utils/fetch/index.ts b/src/utils/fetch/index.ts index c4e7ca1..ccd98bb 100644 --- a/src/utils/fetch/index.ts +++ b/src/utils/fetch/index.ts @@ -9,7 +9,11 @@ import { RFetchVideoRes, IFetchPhotoParams, } from "./fetchtype"; -import { EUWhatLookIng_Url, Host_Url } from "./tool"; +import { + EUWhatLookIng_Url, + Host_Url, + transForEUWhatLookIngResData, +} from "./tool"; import { Omit } from "../index"; import { IFetchEUWhatLookIngParmas, RFetchEUWhatLookIngRes } from "./eu6type"; /** @@ -17,7 +21,7 @@ import { IFetchEUWhatLookIngParmas, RFetchEUWhatLookIngRes } from "./eu6type"; */ export const BackEndAxios = axios.create({ baseURL: Host_Url, - timeout: 9000, + timeout: 20000, transformResponse: [ (data) => { try { @@ -30,7 +34,7 @@ export const BackEndAxios = axios.create({ }); const EUWhatLookAxios = axios.create({ baseURL: EUWhatLookIng_Url, - timeout: 10000, + timeout: 20000, transformResponse: [ (data) => { try { @@ -54,7 +58,6 @@ BackEndAxios.interceptors.request.use((config) => { }); //AbortController对象 const AbortSource: { [k: string]: AbortController | null } = {}; -// let VideoSource: AbortController | null = null; /** * video视频数据获取接口 @@ -106,7 +109,6 @@ export async function fetchVideos( }; } } -// let PhotoSource: AbortController | null = null; /** * photo图片数据获取接口 */ @@ -152,9 +154,9 @@ export async function fetchPhotos( } } -// let EUSource: AbortController | null = null; /** * eu都在溜什么的接口 + * 2023/4/9 使用适配器模式修改 */ export async function fetchEUWhatLookIng( params: IFetchEUWhatLookIngParmas @@ -164,14 +166,14 @@ export async function fetchEUWhatLookIng( } AbortSource.EUSource = new AbortController(); try { - const res = await EUWhatLookAxios.get(`/rank`, { + const res = await EUWhatLookAxios.get(`/video-rank`, { signal: AbortSource.EUSource.signal, params: { by: params, }, }); AbortSource.EUSource = null; - return res.data; + return transForEUWhatLookIngResData(res.data); } catch (err) { if (axios.isAxiosError(err)) { if (err.code === "ERR_CANCELED") { diff --git a/src/utils/fetch/tool.ts b/src/utils/fetch/tool.ts index 91c2a30..6f8bf5a 100644 --- a/src/utils/fetch/tool.ts +++ b/src/utils/fetch/tool.ts @@ -1,7 +1,58 @@ +import { Pick } from ".."; +import { RFetchEUWhatLookIngRes } from "./eu6type"; + export const Host_Url = isdev ? "/v1" : `https://api.vtb.link/eoefans-api/v1`; `https://api.eoe.best/eoefans-api/v1`; //eu都在溜什么的url export const EUWhatLookIng_Url = isdev - ? "/eoefans-video-rank/v1" - : `https://api.eoefans.com/eoefans-video-rank/v1`; + ? "/vtb-rank/v1" + : `https://gateway.vtb.link/vtb-rank/v1`; + +// 新eu都在溜什么的接口类型 +type RNewEUWhatLookIng = { + code: 0; + msg: "success"; + data: { + ctime: number; + list: { + aid: number; + bvid: string; + pic: string; + title: string; + pubdate: 1680273934; + state: 0; + duration: string; + mid: number; + name: string; + face: string; + view: number; + danmaku: number; + reply: number; + favorite: number; + coin: number; + share: number; + like: number; + total_number: string; + }[]; + }; +}; +//eu都在溜什么 接口模式修改 +export function transForEUWhatLookIngResData( + newTypeData: RNewEUWhatLookIng +): RFetchEUWhatLookIngRes { + const list = newTypeData.data.list.map((item) => ({ + ...Pick(item, "bvid", "pic", "title", "duration"), + owner: Pick(item, "name", "face", "mid"), + stat: Pick(item, "view", "danmaku", "favorite", "coin", "share", "like"), + total_number_text: item.total_number, + })); + const Res: RFetchEUWhatLookIngRes = { + code: newTypeData.code, + data: { + ctime: newTypeData.data.ctime, + list: list, + }, + }; + return Res; +}