File size: 3,433 Bytes
216bae4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
def fetch_all(limit=50):
    """
    Vercel API v10/projects๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ”„๋กœ์ ํŠธ ๋ชฉ๋ก์„ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.
    """
    try:
        # API ํŒŒ๋ผ๋ฏธํ„ฐ ์„ค์ •
        params = {"limit": limit}
        if TEAM:
            params["teamId"] = TEAM

        print(f"Vercel API ํ˜ธ์ถœ (ํ”„๋กœ์ ํŠธ): {API}/v10/projects (params={params})")
        
        resp = requests.get(f"{API}/v10/projects",
                            headers=HEAD, params=params, timeout=30)
        
        print(f"API ์‘๋‹ต ์ƒํƒœ ์ฝ”๋“œ: {resp.status_code}")
        if resp.status_code != 200:
            print(f"API ์‘๋‹ต ์˜ค๋ฅ˜: {resp.status_code}, {resp.text[:200] if hasattr(resp, 'text') else ''}")
            return []
            
        data = resp.json()
        
        if "projects" not in data:
            print(f"API ์‘๋‹ต์— projects ํ•„๋“œ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค: {str(data)[:200]}...")
            return []
            
        projects = data.get("projects", [])
        print(f"{len(projects)}๊ฐœ์˜ ํ”„๋กœ์ ํŠธ๋ฅผ ์ฐพ์•˜์Šต๋‹ˆ๋‹ค")
        
        # ๊ฐ ํ”„๋กœ์ ํŠธ์˜ ์ตœ์‹  ๋ฐฐํฌ ์ •๋ณด ๊ฐ€์ ธ์˜ค๊ธฐ
        games = []
        for project in projects:
            project_id = project.get("id")
            project_name = project.get("name", "(์ œ๋ชฉ ์—†์Œ)")
            
            # ํ”„๋กœ์ ํŠธ๋ณ„ ์ตœ์‹  ๋ฐฐํฌ ๊ฐ€์ ธ์˜ค๊ธฐ (projectId ํ•„ํ„ฐ ์ถ”๊ฐ€)
            try:
                deploy_params = {
                    "limit": 1,
                    "projectId": project_id,  # ์ค‘์š”: ํ•ด๋‹น ํ”„๋กœ์ ํŠธ์˜ ๋ฐฐํฌ๋งŒ ํ•„ํ„ฐ๋ง
                    "state": "READY"
                }
                
                if TEAM:
                    deploy_params["teamId"] = TEAM
                
                print(f"ํ”„๋กœ์ ํŠธ {project_id} ({project_name}) ๋ฐฐํฌ ์กฐํšŒ ์ค‘...")
                
                deploy_resp = requests.get(
                    f"{API}/v6/deployments",
                    headers=HEAD,
                    params=deploy_params,
                    timeout=30
                )
                
                if deploy_resp.status_code == 200:
                    deploy_data = deploy_resp.json()
                    deployments = deploy_data.get("deployments", [])
                    
                    if deployments:
                        deployment = deployments[0]
                        url = deployment.get("url", "")
                        if url:
                            games.append({
                                "title": project_name,
                                "url": f"https://{url}",
                                "ts": int(deployment.get("created", time.time() * 1000) / 1000),
                                "projectId": project_id
                            })
                            print(f"ํ”„๋กœ์ ํŠธ {project_name}์˜ ๋ฐฐํฌ URL: https://{url}")
                    else:
                        print(f"ํ”„๋กœ์ ํŠธ {project_name}์— ๋ฐฐํฌ๋œ ๋ฒ„์ „์ด ์—†์Šต๋‹ˆ๋‹ค.")
            except Exception as e:
                print(f"ํ”„๋กœ์ ํŠธ {project_id}์˜ ๋ฐฐํฌ ์ •๋ณด ๊ฐ€์ ธ์˜ค๊ธฐ ์‹คํŒจ: {e}")
                continue

        print(f"์ด {len(games)}๊ฐœ์˜ ์œ ํšจํ•œ ๋ฐฐํฌ๋ฅผ ์ฐพ์•˜์Šต๋‹ˆ๋‹ค")
        return sorted(games, key=lambda x: x["ts"], reverse=True)

    except Exception as e:
        print(f"Vercel API ์˜ค๋ฅ˜: {str(e)}")
        import traceback
        traceback.print_exc()
        return []