Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,7 +22,7 @@ class ConversionRequest(BaseModel):
|
|
| 22 |
filename: str
|
| 23 |
|
| 24 |
def make_structured_zepeto(source_dir, output_file):
|
| 25 |
-
"""Zipping sesuai struktur repository 'sesudah' (
|
| 26 |
allowed_binaries = ["Android", "iOS", "WebGL", "StandaloneWindows64", "StandaloneOSX", "StandaloneLinux64"]
|
| 27 |
with zipfile.ZipFile(output_file, 'w', zipfile.ZIP_DEFLATED) as z:
|
| 28 |
for root, _, files in os.walk(source_dir):
|
|
@@ -57,30 +57,30 @@ def process_pipeline(req: ConversionRequest):
|
|
| 57 |
final_zepeto = f"/tmp/{req.filename}.zepeto"
|
| 58 |
|
| 59 |
try:
|
| 60 |
-
# Download &
|
| 61 |
open(zip_tmp, 'wb').write(requests.get(req.file_url).content)
|
| 62 |
os.makedirs(extract_tmp, exist_ok=True)
|
| 63 |
with zipfile.ZipFile(zip_tmp, 'r') as z: z.extractall(extract_tmp)
|
| 64 |
-
shutil.copytree(BASE_PROJECT_PATH, SESSION_PATH, ignore=shutil.ignore_patterns("Library", "Temp"))
|
| 65 |
|
|
|
|
|
|
|
| 66 |
target_in = os.path.join(SESSION_PATH, "Assets/InputRaw")
|
| 67 |
os.makedirs(target_in, exist_ok=True)
|
| 68 |
for item in os.listdir(extract_tmp): shutil.move(os.path.join(extract_tmp, item), os.path.join(target_in, item))
|
| 69 |
|
| 70 |
-
# Unity Build
|
| 71 |
print("🚀 [UNITY] Memulai Export...", flush=True)
|
| 72 |
subprocess.run([os.environ["UNITY_PATH"], "-batchmode", "-nographics", "-quit", "-projectPath", SESSION_PATH, "-executeMethod", "TestBuilder.ManualConvert", "-logFile", "/dev/stdout"], capture_output=False)
|
| 73 |
|
| 74 |
-
#
|
| 75 |
export_dir = os.path.join(SESSION_PATH, "Assets/FinalPackage")
|
| 76 |
-
# PROTEKSI: Jangan zip jika folder kosong (mencegah file 22 byte)
|
| 77 |
if os.path.exists(export_dir) and len(os.listdir(export_dir)) > 0:
|
| 78 |
make_structured_zepeto(export_dir, final_zepeto)
|
| 79 |
s3 = boto3.client('s3', endpoint_url=f"https://{R2_CONFIG['account_id']}.r2.cloudflarestorage.com", aws_access_key_id=R2_CONFIG['access_key'], aws_secret_access_key=R2_CONFIG['secret_key'])
|
| 80 |
s3.upload_file(final_zepeto, R2_CONFIG['bucket_name'], f"packed/{req.filename}.zepeto")
|
| 81 |
-
print("✅ [SUCCESS] File dikirim.", flush=True)
|
| 82 |
else:
|
| 83 |
-
print("❌ [ERROR] Unity tidak menghasilkan file apa pun
|
| 84 |
|
| 85 |
finally:
|
| 86 |
for p in [SESSION_PATH, extract_tmp, zip_tmp, final_zepeto]:
|
|
|
|
| 22 |
filename: str
|
| 23 |
|
| 24 |
def make_structured_zepeto(source_dir, output_file):
|
| 25 |
+
"""Zipping sesuai struktur repository 'sesudah' (Hanya Binary Platform)"""
|
| 26 |
allowed_binaries = ["Android", "iOS", "WebGL", "StandaloneWindows64", "StandaloneOSX", "StandaloneLinux64"]
|
| 27 |
with zipfile.ZipFile(output_file, 'w', zipfile.ZIP_DEFLATED) as z:
|
| 28 |
for root, _, files in os.walk(source_dir):
|
|
|
|
| 57 |
final_zepeto = f"/tmp/{req.filename}.zepeto"
|
| 58 |
|
| 59 |
try:
|
| 60 |
+
# 1. Download & Extract
|
| 61 |
open(zip_tmp, 'wb').write(requests.get(req.file_url).content)
|
| 62 |
os.makedirs(extract_tmp, exist_ok=True)
|
| 63 |
with zipfile.ZipFile(zip_tmp, 'r') as z: z.extractall(extract_tmp)
|
|
|
|
| 64 |
|
| 65 |
+
# 2. Setup Project
|
| 66 |
+
shutil.copytree(BASE_PROJECT_PATH, SESSION_PATH, ignore=shutil.ignore_patterns("Library", "Temp"))
|
| 67 |
target_in = os.path.join(SESSION_PATH, "Assets/InputRaw")
|
| 68 |
os.makedirs(target_in, exist_ok=True)
|
| 69 |
for item in os.listdir(extract_tmp): shutil.move(os.path.join(extract_tmp, item), os.path.join(target_in, item))
|
| 70 |
|
| 71 |
+
# 3. Unity Build (C# akan otomatis skip modul yang tidak ada)
|
| 72 |
print("🚀 [UNITY] Memulai Export...", flush=True)
|
| 73 |
subprocess.run([os.environ["UNITY_PATH"], "-batchmode", "-nographics", "-quit", "-projectPath", SESSION_PATH, "-executeMethod", "TestBuilder.ManualConvert", "-logFile", "/dev/stdout"], capture_output=False)
|
| 74 |
|
| 75 |
+
# 4. Cek hasil: Minimal harus ada Prefab atau satu binary
|
| 76 |
export_dir = os.path.join(SESSION_PATH, "Assets/FinalPackage")
|
|
|
|
| 77 |
if os.path.exists(export_dir) and len(os.listdir(export_dir)) > 0:
|
| 78 |
make_structured_zepeto(export_dir, final_zepeto)
|
| 79 |
s3 = boto3.client('s3', endpoint_url=f"https://{R2_CONFIG['account_id']}.r2.cloudflarestorage.com", aws_access_key_id=R2_CONFIG['access_key'], aws_secret_access_key=R2_CONFIG['secret_key'])
|
| 80 |
s3.upload_file(final_zepeto, R2_CONFIG['bucket_name'], f"packed/{req.filename}.zepeto")
|
| 81 |
+
print("✅ [SUCCESS] File dikirim ke R2.", flush=True)
|
| 82 |
else:
|
| 83 |
+
print("❌ [ERROR] Unity tidak menghasilkan file apa pun sama sekali.", flush=True)
|
| 84 |
|
| 85 |
finally:
|
| 86 |
for p in [SESSION_PATH, extract_tmp, zip_tmp, final_zepeto]:
|