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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -28
app.py CHANGED
@@ -1,50 +1,48 @@
1
- import gradio as gr
2
  import subprocess
3
  import os
4
  import shutil
5
 
6
- def generate_ipa(app_name, bundle_id, website_url, app_icon):
 
 
 
 
 
 
7
  try:
8
- # Create a temporary path to store the app icon file
9
- app_icon_path = os.path.join("/tmp", app_icon.name)
 
 
 
10
 
11
- # Write the uploaded file to the temp directory
12
- with open(app_icon_path, "wb") as f:
13
- shutil.copyfileobj(app_icon.file, f) # Copy content to the temp file
14
 
15
- # Now trigger the Docker container to build the IPA
16
  command = [
17
  "docker", "run", "--rm",
18
  "-v", f"{app_icon_path}:/app/icon.png", # Mount the app icon to the container
19
- "-v", f"{os.getcwd()}/output:/app/output", # Mount output directory for the IPA file
20
- "ios-ipa-builder", # The name of the Docker image
21
  app_name, bundle_id, website_url
22
  ]
23
 
24
  # Run the docker command to build the IPA
25
  result = subprocess.run(command, capture_output=True, text=True)
26
 
27
- # Check the result
28
  if result.returncode == 0:
29
- ipa_path = "/app/output/your_ipa_file.ipa" # Adjust to the actual IPA file name
30
- return f"IPA file successfully generated! You can download it here: {ipa_path}"
31
  else:
32
- return f"Error during IPA generation: {result.stderr}"
33
-
34
  except Exception as e:
35
- return f"Error: {str(e)}"
36
 
37
- # Define Gradio interface
38
- iface = gr.Interface(
39
- fn=generate_ipa,
40
- inputs=[
41
- gr.Textbox(label="App Name"),
42
- gr.Textbox(label="Bundle ID"),
43
- gr.Textbox(label="Website URL"),
44
- gr.File(label="App Icon (PNG)"),
45
- ],
46
- outputs=gr.Textbox(label="Build Status"),
47
- )
48
 
49
- iface.launch()
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