webzepetoku commited on
Commit
022ec02
·
verified ·
1 Parent(s): b0adfc8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -14
app.py CHANGED
@@ -9,7 +9,7 @@ os.chdir("/tmp")
9
  os.environ["HOME"] = "/tmp"
10
  os.environ["UNITY_PATH"] = "/opt/unity/Editor/Unity"
11
  os.environ["PYTHONUNBUFFERED"] = "1"
12
- # Folder ini berisi Assets, Packages, dan ProjectSettings yang Anda upload
13
  BASE_PROJECT_PATH = "/app/UnityProject"
14
 
15
  app = FastAPI()
@@ -28,7 +28,7 @@ def setup_license():
28
  target_path = os.path.join(target_dir, "Unity_lic.ulf")
29
  shutil.copy2(source_ulf, target_path)
30
  os.chmod(target_path, 0o777)
31
- print(f"✅ [LICENSE] Lisensi berhasil diaktifkan.", flush=True)
32
 
33
  @app.post("/convert")
34
  async def api_convert(req: ConversionRequest, background_tasks: BackgroundTasks):
@@ -43,23 +43,25 @@ def process_pipeline(req: ConversionRequest):
43
  extract_tmp = f"/tmp/extract_{session_id}"
44
 
45
  try:
46
- # 1. DOWNLOAD ASET BARU DARI USER
47
  resp = requests.get(req.file_url, timeout=120)
48
  with open(zip_tmp, 'wb') as f: f.write(resp.content)
49
  os.makedirs(extract_tmp, exist_ok=True)
50
  with zipfile.ZipFile(zip_tmp, 'r') as z: z.extractall(extract_tmp)
51
 
52
- # 2. COPY TEMPLATE PROJECT (Sudah Ada SDK ZEPETO)
53
- shutil.copytree(BASE_PROJECT_PATH, SESSION_PATH, ignore=shutil.ignore_patterns("Library", "Temp"))
 
 
54
 
55
- # Pindahkan aset mentah ke folder InputRaw di project session
56
  target_in = os.path.join(SESSION_PATH, "Assets/InputRaw")
57
  os.makedirs(target_in, exist_ok=True)
58
  for item in os.listdir(extract_tmp):
59
  shutil.move(os.path.join(extract_tmp, item), os.path.join(target_in, item))
60
 
61
- # 3. JALANKAN BUILD (Langsung Eksekusi)
62
- print(f"🚀 [CLI] Memulai Build Studio dari Template untuk {req.z_id}...", flush=True)
63
  subprocess.run([
64
  os.environ["UNITY_PATH"],
65
  "-batchmode", "-nographics", "-quit",
@@ -71,16 +73,15 @@ def process_pipeline(req: ConversionRequest):
71
  "-logFile", "/dev/stdout"
72
  ], capture_output=False, check=True)
73
 
74
- print(f"✅ [SUCCESS] Selesai.", flush=True)
75
 
76
  except Exception as e:
77
  print(f"🔥 [ERROR] Pipeline Gagal: {str(e)}", flush=True)
78
  finally:
79
- # Pembersihan folder sementara
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)
83
- else: os.remove(p)
84
 
85
  if __name__ == "__main__":
86
  import uvicorn
 
9
  os.environ["HOME"] = "/tmp"
10
  os.environ["UNITY_PATH"] = "/opt/unity/Editor/Unity"
11
  os.environ["PYTHONUNBUFFERED"] = "1"
12
+ # Folder ini sekarang harus berisi Assets, Packages, ProjectSettings, DAN Library
13
  BASE_PROJECT_PATH = "/app/UnityProject"
14
 
15
  app = FastAPI()
 
28
  target_path = os.path.join(target_dir, "Unity_lic.ulf")
29
  shutil.copy2(source_ulf, target_path)
30
  os.chmod(target_path, 0o777)
31
+ print(f"✅ [LICENSE] Lisensi aktif.", flush=True)
32
 
33
  @app.post("/convert")
34
  async def api_convert(req: ConversionRequest, background_tasks: BackgroundTasks):
 
43
  extract_tmp = f"/tmp/extract_{session_id}"
44
 
45
  try:
46
+ # 1. DOWNLOAD ASET BARU
47
  resp = requests.get(req.file_url, timeout=120)
48
  with open(zip_tmp, 'wb') as f: f.write(resp.content)
49
  os.makedirs(extract_tmp, exist_ok=True)
50
  with zipfile.ZipFile(zip_tmp, 'r') as z: z.extractall(extract_tmp)
51
 
52
+ # 2. COPY TEMPLATE PROJECT (TERMASUK LIBRARY UNTUK CACHE)
53
+ # Menghapus parameter ignore agar Library ikut tersalin
54
+ if os.path.exists(SESSION_PATH): shutil.rmtree(SESSION_PATH)
55
+ shutil.copytree(BASE_PROJECT_PATH, SESSION_PATH)
56
 
57
+ # Pindahkan aset baru ke 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
+ # 3. JALANKAN BUILD (Jauh lebih cepat karena Library sudah ada)
64
+ print(f"🚀 [CLI] Memulai Build Studio untuk {req.z_id}...", flush=True)
65
  subprocess.run([
66
  os.environ["UNITY_PATH"],
67
  "-batchmode", "-nographics", "-quit",
 
73
  "-logFile", "/dev/stdout"
74
  ], capture_output=False, check=True)
75
 
76
+ print(f"✅ [SUCCESS] Pipeline Selesai dengan Cache.", flush=True)
77
 
78
  except Exception as e:
79
  print(f"🔥 [ERROR] Pipeline Gagal: {str(e)}", flush=True)
80
  finally:
81
+ # Kita hapus SESSION_PATH, tapi BASE_PROJECT_PATH/Library tetap aman di /app/
82
+ if os.path.exists(SESSION_PATH): shutil.rmtree(SESSION_PATH)
83
+ if os.path.exists(extract_tmp): shutil.rmtree(extract_tmp)
84
+ if os.path.exists(zip_tmp): os.remove(zip_tmp)
 
85
 
86
  if __name__ == "__main__":
87
  import uvicorn