from fastapi import FastAPI, UploadFile, File, HTTPException from fastapi.responses import JSONResponse from pydantic import BaseModel import os import subprocess import tempfile import shutil # Initialize FastAPI app app = FastAPI() # Model for incoming data class AppInfo(BaseModel): app_name: str bundle_id: str website_url: str version: str build_number: str fullscreen: bool orientation: str status_bar_style: str hide_status_bar: bool @app.post("/generate-ipa/") async def generate_ipa(app_info: AppInfo, icon: UploadFile = File(...)): try: # Use a temporary directory for storing the icon and IPA files with tempfile.TemporaryDirectory() as temp_dir: # Save the uploaded icon to the temporary directory icon_filename = os.path.join(temp_dir, f"{app_info.app_name}_icon.png") with open(icon_filename, "wb") as icon_file: icon_file.write(await icon.read()) # Prepare the Fastlane command to create the IPA fastlane_command = [ "fastlane", "your_lane", # Replace 'your_lane' with your Fastlane lane "app_name=" + app_info.app_name, "bundle_id=" + app_info.bundle_id, "website_url=" + app_info.website_url, "version=" + app_info.version, "build_number=" + app_info.build_number, "fullscreen=" + str(app_info.fullscreen), "orientation=" + app_info.orientation, "status_bar_style=" + app_info.status_bar_style, "hide_status_bar=" + str(app_info.hide_status_bar), "icon_path=" + icon_filename # Pass the icon path to Fastlane ] # Run the Fastlane command to generate the IPA result = subprocess.run(fastlane_command, capture_output=True, text=True) if result.returncode != 0: raise HTTPException(status_code=500, detail=f"Fastlane error: {result.stderr}") # Assuming Fastlane generates the IPA in the temp directory or specified builds folder ipa_filename = os.path.join(temp_dir, f"{app_info.app_name}.ipa") # Return success message and the path to the generated IPA return JSONResponse(content={ "message": "IPA generated successfully.", "ipa_file": ipa_filename }, status_code=200) except Exception as e: raise HTTPException(status_code=500, detail=f"Error occurred: {str(e)}") # Root route to check if the server is running @app.get("/") def read_root(): return {"message": "Welcome to the Web IPA Creator Backend!"} # Run the server directly if the script is executed if __name__ == "__main__": import uvicorn uvicorn.run(app, host="0.0.0.0", port=8000)