MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / parseFreeGames

Function parseFreeGames

epic/epic.ts:41–96  ·  view source on GitHub ↗
(data: any)

Source from the content-addressed store, hash-verified

39 const current: EpicGame[] = [];
40 const upcoming: EpicGame[] = [];
41
42 const elements = data?.data?.Catalog?.searchStore?.elements || [];
43
44 for (const game of elements) {
45 // 跳过非游戏类型
46 if (!game.categories?.some((c: any) => c.path === "freegames")) continue;
47
48 const promotions = game.promotions;
49 if (!promotions) continue;
50
51 // 获取游戏URL
52 const pageSlug = game.offerMappings?.[0]?.pageSlug || game.catalogNs?.mappings?.[0]?.pageSlug || game.productSlug || game.urlSlug;
53 const url = pageSlug ? `https://store.epicgames.com/zh-CN/p/${pageSlug}` : "";
54
55 // 获取图片
56 const imageUrl = game.keyImages?.find((img: any) => img.type === "OfferImageWide" || img.type === "Thumbnail")?.url || "";
57
58 // 获取价格
59 const price = game.price?.totalPrice;
60 const originalPrice = price?.fmtPrice?.originalPrice || "免费";
61
62 const baseInfo: Omit<EpicGame, "startDate" | "endDate"> = {
63 title: game.title || "未知游戏",
64 description: game.description || "",
65 originalPrice,
66 url,
67 imageUrl,
68 };
69
70 // 当前限免
71 const currentPromo = promotions.promotionalOffers?.[0]?.promotionalOffers?.[0];
72 if (currentPromo && price?.discountPrice === 0) {
73 current.push({
74 ...baseInfo,
75 startDate: currentPromo.startDate,
76 endDate: currentPromo.endDate,
77 });
78 continue;
79 }
80
81 // 即将限免
82 const upcomingPromo = promotions.upcomingPromotionalOffers?.[0]?.promotionalOffers?.[0];
83 if (upcomingPromo && upcomingPromo.discountSetting?.discountPercentage === 0) {
84 upcoming.push({
85 ...baseInfo,
86 startDate: upcomingPromo.startDate,
87 endDate: upcomingPromo.endDate,
88 });
89 }
90 }
91
92 return { current, upcoming };
93}
94
95// 格式化日期
96function formatDate(dateStr: string): string {
97 try {
98 const date = new Date(dateStr);

Callers 1

EpicPluginClass · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected