11import { get } from "./utils" ;
22
33// 定义表示 Steam 游戏数据的接口
4- interface PlayedGame {
4+ export interface PlayedGame {
55 appid : number ;
66 name : string ;
77 playtime_2weeks : number ;
@@ -13,12 +13,18 @@ interface PlayedGame {
1313 playtime_deck_forever : number ;
1414}
1515
16- const BASE_URL = "http://api.steampowered.com" ;
1716const { STEAM_API_KEY , STEAM_ID } = import . meta. env ;
17+ if ( ! STEAM_API_KEY ) throw Error ( "STEAM_API_KEY not configured!" ) ;
18+ if ( ! STEAM_ID ) throw Error ( "STEAM_ID not configured!" ) ;
1819
20+ const API_URL = "https://api.steampowered.com" ;
21+ const WEB_URL = "https://store.steampowered.com" ;
22+ const CDN_URL = "https://shared.fastly.steamstatic.com" ;
23+
24+ //获取我玩过的游戏列表
1925export const playedGames = async ( ) : Promise < PlayedGame [ ] > => {
2026 const path = "/IPlayerService/GetOwnedGames/v0001/" ;
21- const res = await get ( `${ BASE_URL } ${ path } ` , {
27+ const res = await get ( `${ API_URL } ${ path } ` , {
2228 key : STEAM_API_KEY ,
2329 steamid : STEAM_ID ,
2430 include_played_free_games : "true" , // 包括免费游戏
@@ -33,11 +39,30 @@ const sortPlayedGame = (games: PlayedGame[]): PlayedGame[] => {
3339 ) ;
3440} ;
3541
36- export const chineseImageUrl = ( appid : string ) => {
37- return `https://shared.fastly.steamstatic.com/store_item_assets/steam/apps/${ appid } /header_schinese.jpg` ;
42+ //获取指定应用详情
43+ export const appdetails = async ( appid : string ) => {
44+ const path = "/api/appdetails" ;
45+ const res = await get ( `${ WEB_URL } ${ path } ` , {
46+ appids : appid ,
47+ l : "schinese" ,
48+ cc : "CN" ,
49+ } ) ;
50+ return await res ?. json ( ) ;
3851} ;
3952
53+ //获取指定应用中文封面url
54+ export const chineseImageUrl = ( appid : string ) =>
55+ `${ CDN_URL } /store_item_assets/steam/apps/${ appid } /header_schinese.jpg` ;
56+
57+ //获取指定应用中文封面
4058export const chineseImage = async ( appid : string ) => {
4159 const res = await get ( chineseImageUrl ( appid ) ) ;
4260 return res ?. blob ( ) ;
4361} ;
62+ export const getGlobalAchievement = async ( appid : string ) => {
63+ const path = "ISteamUserStats/GetGlobalAchievementPercentagesForApp/v0002/" ;
64+ const res = await get ( `${ API_URL } ${ path } ` , {
65+ gameid : appid ,
66+ } ) ;
67+ return await res ?. json ( ) ;
68+ } ;
0 commit comments