File size: 6,827 Bytes
fa0ae19
10c3f69
2e9406d
10c3f69
 
 
2e9406d
fa0ae19
2e9406d
 
fa0ae19
10c3f69
 
2e9406d
fa0ae19
 
2e9406d
4bfda21
10c3f69
 
 
 
 
3573333
4bfda21
 
10c3f69
f1821c8
10c3f69
 
2e9406d
8d5e73b
 
 
 
4bfda21
fa0ae19
f1821c8
 
 
8d5e73b
 
 
fa0ae19
f1821c8
8d5e73b
3573333
4bfda21
f1821c8
8d5e73b
 
 
 
 
 
 
f1821c8
 
2e9406d
8d5e73b
 
fa0ae19
f1821c8
 
 
4bfda21
3573333
4bfda21
 
f1821c8
10c3f69
2e9406d
10c3f69
 
fa0ae19
3573333
10c3f69
2e9406d
fa0ae19
2e9406d
10c3f69
4bfda21
2e9406d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10c3f69
 
fa0ae19
10c3f69
 
fa0ae19
2e9406d
 
 
 
 
10c3f69
2e9406d
 
10c3f69
2e9406d
 
fa0ae19
2e9406d
3573333
2e9406d
 
 
 
 
 
10c3f69
 
 
 
 
 
 
 
 
fa0ae19
2e9406d
10c3f69
2e9406d
10c3f69
2e9406d
10c3f69
 
 
 
 
 
4bfda21
10c3f69
4bfda21
 
2e9406d
3573333
4bfda21
3573333
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153

import os, re, time, json, datetime, requests, gradio as gr

# โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ 1. Vercel API โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
TOKEN = os.getenv("SVR_TOKEN")
TEAM  = os.getenv("VERCEL_TEAM_ID")
if not TOKEN:
    raise EnvironmentError("SVR_TOKEN ํ™˜๊ฒฝ๋ณ€์ˆ˜๋ฅผ ์„ค์ •ํ•˜์„ธ์š”.")
API   = "https://api.vercel.com"
HEAD  = {"Authorization": f"Bearer {TOKEN}"}

# โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ 2. BEST ๋ฐ์ดํ„ฐ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
BEST_FILE, PER_PAGE = "best_games.json", 48
def _init_best():
    if not os.path.exists(BEST_FILE):
        json.dump([], open(BEST_FILE, "w"))
def _load_best():
    try:
        data = json.load(open(BEST_FILE))
        for it in data:
            if "ts" not in it:
                it["ts"] = int(it.get("timestamp", time.time()))
        return data
    except Exception:
        return []

# โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ 3. NEW: 6๊ธ€์ž vercel.app ๋ฐฐํฌ โ”€โ”€โ”€โ”€โ”€
# 3. NEW: 6๊ธ€์ž vercel.app ๋ฐฐํฌ
PAT = re.compile(r"^[a-z0-9]{6}\.vercel\.app$", re.I)

def fetch_all(limit=200):
    """
    READY ๋ฐฐํฌ ์ค‘ 'tmkdop.vercel.app' ์ฒ˜๋Ÿผ 6๊ธ€์ž ๋„๋ฉ”์ธ์ด ๋‹ฌ๋ฆฐ ๊ฒƒ๋งŒ ์ˆ˜์ง‘
    ยท url ํ•„๋“œ์™€ alias ๋ฐฐ์—ด์„ ๋ชจ๋‘ ๊ฒ€์ƒ‰
    """
    try:
        params = {"limit": limit}
        if TEAM:
            params["teamId"] = TEAM

        resp = requests.get(f"{API}/v6/deployments",
                            headers=HEAD, params=params, timeout=30)
        resp.raise_for_status()

        games = []
        for d in resp.json().get("deployments", []):
            if d.get("state") != "READY":
                continue

            # โ”€โ”€ url + alias ๋ฐฐ์—ด ํ†ตํ•ฉ ๊ฒ€์‚ฌ
            candidates = [d.get("url", "")]
            candidates.extend(d.get("alias", []))

            six = next((dom for dom in candidates if PAT.match(dom)), None)
            if not six:
                continue

            games.append({
                "title": d.get("name", "(์ œ๋ชฉ ์—†์Œ)"),
                "url": f"https://{six}",
                "ts": int(d.get("created", time.time() * 1000) / 1000)
            })

        return sorted(games, key=lambda x: x["ts"], reverse=True)

    except Exception as e:
        print("Vercel API ์˜ค๋ฅ˜:", e)
        return []


# โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ 4. ํŽ˜์ด์ง€๋„ค์ด์…˜ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
def page(lst, pg):
    s=(pg-1)*PER_PAGE; e=s+PER_PAGE
    total=(len(lst)+PER_PAGE-1)//PER_PAGE
    return lst[s:e], total

# โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ 5. HTML 3-์—ด ๊ทธ๋ฆฌ๋“œ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
def html(cards, pg, total):
    if not cards:
        return "<div style='text-align:center;padding:70px;color:#555;'>ํ‘œ์‹œํ•  ๋ฐฐํฌ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.</div>"
    css=r"""
    <style>
    body{margin:0;font-family:Poppins,sans-serif;background:linear-gradient(135deg,#C5E8FF 0%,#FFD6E0 100%);}
    .grid{display:grid;grid-template-columns:repeat(3,1fr);gap:28px 24px;margin:0 20px 60px;}
    @media(max-width:1024px){.grid{grid-template-columns:repeat(2,1fr);} }
    @media(max-width:640px){ .grid{grid-template-columns:1fr;} }
    .card{background:#fff;border-radius:18px;overflow:hidden;box-shadow:0 10px 25px rgba(0,0,0,.08);transition:.3s}
    .card:hover{transform:translateY(-6px);box-shadow:0 16px 40px rgba(0,0,0,.12)}
    .hdr{padding:20px 24px;background:rgba(255,255,255,.75);backdrop-filter:blur(8px);border-bottom:1px solid #eee;}
    .ttl{margin:0;font-size:1.15rem;font-weight:700;color:#333;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
    .date{margin-top:4px;font-size:.85rem;color:#777;}
    .frame{position:relative;width:100%;padding-top:60%;overflow:hidden;}
    .frame iframe{position:absolute;top:0;left:0;width:142.857%;height:142.857%;
                  transform:scale(.7);transform-origin:top left;border:0;}
    .foot{padding:14px 24px;background:rgba(255,255,255,.85);backdrop-filter:blur(8px);text-align:right;}
    .link{font-size:.85rem;font-weight:600;color:#4a6dd8;text-decoration:none;}
    .cnt{text-align:center;font-size:.85rem;color:#555;margin:10px 0 40px;}
    </style>"""
    h=css+"<div class='grid'>"
    for c in cards:
        date=datetime.datetime.fromtimestamp(int(c["ts"])).strftime("%Y-%m-%d")
        h+=f"""
        <div class='card'>
          <div class='hdr'><p class='ttl'>{c['title']}</p><p class='date'>{date}</p></div>
          <div class='frame'><iframe src="{c['url']}" loading="lazy"
               allow="accelerometer; camera; encrypted-media; gyroscope;"></iframe></div>
          <div class='foot'><a class='link' href="{c['url']}" target="_blank">์›๋ณธโ†—</a></div>
        </div>"""
    h+="</div><p class='cnt'>Page "+str(pg)+" / "+str(total)+"</p>"
    return h

# โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ 6. Gradio Blocks UI โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
def build():
    _init_best()
    with gr.Blocks(title="Vibe Game Craft", css="body{overflow-x:hidden;}") as demo:
        gr.Markdown("<h1 style='text-align:center;padding:32px 0 0;color:#333;'>๐ŸŽฎ Vibe Game Craft</h1>")
        with gr.Row():
            b_new  = gr.Button("NEW",  size="sm")
            b_best = gr.Button("BEST", size="sm")
            b_prev = gr.Button("โฌ…๏ธ Prev", size="sm")
            b_next = gr.Button("Next โžก๏ธ", size="sm")
            b_ref  = gr.Button("๐Ÿ”„ Reload", size="sm")

        tab = gr.State("new"); np = gr.State(1); bp = gr.State(1); out = gr.HTML()

        def show_new(p=1):  d,t=page(fetch_all(),p);  return html(d,p,t),"new",p
        def show_best(p=1): d,t=page(_load_best(),p); return html(d,p,t),"best",p

        def prev(t,n,b):
            if t=="new": n=max(1,n-1); h,_,_=show_new(n);  return h,n,b
            b=max(1,b-1); h,_,_=show_best(b); return h,n,b
        def nxt(t,n,b):
            if t=="new":
                maxp=(len(fetch_all())+PER_PAGE-1)//PER_PAGE
                n=min(maxp,n+1); h,_,_=show_new(n); return h,n,b
            maxp=(len(_load_best())+PER_PAGE-1)//PER_PAGE
            b=min(maxp,b+1); h,_,_=show_best(b); return h,n,b

        b_new.click(show_new,  outputs=[out,tab,np])
        b_best.click(show_best,outputs=[out,tab,bp])
        b_prev.click(prev,     inputs=[tab,np,bp], outputs=[out,np,bp])
        b_next.click(nxt,      inputs=[tab,np,bp], outputs=[out,np,bp])
        b_ref.click(lambda t,n,b: show_new(n)[0] if t=="new" else show_best(b)[0],
                     inputs=[tab,np,bp], outputs=[out])

        demo.load(show_new, outputs=[out,tab,np])
    return demo

app = build()

if __name__ == "__main__":
    app.launch()