webzepetoku commited on
Commit
dfac2b3
Β·
verified Β·
1 Parent(s): afeeaf0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -14
app.py CHANGED
@@ -21,9 +21,6 @@ R2_CONFIG = {
21
 
22
  app = FastAPI()
23
 
24
- # ==========================================
25
- # STRUKTUR DATABASE / REQUEST
26
- # ==========================================
27
  class ConversionRequest(BaseModel):
28
  file_url: str
29
  filename: str
@@ -38,11 +35,6 @@ def setup_license():
38
  shutil.copy2(source_ulf, os.path.join(target_dir, "Unity_lic.ulf"))
39
  print("βœ… [LICENSE] Lisensi terpasang.", flush=True)
40
 
41
- @app.post("/convert")
42
- async def api_convert(req: ConversionRequest, background_tasks: BackgroundTasks):
43
- background_tasks.add_task(process_pipeline, req)
44
- return {"status": "processing"}
45
-
46
  def process_pipeline(req: ConversionRequest):
47
  setup_license()
48
  session_id = str(uuid.uuid4())[:8]
@@ -51,7 +43,7 @@ def process_pipeline(req: ConversionRequest):
51
  zip_tmp = f"/tmp/{session_id}.zepeto"
52
 
53
  try:
54
- # 1. DOWNLOAD & EKSTRAKSI (Alur Berfungsi)
55
  print(f"πŸ“₯ [STEP 1] Downloading: {req.file_url}", flush=True)
56
  open(zip_tmp, 'wb').write(requests.get(req.file_url).content)
57
 
@@ -64,13 +56,12 @@ def process_pipeline(req: ConversionRequest):
64
  target_in = os.path.join(SESSION_PATH, "Assets/InputRaw")
65
  os.makedirs(target_in, exist_ok=True)
66
 
67
- # Pindahkan aset hasil ekstrak (Prefab, Shader, PNG)
68
  for item in os.listdir(extract_tmp):
69
  shutil.move(os.path.join(extract_tmp, item), os.path.join(target_in, item))
70
 
71
  # 3. JALANKAN UNITY (Simplify & ZEPETO Pack)
72
- print("πŸš€ [UNITY] Memulai Export dengan Login ZEPETO...", flush=True)
73
- # Menjalankan alur pemadatan mesh & builder resmi ZEPETO
74
  subprocess.run([
75
  os.environ["UNITY_PATH"],
76
  "-batchmode", "-nographics", "-quit",
@@ -79,12 +70,12 @@ def process_pipeline(req: ConversionRequest):
79
  "-id", req.z_id,
80
  "-password", req.z_pw,
81
  "-logFile", "/dev/stdout"
82
- ], capture_output=False)
83
 
84
  print("βœ… [SUCCESS] Alur ZEPETO Selesai.", flush=True)
85
 
86
  except Exception as e:
87
- print(f"πŸ”₯ [ERROR] {str(e)}", flush=True)
88
  finally:
89
  # Cleanup
90
  for p in [SESSION_PATH, extract_tmp, zip_tmp]:
@@ -92,6 +83,11 @@ def process_pipeline(req: ConversionRequest):
92
  if os.path.isdir(p): shutil.rmtree(p)
93
  else: os.remove(p)
94
 
 
 
 
 
 
95
  if __name__ == "__main__":
96
  import uvicorn
97
  uvicorn.run(app, host="0.0.0.0", port=7860)
 
21
 
22
  app = FastAPI()
23
 
 
 
 
24
  class ConversionRequest(BaseModel):
25
  file_url: str
26
  filename: str
 
35
  shutil.copy2(source_ulf, os.path.join(target_dir, "Unity_lic.ulf"))
36
  print("βœ… [LICENSE] Lisensi terpasang.", flush=True)
37
 
 
 
 
 
 
38
  def process_pipeline(req: ConversionRequest):
39
  setup_license()
40
  session_id = str(uuid.uuid4())[:8]
 
43
  zip_tmp = f"/tmp/{session_id}.zepeto"
44
 
45
  try:
46
+ # 1. DOWNLOAD & EKSTRAKSI (Alur yang Berfungsi)
47
  print(f"πŸ“₯ [STEP 1] Downloading: {req.file_url}", flush=True)
48
  open(zip_tmp, 'wb').write(requests.get(req.file_url).content)
49
 
 
56
  target_in = os.path.join(SESSION_PATH, "Assets/InputRaw")
57
  os.makedirs(target_in, exist_ok=True)
58
 
59
+ # Pindahkan aset hasil ekstrak ke InputRaw
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 UNITY (Simplify & ZEPETO Pack)
64
+ print("πŸš€ [UNITY] Memulai Proses dengan Unity 2022.3.34...", flush=True)
 
65
  subprocess.run([
66
  os.environ["UNITY_PATH"],
67
  "-batchmode", "-nographics", "-quit",
 
70
  "-id", req.z_id,
71
  "-password", req.z_pw,
72
  "-logFile", "/dev/stdout"
73
+ ], capture_output=False, check=True)
74
 
75
  print("βœ… [SUCCESS] Alur ZEPETO Selesai.", flush=True)
76
 
77
  except Exception as e:
78
+ print(f"πŸ”₯ [ERROR] Pipeline Gagal: {str(e)}", flush=True)
79
  finally:
80
  # Cleanup
81
  for p in [SESSION_PATH, extract_tmp, zip_tmp]:
 
83
  if os.path.isdir(p): shutil.rmtree(p)
84
  else: os.remove(p)
85
 
86
+ @app.post("/convert")
87
+ async def api_convert(req: ConversionRequest, background_tasks: BackgroundTasks):
88
+ background_tasks.add_task(process_pipeline, req)
89
+ return {"status": "processing"}
90
+
91
  if __name__ == "__main__":
92
  import uvicorn
93
  uvicorn.run(app, host="0.0.0.0", port=7860)