Spaces:
Runtime error
Runtime error
Update app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748from flask import Flask, request, jsonifyimport subprocessimport osimport shutilapp = Flask(__name__)# Ensure the output directory existsos.makedirs('./output', exist_ok=True)@app.route('/upload', methods=['POST'])def upload():try:# Get form dataapp_name = request.form['appName']bundle_id = request.form['bundleId']website_url = request.form['websiteUrl']icon_file = request.files['icon']# Save the app icon to a temporary fileapp_icon_path = os.path.join("/tmp", icon_file.filename)icon_file.save(app_icon_path)# Docker command to run the IPA buildercommand = ["docker", "run", "--rm","-v", f"{app_icon_path}:/app/icon.png", # Mount the app icon to the container"-v", f"{os.getcwd()}/output:/app/output", # Mount the output folder"ios-ipa-builder", # Docker image nameapp_name, bundle_id, website_url]# Run the docker command to build the IPAresult = subprocess.run(command, capture_output=True, text=True)if result.returncode == 0:ipa_path = "/app/output/your_ipa_file.ipa" # Change this based on your output pathreturn jsonify({"status": "success", "ipa_url": ipa_path}), 200else:return jsonify({"status": "error", "message": result.stderr}), 500except Exception as e:return jsonify({"status": "error", "message": str(e)}), 500if __name__ == "__main__":app.run(debug=True, host='0.0.0.0', port=5000)1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950from fastapi import FastAPI, Form, UploadFile, Filefrom fastapi.responses import JSONResponsefrom pydantic import BaseModelimport os# Initialize FastAPI appapp = FastAPI()# Model for incoming dataclass AppInfo(BaseModel):app_name: strbundle_id: strwebsite_url: strversion: strbuild_number: strfullscreen: boolorientation: strstatus_bar_style: strhide_status_bar: bool# Endpoint to receive app info and icon@app.post("/generate-ipa/")async def generate_ipa(app_info: AppInfo, icon: UploadFile = File(...)):try:# Save icon (just as an example)icon_filename = f"icons/{app_info.app_name}_icon.png"os.makedirs(os.path.dirname(icon_filename), exist_ok=True)with open(icon_filename, "wb") as icon_file:icon_file.write(await icon.read())# Simulate IPA creation process# You'd add the actual logic for creating the IPA here (Xcode, Fastlane, etc.)# Simulate a delay for the build processreturn JSONResponse(content={"message": "Successfully received data, simulating IPA generation.","app_info": app_info.dict(),"icon": icon_filename}, status_code=200)except Exception as e:return JSONResponse(content={"error": str(e)}, status_code=500)# Root route to check if the server is running@app.get("/")def read_root():return {"message": "Welcome to the Web IPA Creator Backend!"}
app.py+39-37