Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,9 @@
|
|
| 1 |
-
from fastapi import FastAPI,
|
| 2 |
from fastapi.responses import JSONResponse
|
| 3 |
from pydantic import BaseModel
|
| 4 |
import os
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# Initialize FastAPI app
|
| 7 |
app = FastAPI()
|
|
@@ -18,38 +20,66 @@ class AppInfo(BaseModel):
|
|
| 18 |
status_bar_style: str
|
| 19 |
hide_status_bar: bool
|
| 20 |
|
| 21 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
@app.post("/generate-ipa/")
|
| 23 |
async def generate_ipa(app_info: AppInfo, icon: UploadFile = File(...)):
|
| 24 |
try:
|
| 25 |
-
# Save icon
|
| 26 |
-
icon_filename = f"
|
| 27 |
-
os.makedirs(os.path.dirname(icon_filename), exist_ok=True)
|
| 28 |
with open(icon_filename, "wb") as icon_file:
|
| 29 |
icon_file.write(await icon.read())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
#
|
| 32 |
-
|
| 33 |
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
return JSONResponse(content={
|
| 36 |
-
"message": "
|
| 37 |
-
"
|
| 38 |
-
"icon": icon_filename
|
| 39 |
}, status_code=200)
|
| 40 |
|
| 41 |
except Exception as e:
|
| 42 |
-
|
| 43 |
|
| 44 |
# Root route to check if the server is running
|
| 45 |
@app.get("/")
|
| 46 |
def read_root():
|
| 47 |
return {"message": "Welcome to the Web IPA Creator Backend!"}
|
| 48 |
|
| 49 |
-
#
|
| 50 |
if __name__ == "__main__":
|
| 51 |
import uvicorn
|
| 52 |
-
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
|
|
| 53 |
|
| 54 |
|
| 55 |
|
|
|
|
| 1 |
+
from fastapi import FastAPI, UploadFile, File, HTTPException
|
| 2 |
from fastapi.responses import JSONResponse
|
| 3 |
from pydantic import BaseModel
|
| 4 |
import os
|
| 5 |
+
import subprocess
|
| 6 |
+
import shutil
|
| 7 |
|
| 8 |
# Initialize FastAPI app
|
| 9 |
app = FastAPI()
|
|
|
|
| 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 |
+
# Save icon to the system
|
| 35 |
+
icon_filename = f"{ICON_DIR}{app_info.app_name}_icon.png"
|
|
|
|
| 36 |
with open(icon_filename, "wb") as icon_file:
|
| 37 |
icon_file.write(await icon.read())
|
| 38 |
+
|
| 39 |
+
# Prepare the command to call Fastlane for IPA creation
|
| 40 |
+
# Make sure to replace 'your_lane' with the actual lane you want to run
|
| 41 |
+
fastlane_command = [
|
| 42 |
+
"fastlane", "your_lane", # Replace 'your_lane' with the lane name for building the IPA
|
| 43 |
+
"app_name=" + app_info.app_name,
|
| 44 |
+
"bundle_id=" + app_info.bundle_id,
|
| 45 |
+
"website_url=" + app_info.website_url,
|
| 46 |
+
"version=" + app_info.version,
|
| 47 |
+
"build_number=" + app_info.build_number,
|
| 48 |
+
"fullscreen=" + str(app_info.fullscreen),
|
| 49 |
+
"orientation=" + app_info.orientation,
|
| 50 |
+
"status_bar_style=" + app_info.status_bar_style,
|
| 51 |
+
"hide_status_bar=" + str(app_info.hide_status_bar),
|
| 52 |
+
"icon_path=" + icon_filename # Pass the icon path to Fastlane
|
| 53 |
+
]
|
| 54 |
|
| 55 |
+
# Run Fastlane to generate IPA
|
| 56 |
+
result = subprocess.run(fastlane_command, capture_output=True, text=True)
|
| 57 |
|
| 58 |
+
if result.returncode != 0:
|
| 59 |
+
raise HTTPException(status_code=500, detail=f"Fastlane error: {result.stderr}")
|
| 60 |
+
|
| 61 |
+
# Assuming Fastlane places the generated IPA in '/app/builds'
|
| 62 |
+
ipa_filename = f"{IPA_DIR}{app_info.app_name}.ipa"
|
| 63 |
+
|
| 64 |
+
# Return success message and the path to the generated IPA
|
| 65 |
return JSONResponse(content={
|
| 66 |
+
"message": "IPA generated successfully.",
|
| 67 |
+
"ipa_file": ipa_filename
|
|
|
|
| 68 |
}, status_code=200)
|
| 69 |
|
| 70 |
except Exception as e:
|
| 71 |
+
raise HTTPException(status_code=500, detail=f"Error occurred: {str(e)}")
|
| 72 |
|
| 73 |
# Root route to check if the server is running
|
| 74 |
@app.get("/")
|
| 75 |
def read_root():
|
| 76 |
return {"message": "Welcome to the Web IPA Creator Backend!"}
|
| 77 |
|
| 78 |
+
# Run the server directly if the script is executed
|
| 79 |
if __name__ == "__main__":
|
| 80 |
import uvicorn
|
| 81 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|
| 82 |
+
|
| 83 |
|
| 84 |
|
| 85 |
|