webzepetoku commited on
Commit
700ec8b
·
verified ·
1 Parent(s): 769616e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -3,14 +3,14 @@ from fastapi import FastAPI, BackgroundTasks
3
  from pydantic import BaseModel
4
 
5
  # ==========================================
6
- # PANEL CONFIG
7
  # ==========================================
8
  os.chdir("/tmp")
9
  os.environ["HOME"] = "/tmp"
10
  os.environ["UNITY_PATH"] = "/opt/unity/Editor/Unity"
11
  os.environ["PYTHONUNBUFFERED"] = "1"
12
  BASE_PROJECT_PATH = "/app/UnityProject"
13
- # Path ke file template yang Anda upload
14
  TEMPLATE_PATH = "/app/ZEPETO World Template Installer.unitypackage"
15
 
16
  app = FastAPI()
@@ -35,16 +35,17 @@ def process_pipeline(req: ConversionRequest):
35
  try:
36
  # 1. DOWNLOAD ASET USER
37
  print(f"📥 [STEP 1] Downloading user assets...", flush=True)
38
- resp = requests.get(req.file_url)
39
  with open(zip_tmp, 'wb') as f: f.write(resp.content)
40
 
41
  os.makedirs(extract_tmp, exist_ok=True)
42
  with zipfile.ZipFile(zip_tmp, 'r') as z: z.extractall(extract_tmp)
43
 
44
- # 2. SETUP PROJECT
45
  shutil.copytree(BASE_PROJECT_PATH, SESSION_PATH, ignore=shutil.ignore_patterns("Library", "Temp"))
46
 
47
  # 3. CLI: IMPORT TEMPLATE
 
48
  print(f"📦 [STEP 2] CLI: Mengimport ZEPETO Template...", flush=True)
49
  subprocess.run([
50
  os.environ["UNITY_PATH"],
@@ -53,13 +54,13 @@ def process_pipeline(req: ConversionRequest):
53
  "-importPackage", TEMPLATE_PATH
54
  ], check=True)
55
 
56
- # Pindahkan aset user ke dalam folder InputRaw proyek baru
57
  target_in = os.path.join(SESSION_PATH, "Assets/InputRaw")
58
  os.makedirs(target_in, exist_ok=True)
59
  for item in os.listdir(extract_tmp):
60
  shutil.move(os.path.join(extract_tmp, item), os.path.join(target_in, item))
61
 
62
- # 4. CLI: JALANKAN BUILD DINAMIS
63
  print(f"🚀 [STEP 3] CLI: Memulai Build untuk {req.z_id}...", flush=True)
64
  subprocess.run([
65
  os.environ["UNITY_PATH"],
@@ -77,6 +78,7 @@ def process_pipeline(req: ConversionRequest):
77
  except Exception as e:
78
  print(f"🔥 [ERROR] Pipeline CLI Gagal: {str(e)}", flush=True)
79
  finally:
 
80
  for p in [SESSION_PATH, extract_tmp, zip_tmp]:
81
  if os.path.exists(p):
82
  if os.path.isdir(p): shutil.rmtree(p)
 
3
  from pydantic import BaseModel
4
 
5
  # ==========================================
6
+ # PANEL CONFIG (JANGAN DIHAPUS)
7
  # ==========================================
8
  os.chdir("/tmp")
9
  os.environ["HOME"] = "/tmp"
10
  os.environ["UNITY_PATH"] = "/opt/unity/Editor/Unity"
11
  os.environ["PYTHONUNBUFFERED"] = "1"
12
  BASE_PROJECT_PATH = "/app/UnityProject"
13
+ # Mengarah ke file yang Anda upload sejajar dengan app.py
14
  TEMPLATE_PATH = "/app/ZEPETO World Template Installer.unitypackage"
15
 
16
  app = FastAPI()
 
35
  try:
36
  # 1. DOWNLOAD ASET USER
37
  print(f"📥 [STEP 1] Downloading user assets...", flush=True)
38
+ resp = requests.get(req.file_url, timeout=120)
39
  with open(zip_tmp, 'wb') as f: f.write(resp.content)
40
 
41
  os.makedirs(extract_tmp, exist_ok=True)
42
  with zipfile.ZipFile(zip_tmp, 'r') as z: z.extractall(extract_tmp)
43
 
44
+ # 2. SETUP PROJECT (Clean copy)
45
  shutil.copytree(BASE_PROJECT_PATH, SESSION_PATH, ignore=shutil.ignore_patterns("Library", "Temp"))
46
 
47
  # 3. CLI: IMPORT TEMPLATE
48
+ # Mengimpor struktur folder standar ZEPETO via CLI
49
  print(f"📦 [STEP 2] CLI: Mengimport ZEPETO Template...", flush=True)
50
  subprocess.run([
51
  os.environ["UNITY_PATH"],
 
54
  "-importPackage", TEMPLATE_PATH
55
  ], check=True)
56
 
57
+ # Pindahkan aset user ke dalam folder InputRaw
58
  target_in = os.path.join(SESSION_PATH, "Assets/InputRaw")
59
  os.makedirs(target_in, exist_ok=True)
60
  for item in os.listdir(extract_tmp):
61
  shutil.move(os.path.join(extract_tmp, item), os.path.join(target_in, item))
62
 
63
+ # 4. CLI: JALANKAN BUILD DINAMIS (Login & Worker count)
64
  print(f"🚀 [STEP 3] CLI: Memulai Build untuk {req.z_id}...", flush=True)
65
  subprocess.run([
66
  os.environ["UNITY_PATH"],
 
78
  except Exception as e:
79
  print(f"🔥 [ERROR] Pipeline CLI Gagal: {str(e)}", flush=True)
80
  finally:
81
+ # Cleanup
82
  for p in [SESSION_PATH, extract_tmp, zip_tmp]:
83
  if os.path.exists(p):
84
  if os.path.isdir(p): shutil.rmtree(p)