Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ from fastapi.responses import JSONResponse
|
|
| 3 |
from pydantic import BaseModel
|
| 4 |
import os
|
| 5 |
import subprocess
|
|
|
|
| 6 |
import shutil
|
| 7 |
|
| 8 |
# Initialize FastAPI app
|
|
@@ -20,53 +21,46 @@ class AppInfo(BaseModel):
|
|
| 20 |
status_bar_style: str
|
| 21 |
hide_status_bar: bool
|
| 22 |
|
| 23 |
-
# Directory for saving files
|
| 24 |
-
ICON_DIR = "/app/icons/"
|
| 25 |
-
IPA_DIR = "/app/builds/"
|
| 26 |
-
|
| 27 |
-
# Ensure the directories exist
|
| 28 |
-
os.makedirs(ICON_DIR, exist_ok=True)
|
| 29 |
-
os.makedirs(IPA_DIR, exist_ok=True)
|
| 30 |
-
|
| 31 |
@app.post("/generate-ipa/")
|
| 32 |
async def generate_ipa(app_info: AppInfo, icon: UploadFile = File(...)):
|
| 33 |
try:
|
| 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 |
except Exception as e:
|
| 71 |
raise HTTPException(status_code=500, detail=f"Error occurred: {str(e)}")
|
| 72 |
|
|
@@ -86,3 +80,4 @@ if __name__ == "__main__":
|
|
| 86 |
|
| 87 |
|
| 88 |
|
|
|
|
|
|
| 3 |
from pydantic import BaseModel
|
| 4 |
import os
|
| 5 |
import subprocess
|
| 6 |
+
import tempfile
|
| 7 |
import shutil
|
| 8 |
|
| 9 |
# Initialize FastAPI app
|
|
|
|
| 21 |
status_bar_style: str
|
| 22 |
hide_status_bar: bool
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
@app.post("/generate-ipa/")
|
| 25 |
async def generate_ipa(app_info: AppInfo, icon: UploadFile = File(...)):
|
| 26 |
try:
|
| 27 |
+
# Use a temporary directory for storing the icon and IPA files
|
| 28 |
+
with tempfile.TemporaryDirectory() as temp_dir:
|
| 29 |
+
# Save the uploaded icon to the temporary directory
|
| 30 |
+
icon_filename = os.path.join(temp_dir, f"{app_info.app_name}_icon.png")
|
| 31 |
+
with open(icon_filename, "wb") as icon_file:
|
| 32 |
+
icon_file.write(await icon.read())
|
| 33 |
+
|
| 34 |
+
# Prepare the Fastlane command to create the IPA
|
| 35 |
+
fastlane_command = [
|
| 36 |
+
"fastlane", "your_lane", # Replace 'your_lane' with your Fastlane lane
|
| 37 |
+
"app_name=" + app_info.app_name,
|
| 38 |
+
"bundle_id=" + app_info.bundle_id,
|
| 39 |
+
"website_url=" + app_info.website_url,
|
| 40 |
+
"version=" + app_info.version,
|
| 41 |
+
"build_number=" + app_info.build_number,
|
| 42 |
+
"fullscreen=" + str(app_info.fullscreen),
|
| 43 |
+
"orientation=" + app_info.orientation,
|
| 44 |
+
"status_bar_style=" + app_info.status_bar_style,
|
| 45 |
+
"hide_status_bar=" + str(app_info.hide_status_bar),
|
| 46 |
+
"icon_path=" + icon_filename # Pass the icon path to Fastlane
|
| 47 |
+
]
|
| 48 |
+
|
| 49 |
+
# Run the Fastlane command to generate the IPA
|
| 50 |
+
result = subprocess.run(fastlane_command, capture_output=True, text=True)
|
| 51 |
+
|
| 52 |
+
if result.returncode != 0:
|
| 53 |
+
raise HTTPException(status_code=500, detail=f"Fastlane error: {result.stderr}")
|
| 54 |
+
|
| 55 |
+
# Assuming Fastlane generates the IPA in the temp directory or specified builds folder
|
| 56 |
+
ipa_filename = os.path.join(temp_dir, f"{app_info.app_name}.ipa")
|
| 57 |
+
|
| 58 |
+
# Return success message and the path to the generated IPA
|
| 59 |
+
return JSONResponse(content={
|
| 60 |
+
"message": "IPA generated successfully.",
|
| 61 |
+
"ipa_file": ipa_filename
|
| 62 |
+
}, status_code=200)
|
| 63 |
+
|
| 64 |
except Exception as e:
|
| 65 |
raise HTTPException(status_code=500, detail=f"Error occurred: {str(e)}")
|
| 66 |
|
|
|
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
+
|