sudo-soldier commited on
Commit
d06c28a
·
verified ·
1 Parent(s): 1161094

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -37
app.py CHANGED
@@ -1,48 +1,50 @@
1
- from flask import Flask, request, jsonify
2
- import subprocess
 
3
  import os
4
- import shutil
5
 
6
- app = Flask(__name__)
 
7
 
8
- # Ensure the output directory exists
9
- os.makedirs('./output', exist_ok=True)
 
 
 
 
 
 
 
 
 
10
 
11
- @app.route('/upload', methods=['POST'])
12
- def upload():
 
13
  try:
14
- # Get form data
15
- app_name = request.form['appName']
16
- bundle_id = request.form['bundleId']
17
- website_url = request.form['websiteUrl']
18
- icon_file = request.files['icon']
19
 
20
- # Save the app icon to a temporary file
21
- app_icon_path = os.path.join("/tmp", icon_file.filename)
22
- icon_file.save(app_icon_path)
23
-
24
- # Docker command to run the IPA builder
25
- command = [
26
- "docker", "run", "--rm",
27
- "-v", f"{app_icon_path}:/app/icon.png", # Mount the app icon to the container
28
- "-v", f"{os.getcwd()}/output:/app/output", # Mount the output folder
29
- "ios-ipa-builder", # Docker image name
30
- app_name, bundle_id, website_url
31
- ]
32
-
33
- # Run the docker command to build the IPA
34
- result = subprocess.run(command, capture_output=True, text=True)
35
-
36
- if result.returncode == 0:
37
- ipa_path = "/app/output/your_ipa_file.ipa" # Change this based on your output path
38
- return jsonify({"status": "success", "ipa_url": ipa_path}), 200
39
- else:
40
- return jsonify({"status": "error", "message": result.stderr}), 500
41
 
 
 
 
 
 
 
 
42
  except Exception as e:
43
- return jsonify({"status": "error", "message": str(e)}), 500
 
 
 
 
 
44
 
45
- if __name__ == "__main__":
46
- app.run(debug=True, host='0.0.0.0', port=5000)
47
 
48
 
 
1
+ from fastapi import FastAPI, Form, UploadFile, File
2
+ from fastapi.responses import JSONResponse
3
+ from pydantic import BaseModel
4
  import os
 
5
 
6
+ # Initialize FastAPI app
7
+ app = FastAPI()
8
 
9
+ # Model for incoming data
10
+ class AppInfo(BaseModel):
11
+ app_name: str
12
+ bundle_id: str
13
+ website_url: str
14
+ version: str
15
+ build_number: str
16
+ fullscreen: bool
17
+ orientation: str
18
+ status_bar_style: str
19
+ hide_status_bar: bool
20
 
21
+ # Endpoint to receive app info and icon
22
+ @app.post("/generate-ipa/")
23
+ async def generate_ipa(app_info: AppInfo, icon: UploadFile = File(...)):
24
  try:
25
+ # Save icon (just as an example)
26
+ icon_filename = f"icons/{app_info.app_name}_icon.png"
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
+ # Simulate IPA creation process
32
+ # You'd add the actual logic for creating the IPA here (Xcode, Fastlane, etc.)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
+ # Simulate a delay for the build process
35
+ return JSONResponse(content={
36
+ "message": "Successfully received data, simulating IPA generation.",
37
+ "app_info": app_info.dict(),
38
+ "icon": icon_filename
39
+ }, status_code=200)
40
+
41
  except Exception as e:
42
+ return JSONResponse(content={"error": str(e)}, status_code=500)
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