85 lines
2.2 KiB
TypeScript
85 lines
2.2 KiB
TypeScript
|
|
import type { ApiResponse } from "@/lib/api"
|
|||
|
|
import type {
|
|||
|
|
ShuidiGame,
|
|||
|
|
ShuidiPackageList,
|
|||
|
|
ShuidiRegion,
|
|||
|
|
} from "@/lib/models/shuidi"
|
|||
|
|
import { phpFetch, phpGet, phpPost } from "./http"
|
|||
|
|
|
|||
|
|
// ==================== 水滴静态/固态(jinyou) ====================
|
|||
|
|
// - 游戏列表:POST /jinyou/api/gameList(不带 cookie)
|
|||
|
|
// - 套餐列表:POST /jinyou/Jinyoujt/getPackage?type=1(1:静态 2:固态),需带 cookie
|
|||
|
|
// - 线路列表:GET /jinyou/api/regionSurplusOuts?product_id=&is_unshar=&game_id=(不带 cookie)
|
|||
|
|
|
|||
|
|
type JinyouResult<T> = {
|
|||
|
|
code: number
|
|||
|
|
msg?: string
|
|||
|
|
data?: T
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export async function fetchShuidiGameList(): Promise<
|
|||
|
|
ApiResponse<ShuidiGame[]>
|
|||
|
|
> {
|
|||
|
|
const res = await phpFetch<JinyouResult<ShuidiGame[]>>(
|
|||
|
|
"POST",
|
|||
|
|
"/jinyou/api/gameList",
|
|||
|
|
)
|
|||
|
|
if (!res.success) return res
|
|||
|
|
const data = res.data?.data
|
|||
|
|
return {
|
|||
|
|
success: true,
|
|||
|
|
data: Array.isArray(data) ? data : [],
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export async function fetchShuidiPackages(
|
|||
|
|
type: 1 | 2 = 1,
|
|||
|
|
): Promise<ApiResponse<ShuidiPackageList>> {
|
|||
|
|
const res = await phpPost<JinyouResult<ShuidiPackageList>>(
|
|||
|
|
`/jinyou/Jinyoujt/getPackage?type=${type}`,
|
|||
|
|
{ cookie: document.cookie },
|
|||
|
|
)
|
|||
|
|
if (!res.success) return res
|
|||
|
|
const data = res.data?.data
|
|||
|
|
if (!data || typeof data !== "object") {
|
|||
|
|
return { success: true, data: { game: {}, line: {} } }
|
|||
|
|
}
|
|||
|
|
return {
|
|||
|
|
success: true,
|
|||
|
|
data: {
|
|||
|
|
game: data.game ?? {},
|
|||
|
|
line: data.line ?? {},
|
|||
|
|
},
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export async function fetchShuidiRegions(params: {
|
|||
|
|
product_id: number
|
|||
|
|
is_unshar: 0 | 1
|
|||
|
|
game_id: number | ""
|
|||
|
|
}): Promise<ApiResponse<ShuidiRegion>> {
|
|||
|
|
const query = new URLSearchParams({
|
|||
|
|
product_id: String(params.product_id),
|
|||
|
|
is_unshar: String(params.is_unshar),
|
|||
|
|
game_id: String(params.game_id),
|
|||
|
|
})
|
|||
|
|
const res = await phpGet<JinyouResult<{ region?: ShuidiRegion }>>(
|
|||
|
|
`/jinyou/api/regionSurplusOuts?${query.toString()}`,
|
|||
|
|
)
|
|||
|
|
if (!res.success) return res
|
|||
|
|
const region = res.data?.data?.region
|
|||
|
|
if (!region || typeof region !== "object") {
|
|||
|
|
return {
|
|||
|
|
success: true,
|
|||
|
|
data: { province_surplus_outs: {} },
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return {
|
|||
|
|
success: true,
|
|||
|
|
data: {
|
|||
|
|
surplus_out_total: region.surplus_out_total,
|
|||
|
|
province_surplus_outs: region.province_surplus_outs ?? {},
|
|||
|
|
},
|
|||
|
|
}
|
|||
|
|
}
|