Skip to content

Commit

Permalink
🧑‍💻 chore(custom): 修改eu都在溜什么的接口
Browse files Browse the repository at this point in the history
  • Loading branch information
master1lan committed Apr 9, 2023
1 parent 76011c8 commit a76c02a
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 12 deletions.
4 changes: 2 additions & 2 deletions config/vite.dev.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
Expand Down
18 changes: 10 additions & 8 deletions src/utils/fetch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ 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";
/**
* @description 大部分请求都用这个,除非是eu都在溜什么
*/
export const BackEndAxios = axios.create({
baseURL: Host_Url,
timeout: 9000,
timeout: 20000,
transformResponse: [
(data) => {
try {
Expand All @@ -30,7 +34,7 @@ export const BackEndAxios = axios.create({
});
const EUWhatLookAxios = axios.create({
baseURL: EUWhatLookIng_Url,
timeout: 10000,
timeout: 20000,
transformResponse: [
(data) => {
try {
Expand All @@ -54,7 +58,6 @@ BackEndAxios.interceptors.request.use((config) => {
});
//AbortController对象
const AbortSource: { [k: string]: AbortController | null } = {};
// let VideoSource: AbortController | null = null;

/**
* video视频数据获取接口
Expand Down Expand Up @@ -106,7 +109,6 @@ export async function fetchVideos(
};
}
}
// let PhotoSource: AbortController | null = null;
/**
* photo图片数据获取接口
*/
Expand Down Expand Up @@ -152,9 +154,9 @@ export async function fetchPhotos(
}
}

// let EUSource: AbortController | null = null;
/**
* eu都在溜什么的接口
* 2023/4/9 使用适配器模式修改
*/
export async function fetchEUWhatLookIng(
params: IFetchEUWhatLookIngParmas
Expand All @@ -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") {
Expand Down
55 changes: 53 additions & 2 deletions src/utils/fetch/tool.ts
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit a76c02a

Please sign in to comment.