|
@@ -1,14 +1,25 @@
|
|
|
import axios from "axios";
|
|
import axios from "axios";
|
|
|
import { useUserStore } from "@/store/user";
|
|
import { useUserStore } from "@/store/user";
|
|
|
|
|
|
|
|
|
|
+const API_URL = import.meta.env.VITE_API_URL;
|
|
|
|
|
+const VIDEO_API_URL = import.meta.env.VITE_VIDEO_API_URL;
|
|
|
|
|
+
|
|
|
|
|
+const plat_id = import.meta.env.VITE_VIDEO_PLAT_ID;
|
|
|
|
|
+const channel_id = import.meta.env.VITE_VIDEO_CHANNEL_ID;
|
|
|
|
|
+const user_id = import.meta.env.VITE_VIDEO_USER_ID;
|
|
|
|
|
+const token = import.meta.env.VITE_VIDEO_TOKEN;
|
|
|
|
|
+
|
|
|
const api = axios.create({
|
|
const api = axios.create({
|
|
|
- baseURL: import.meta.env.VITE_API_URL,
|
|
|
|
|
- headers: {
|
|
|
|
|
- "Content-Type": "application/json",
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ baseURL: API_URL,
|
|
|
|
|
+ headers: { "Content-Type": "application/json" },
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
-// 请求拦截器
|
|
|
|
|
|
|
+const videoApi = axios.create({
|
|
|
|
|
+ baseURL: VIDEO_API_URL,
|
|
|
|
|
+ headers: { "Content-Type": "multipart/form-data" },
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
|
|
+// api请求拦截器
|
|
|
api.interceptors.request.use(
|
|
api.interceptors.request.use(
|
|
|
(config) => {
|
|
(config) => {
|
|
|
const userStore = useUserStore();
|
|
const userStore = useUserStore();
|
|
@@ -17,12 +28,10 @@ api.interceptors.request.use(
|
|
|
}
|
|
}
|
|
|
return config;
|
|
return config;
|
|
|
},
|
|
},
|
|
|
- (error) => {
|
|
|
|
|
- return Promise.reject(error);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ (error) => Promise.reject(error)
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
-// 响应拦截器
|
|
|
|
|
|
|
+// api响应拦截器
|
|
|
api.interceptors.response.use(
|
|
api.interceptors.response.use(
|
|
|
(response) => response,
|
|
(response) => response,
|
|
|
(error) => {
|
|
(error) => {
|
|
@@ -30,37 +39,77 @@ api.interceptors.response.use(
|
|
|
const userStore = useUserStore();
|
|
const userStore = useUserStore();
|
|
|
userStore.logout();
|
|
userStore.logout();
|
|
|
}
|
|
}
|
|
|
- console.error("Errorxxx:", error.response?.data || error);
|
|
|
|
|
|
|
+ console.error("API Error:", error.response?.data || error);
|
|
|
return Promise.reject(error.response?.data || error);
|
|
return Promise.reject(error.response?.data || error);
|
|
|
}
|
|
}
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
|
|
+// videoApi响应拦截器
|
|
|
|
|
+videoApi.interceptors.response.use(
|
|
|
|
|
+ (response) => response,
|
|
|
|
|
+ (error) => {
|
|
|
|
|
+ console.error("Video API Error:", error.response?.data || error);
|
|
|
|
|
+ return Promise.reject(error.response?.data || error);
|
|
|
|
|
+ }
|
|
|
|
|
+);
|
|
|
|
|
+
|
|
|
|
|
+// videoApi共用参数
|
|
|
|
|
+function createVideoFormData(
|
|
|
|
|
+ device: string,
|
|
|
|
|
+ page_count = 1,
|
|
|
|
|
+ page_size = 20,
|
|
|
|
|
+ extraParams: Record<string, string> = {}
|
|
|
|
|
+): FormData {
|
|
|
|
|
+ const formData = new FormData();
|
|
|
|
|
+ const commonParams: Record<string, string> = {
|
|
|
|
|
+ plat_id,
|
|
|
|
|
+ channel_id,
|
|
|
|
|
+ user_id,
|
|
|
|
|
+ app_type: "4",
|
|
|
|
|
+ token,
|
|
|
|
|
+ device,
|
|
|
|
|
+ device_type: "3",
|
|
|
|
|
+ page_count: String(page_count),
|
|
|
|
|
+ page_size: String(page_size),
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ Object.entries({ ...commonParams, ...extraParams }).forEach(([k, v]) =>
|
|
|
|
|
+ formData.append(k, v)
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ return formData;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// 统一视频请求
|
|
|
|
|
+async function videoRequest(
|
|
|
|
|
+ endpoint: string,
|
|
|
|
|
+ formData: FormData
|
|
|
|
|
+): Promise<any> {
|
|
|
|
|
+ const res = await videoApi.post(endpoint, formData);
|
|
|
|
|
+ return res.data;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * ===================== 用户相关接口 =====================
|
|
|
|
|
+ */
|
|
|
export const login = async (name: string, password: string): Promise<any> => {
|
|
export const login = async (name: string, password: string): Promise<any> => {
|
|
|
- const response = await api.post("/member/login", {
|
|
|
|
|
- name,
|
|
|
|
|
- password,
|
|
|
|
|
- });
|
|
|
|
|
- return response.data;
|
|
|
|
|
|
|
+ const res = await api.post("/member/login", { name, password });
|
|
|
|
|
+ return res.data;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
export const profile = async (): Promise<any> => {
|
|
export const profile = async (): Promise<any> => {
|
|
|
- const response = await api.get("/member/profile");
|
|
|
|
|
- return response.data;
|
|
|
|
|
|
|
+ const res = await api.get("/member/profile");
|
|
|
|
|
+ return res.data;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
export const resetPassword = async (password: string): Promise<any> => {
|
|
export const resetPassword = async (password: string): Promise<any> => {
|
|
|
- const response = await api.post("/users/reset-password", {
|
|
|
|
|
- password,
|
|
|
|
|
- });
|
|
|
|
|
- return response.data;
|
|
|
|
|
|
|
+ const res = await api.post("/users/reset-password", { password });
|
|
|
|
|
+ return res.data;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
export const newGuest = async (code?: string): Promise<any> => {
|
|
export const newGuest = async (code?: string): Promise<any> => {
|
|
|
- const params = { code };
|
|
|
|
|
- if (code) params.code = code;
|
|
|
|
|
-
|
|
|
|
|
- const response = await api.get("/member/guest", { params });
|
|
|
|
|
- return response.data;
|
|
|
|
|
|
|
+ const res = await api.get("/member/guest", { params: code ? { code } : {} });
|
|
|
|
|
+ return res.data;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
export const upgradeGuest = async (
|
|
export const upgradeGuest = async (
|
|
@@ -70,25 +119,97 @@ export const upgradeGuest = async (
|
|
|
email?: string,
|
|
email?: string,
|
|
|
phone?: string
|
|
phone?: string
|
|
|
): Promise<any> => {
|
|
): Promise<any> => {
|
|
|
- const response = await api.post("/member/guestUpgrade", {
|
|
|
|
|
|
|
+ const res = await api.post("/member/guestUpgrade", {
|
|
|
userId,
|
|
userId,
|
|
|
name,
|
|
name,
|
|
|
password,
|
|
password,
|
|
|
email: email || null,
|
|
email: email || null,
|
|
|
phone: phone || null,
|
|
phone: phone || null,
|
|
|
});
|
|
});
|
|
|
- return response.data;
|
|
|
|
|
|
|
+ return res.data;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
export const purchaseMember = async (
|
|
export const purchaseMember = async (
|
|
|
userId: number,
|
|
userId: number,
|
|
|
type: string
|
|
type: string
|
|
|
): Promise<any> => {
|
|
): Promise<any> => {
|
|
|
- const response = await api.post("/payment/create", {
|
|
|
|
|
- userId,
|
|
|
|
|
- type,
|
|
|
|
|
|
|
+ const res = await api.post("/payment/create", { userId, type });
|
|
|
|
|
+ return res.data;
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * ===================== 视频相关接口 =====================
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+// 视频关键字 查询接口
|
|
|
|
|
+export const searchVideoByKeyword = async (
|
|
|
|
|
+ device: string,
|
|
|
|
|
+ keyword: string,
|
|
|
|
|
+ page_count = 1,
|
|
|
|
|
+ page_size = 20,
|
|
|
|
|
+ resource_type?: "long" | "short",
|
|
|
|
|
+ lang?: string
|
|
|
|
|
+): Promise<any> => {
|
|
|
|
|
+ const formData = createVideoFormData(device, page_count, page_size, {
|
|
|
|
|
+ keyword,
|
|
|
|
|
+ ...(resource_type && { resource_type }),
|
|
|
|
|
+ ...(lang && { lang }),
|
|
|
|
|
+ });
|
|
|
|
|
+ return videoRequest(`/api/media/${plat_id}/keyword`, formData);
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+// 标签分类 查询接口
|
|
|
|
|
+export const searchVideoByTags = async (
|
|
|
|
|
+ device: string,
|
|
|
|
|
+ tag: string,
|
|
|
|
|
+ page_count = 1,
|
|
|
|
|
+ page_size = 20,
|
|
|
|
|
+ resource_type?: "long" | "short",
|
|
|
|
|
+ sort?: "view" | "like" | "time"
|
|
|
|
|
+): Promise<any> => {
|
|
|
|
|
+ const formData = createVideoFormData(device, page_count, page_size, {
|
|
|
|
|
+ tag,
|
|
|
|
|
+ ...(resource_type && { resource_type }),
|
|
|
|
|
+ ...(sort && { sort }),
|
|
|
});
|
|
});
|
|
|
- return response.data;
|
|
|
|
|
|
|
+ return videoRequest(`/api/media/${plat_id}/search`, formData);
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+// 长/短视频类型 查询接口
|
|
|
|
|
+export const searchVideoByType = async (
|
|
|
|
|
+ device: string,
|
|
|
|
|
+ resource_type: "long" | "short",
|
|
|
|
|
+ sort?: "view" | "like" | "time",
|
|
|
|
|
+ page_count = 1,
|
|
|
|
|
+ page_size = 20
|
|
|
|
|
+): Promise<any> => {
|
|
|
|
|
+ const formData = createVideoFormData(device, page_count, page_size, {
|
|
|
|
|
+ resource_type,
|
|
|
|
|
+ ...(sort && { sort }),
|
|
|
|
|
+ });
|
|
|
|
|
+ return videoRequest(`/api/media/${plat_id}/search`, formData);
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+// 视频顶部标签 查询接口
|
|
|
|
|
+export const getVideoMenu = async (
|
|
|
|
|
+ device: string,
|
|
|
|
|
+ type: "1" | "2",
|
|
|
|
|
+ page_count = 1,
|
|
|
|
|
+ page_size = 20
|
|
|
|
|
+): Promise<any> => {
|
|
|
|
|
+ const formData = createVideoFormData(device, page_count, page_size, { type });
|
|
|
|
|
+ return videoRequest(`/api/media/${plat_id}/menu`, formData);
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+// 点播集 查询接口
|
|
|
|
|
+export const getVodList = async (
|
|
|
|
|
+ device: string,
|
|
|
|
|
+ hash: string,
|
|
|
|
|
+ page_count = 1,
|
|
|
|
|
+ page_size = 20
|
|
|
|
|
+): Promise<any> => {
|
|
|
|
|
+ const formData = createVideoFormData(device, page_count, page_size, { hash });
|
|
|
|
|
+ return videoRequest(`/api/media/${plat_id}/menu/vods`, formData);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
export default api;
|
|
export default api;
|