Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,9 +3,12 @@ import os, re, time, json, datetime, requests, gradio as gr
|
|
3 |
# โโโโโโโโโโโโโโโโโโโโโ 1. Vercel API โโโโโโโโโโโโโโโโโโโโโ
|
4 |
TOKEN = os.getenv("SVR_TOKEN")
|
5 |
TEAM = os.getenv("VERCEL_TEAM_ID")
|
|
|
6 |
|
7 |
-
# ํ ID
|
8 |
-
if not TEAM:
|
|
|
|
|
9 |
# ์ค์ ํ ID๋ก ๊ต์ฒดํ์ธ์
|
10 |
TEAM = "team_YOUR_ACTUAL_TEAM_ID_HERE"
|
11 |
print(f"ํ๊ฒฝ ๋ณ์์ ํ ID๊ฐ ์์ด์ ํ๋์ฝ๋ฉ๋ ๊ฐ์ ์ฌ์ฉํฉ๋๋ค: {TEAM}")
|
@@ -16,7 +19,7 @@ if not TOKEN:
|
|
16 |
API = "https://api.vercel.com"
|
17 |
HEAD = {"Authorization": f"Bearer {TOKEN}"}
|
18 |
|
19 |
-
print(f"์ฌ์ฉ ์ค์ธ ํ ID
|
20 |
|
21 |
# โโโโโโโโโโโโโโโโโโโโโ 2. BEST ๋ฐ์ดํฐ โโโโโโโโโโโโโโโโโโโโ
|
22 |
BEST_FILE, PER_PAGE = "best_games.json", 48
|
@@ -47,14 +50,22 @@ def fetch_all(limit=200):
|
|
47 |
print("์ค๋ฅ: API ํ ํฐ์ด ์ค์ ๋์ง ์์์ต๋๋ค")
|
48 |
return []
|
49 |
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
-
# ํ ID ์ฒ๋ฆฌ
|
53 |
if TEAM:
|
54 |
params["teamId"] = TEAM
|
55 |
print(f"ํ ID๋ก ์์ฒญํฉ๋๋ค: {TEAM}")
|
|
|
|
|
|
|
56 |
else:
|
57 |
-
print("๊ฒฝ๊ณ : ํ
|
58 |
|
59 |
print(f"Vercel API ํธ์ถ: {API}/v6/deployments (params={params})")
|
60 |
|
@@ -64,7 +75,10 @@ def fetch_all(limit=200):
|
|
64 |
# ์์ธํ ์๋ต ์ ๋ณด ์ถ๋ ฅ
|
65 |
print(f"API ์๋ต ์ํ ์ฝ๋: {resp.status_code}")
|
66 |
if resp.status_code != 200:
|
67 |
-
|
|
|
|
|
|
|
68 |
return []
|
69 |
|
70 |
data = resp.json()
|
@@ -80,12 +94,15 @@ def fetch_all(limit=200):
|
|
80 |
first = data["deployments"][0]
|
81 |
print(f"\n์ฒซ ๋ฒ์งธ ๋ฐฐํฌ URL: {first.get('url')}")
|
82 |
print(f"์ฒซ ๋ฒ์งธ ๋ฐฐํฌ Alias: {first.get('alias', [])}\n")
|
|
|
83 |
|
84 |
# ํจํด ์ํ: vercel.app์ผ๋ก ๋๋๋ ๋ชจ๋ URL ํ์ฉ
|
85 |
domain_pat = re.compile(r"\.vercel\.app$", re.I)
|
86 |
|
87 |
games = []
|
88 |
for d in data.get("deployments", []):
|
|
|
|
|
89 |
if d.get("state") != "READY":
|
90 |
continue
|
91 |
|
@@ -103,10 +120,26 @@ def fetch_all(limit=200):
|
|
103 |
break
|
104 |
|
105 |
if matched_url:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
games.append({
|
107 |
"title": d.get("name", "(์ ๋ชฉ ์์)"),
|
108 |
"url": f"https://{matched_url}",
|
109 |
-
"ts":
|
|
|
|
|
|
|
|
|
|
|
110 |
})
|
111 |
|
112 |
print(f"vercel.app ๋๋ฉ์ธ ๋ฐฐํฌ {len(games)}๊ฐ๋ฅผ ํํฐ๋งํ์ต๋๋ค")
|
@@ -168,7 +201,7 @@ def html(cards, pg, total):
|
|
168 |
errorDiv.className = 'frame-error';
|
169 |
errorDiv.innerHTML = '<div class="frame-error-icon">๐</div>' +
|
170 |
'<div><strong>์ ๊ทผ์ด ์ ํ๋ ๋ฐฐํฌ์
๋๋ค</strong></div>' +
|
171 |
-
'<div
|
172 |
'<button class="frame-error-btn" onclick="window.open(\'' + url + '\', \'_blank\')">์ ํญ์์ ์ด๊ธฐ</button>';
|
173 |
container.appendChild(errorDiv);
|
174 |
}
|
@@ -176,11 +209,13 @@ def html(cards, pg, total):
|
|
176 |
// iframe ๋ก๋ ์ฑ๊ณต ์ฒ๋ฆฌ
|
177 |
function handleIframeLoad(iframe) {
|
178 |
try {
|
179 |
-
// CORS ์ค๋ฅ ํ์ง ์๋
|
180 |
-
iframe.contentWindow.location.href
|
181 |
-
|
|
|
182 |
} catch (e) {
|
183 |
// CORS ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ฉด handleIframeError ํธ์ถ
|
|
|
184 |
handleIframeError(iframe);
|
185 |
}
|
186 |
}
|
@@ -192,17 +227,20 @@ def html(cards, pg, total):
|
|
192 |
frames.forEach(frame => {
|
193 |
// ์ค๋ฅ ์ด๋ฒคํธ ๋ฆฌ์ค๋
|
194 |
frame.addEventListener('error', function() {
|
|
|
195 |
handleIframeError(this);
|
196 |
});
|
197 |
|
198 |
// ๋ก๋ ์ด๋ฒคํธ ๋ฆฌ์ค๋
|
199 |
frame.addEventListener('load', function() {
|
|
|
200 |
handleIframeLoad(this);
|
201 |
});
|
202 |
|
203 |
// 5์ด ํ์๋ ๋ก๋๋์ง ์์ผ๋ฉด ์ค๋ฅ๋ก ๊ฐ์ฃผ
|
204 |
setTimeout(function() {
|
205 |
if(frame.style.opacity !== '1') {
|
|
|
206 |
handleIframeError(frame);
|
207 |
}
|
208 |
}, 5000);
|
@@ -218,7 +256,8 @@ def html(cards, pg, total):
|
|
218 |
<div class='hdr'><p class='ttl'>{c['title']}</p><p class='date'>{date}</p></div>
|
219 |
<div class='frame'>
|
220 |
<iframe src="{c['url']}" loading="lazy"
|
221 |
-
|
|
|
222 |
allow="accelerometer; camera; encrypted-media; gyroscope;"></iframe>
|
223 |
</div>
|
224 |
<div class='foot'><a class='link' href="{c['url']}" target="_blank">์๋ณธโ</a></div>
|
|
|
3 |
# โโโโโโโโโโโโโโโโโโโโโ 1. Vercel API โโโโโโโโโโโโโโโโโโโโโ
|
4 |
TOKEN = os.getenv("SVR_TOKEN")
|
5 |
TEAM = os.getenv("VERCEL_TEAM_ID")
|
6 |
+
TEAM_SLUG = os.getenv("VERCEL_TEAM_SLUG") # ํ ์ฌ๋ฌ๊ทธ๋ ์ถ๊ฐ
|
7 |
|
8 |
+
# ํ ID ๋๋ ์ฌ๋ฌ๊ทธ ํ์ธ
|
9 |
+
if not TEAM and TEAM_SLUG:
|
10 |
+
print(f"ํ ID ๋์ ํ ์ฌ๋ฌ๊ทธ๋ฅผ ์ฌ์ฉํฉ๋๋ค: {TEAM_SLUG}")
|
11 |
+
elif not TEAM:
|
12 |
# ์ค์ ํ ID๋ก ๊ต์ฒดํ์ธ์
|
13 |
TEAM = "team_YOUR_ACTUAL_TEAM_ID_HERE"
|
14 |
print(f"ํ๊ฒฝ ๋ณ์์ ํ ID๊ฐ ์์ด์ ํ๋์ฝ๋ฉ๋ ๊ฐ์ ์ฌ์ฉํฉ๋๋ค: {TEAM}")
|
|
|
19 |
API = "https://api.vercel.com"
|
20 |
HEAD = {"Authorization": f"Bearer {TOKEN}"}
|
21 |
|
22 |
+
print(f"์ฌ์ฉ ์ค์ธ ํ ์ ๋ณด: ID={TEAM if TEAM else '์์'}, Slug={TEAM_SLUG if TEAM_SLUG else '์์'}")
|
23 |
|
24 |
# โโโโโโโโโโโโโโโโโโโโโ 2. BEST ๋ฐ์ดํฐ โโโโโโโโโโโโโโโโโโโโ
|
25 |
BEST_FILE, PER_PAGE = "best_games.json", 48
|
|
|
50 |
print("์ค๋ฅ: API ํ ํฐ์ด ์ค์ ๋์ง ์์์ต๋๋ค")
|
51 |
return []
|
52 |
|
53 |
+
# API ๋ฌธ์ ๊ธฐ๋ฐ์ผ๋ก ํ๋ผ๋ฏธํฐ ์ค์
|
54 |
+
params = {
|
55 |
+
"limit": limit,
|
56 |
+
# ์ํ๊ฐ "READY"์ธ ๋ฐฐํฌ๋ง ๊ฐ์ ธ์ค๊ธฐ ์ํ ํํฐ๋ง
|
57 |
+
"state": "READY"
|
58 |
+
}
|
59 |
|
60 |
+
# ํ ID ๋๋ ์ฌ๋ฌ๊ทธ ์ฒ๋ฆฌ
|
61 |
if TEAM:
|
62 |
params["teamId"] = TEAM
|
63 |
print(f"ํ ID๋ก ์์ฒญํฉ๋๋ค: {TEAM}")
|
64 |
+
elif TEAM_SLUG:
|
65 |
+
params["slug"] = TEAM_SLUG
|
66 |
+
print(f"ํ ์ฌ๋ฌ๊ทธ๋ก ์์ฒญํฉ๋๋ค: {TEAM_SLUG}")
|
67 |
else:
|
68 |
+
print("๊ฒฝ๊ณ : ํ ์ ๋ณด๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค. ๊ฐ์ธ ํ๋ก์ ํธ๋ง ์กฐํ๋ฉ๋๋ค.")
|
69 |
|
70 |
print(f"Vercel API ํธ์ถ: {API}/v6/deployments (params={params})")
|
71 |
|
|
|
75 |
# ์์ธํ ์๋ต ์ ๋ณด ์ถ๋ ฅ
|
76 |
print(f"API ์๋ต ์ํ ์ฝ๋: {resp.status_code}")
|
77 |
if resp.status_code != 200:
|
78 |
+
error_msg = f"API ์๋ต ์ค๋ฅ: {resp.status_code}"
|
79 |
+
if hasattr(resp, 'text'):
|
80 |
+
error_msg += f", {resp.text[:200]}"
|
81 |
+
print(error_msg)
|
82 |
return []
|
83 |
|
84 |
data = resp.json()
|
|
|
94 |
first = data["deployments"][0]
|
95 |
print(f"\n์ฒซ ๋ฒ์งธ ๋ฐฐํฌ URL: {first.get('url')}")
|
96 |
print(f"์ฒซ ๋ฒ์งธ ๋ฐฐํฌ Alias: {first.get('alias', [])}\n")
|
97 |
+
print(f"์ฒซ ๋ฒ์งธ ๋ฐฐํฌ ์ํ: {first.get('state')}\n")
|
98 |
|
99 |
# ํจํด ์ํ: vercel.app์ผ๋ก ๋๋๋ ๋ชจ๋ URL ํ์ฉ
|
100 |
domain_pat = re.compile(r"\.vercel\.app$", re.I)
|
101 |
|
102 |
games = []
|
103 |
for d in data.get("deployments", []):
|
104 |
+
# ๋ฌธ์์์๋ state ํํฐ๋ง์ URL ํ๋ผ๋ฏธํฐ๋ก ํ์ง๋ง,
|
105 |
+
# ์ถ๊ฐ ๊ฒ์ฆ์ ์ํด ์ฌ๊ธฐ์๋ ํ์ธํฉ๋๋ค
|
106 |
if d.get("state") != "READY":
|
107 |
continue
|
108 |
|
|
|
120 |
break
|
121 |
|
122 |
if matched_url:
|
123 |
+
# ์๊ฐ ํ์ ๋ณํ ๊ฐ์
|
124 |
+
created_time = d.get("created")
|
125 |
+
if created_time:
|
126 |
+
# milliseconds to seconds ๋ณํ
|
127 |
+
try:
|
128 |
+
ts = int(created_time / 1000)
|
129 |
+
except:
|
130 |
+
ts = int(time.time())
|
131 |
+
else:
|
132 |
+
ts = int(time.time())
|
133 |
+
|
134 |
games.append({
|
135 |
"title": d.get("name", "(์ ๋ชฉ ์์)"),
|
136 |
"url": f"https://{matched_url}",
|
137 |
+
"ts": ts,
|
138 |
+
"meta": { # ์ถ๊ฐ ๋ฉํ๋ฐ์ดํฐ ์ ์ฅ
|
139 |
+
"projectId": d.get("projectId"),
|
140 |
+
"target": d.get("target"),
|
141 |
+
"deploymentId": d.get("uid")
|
142 |
+
}
|
143 |
})
|
144 |
|
145 |
print(f"vercel.app ๋๋ฉ์ธ ๋ฐฐํฌ {len(games)}๊ฐ๋ฅผ ํํฐ๋งํ์ต๋๋ค")
|
|
|
201 |
errorDiv.className = 'frame-error';
|
202 |
errorDiv.innerHTML = '<div class="frame-error-icon">๐</div>' +
|
203 |
'<div><strong>์ ๊ทผ์ด ์ ํ๋ ๋ฐฐํฌ์
๋๋ค</strong></div>' +
|
204 |
+
'<div>๋ณด์ ์ค์ ์ผ๋ก ์ธํด iframe์์ ํ์ํ ์ ์์ต๋๋ค</div>' +
|
205 |
'<button class="frame-error-btn" onclick="window.open(\'' + url + '\', \'_blank\')">์ ํญ์์ ์ด๊ธฐ</button>';
|
206 |
container.appendChild(errorDiv);
|
207 |
}
|
|
|
209 |
// iframe ๋ก๋ ์ฑ๊ณต ์ฒ๋ฆฌ
|
210 |
function handleIframeLoad(iframe) {
|
211 |
try {
|
212 |
+
// CORS ์ค๋ฅ ํ์ง ์๋ - ๋ค๋ฅธ ๋๋ฉ์ธ์ iframe ์ ๊ทผ ์ ์์ธ ๋ฐ์
|
213 |
+
if(iframe.contentWindow.location.href) {
|
214 |
+
iframe.style.opacity = 1;
|
215 |
+
}
|
216 |
} catch (e) {
|
217 |
// CORS ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ฉด handleIframeError ํธ์ถ
|
218 |
+
console.log("CORS ์ค๋ฅ ๋๋ ์ ๊ทผ ๊ฑฐ๋ถ๋จ:", e);
|
219 |
handleIframeError(iframe);
|
220 |
}
|
221 |
}
|
|
|
227 |
frames.forEach(frame => {
|
228 |
// ์ค๋ฅ ์ด๋ฒคํธ ๋ฆฌ์ค๋
|
229 |
frame.addEventListener('error', function() {
|
230 |
+
console.log("iframe ๋ก๋ ์ค๋ฅ ๋ฐ์");
|
231 |
handleIframeError(this);
|
232 |
});
|
233 |
|
234 |
// ๋ก๋ ์ด๋ฒคํธ ๋ฆฌ์ค๋
|
235 |
frame.addEventListener('load', function() {
|
236 |
+
console.log("iframe ๋ก๋๋จ:", this.src);
|
237 |
handleIframeLoad(this);
|
238 |
});
|
239 |
|
240 |
// 5์ด ํ์๋ ๋ก๋๋์ง ์์ผ๋ฉด ์ค๋ฅ๋ก ๊ฐ์ฃผ
|
241 |
setTimeout(function() {
|
242 |
if(frame.style.opacity !== '1') {
|
243 |
+
console.log("iframe ๋ก๋ ํ์์์:", frame.src);
|
244 |
handleIframeError(frame);
|
245 |
}
|
246 |
}, 5000);
|
|
|
256 |
<div class='hdr'><p class='ttl'>{c['title']}</p><p class='date'>{date}</p></div>
|
257 |
<div class='frame'>
|
258 |
<iframe src="{c['url']}" loading="lazy"
|
259 |
+
referrerpolicy="no-referrer"
|
260 |
+
sandbox="allow-scripts allow-same-origin allow-forms"
|
261 |
allow="accelerometer; camera; encrypted-media; gyroscope;"></iframe>
|
262 |
</div>
|
263 |
<div class='foot'><a class='link' href="{c['url']}" target="_blank">์๋ณธโ</a></div>
|