sudo-soldier commited on
Commit
d9992d2
·
verified ·
1 Parent(s): de50a4d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -44
app.py CHANGED
@@ -3,6 +3,7 @@ from fastapi.responses import JSONResponse
3
  from pydantic import BaseModel
4
  import os
5
  import subprocess
 
6
  import shutil
7
 
8
  # Initialize FastAPI app
@@ -20,53 +21,46 @@ class AppInfo(BaseModel):
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
 
@@ -86,3 +80,4 @@ if __name__ == "__main__":
86
 
87
 
88
 
 
 
3
  from pydantic import BaseModel
4
  import os
5
  import subprocess
6
+ import tempfile
7
  import shutil
8
 
9
  # Initialize FastAPI app
 
21
  status_bar_style: str
22
  hide_status_bar: bool
23
 
 
 
 
 
 
 
 
 
24
  @app.post("/generate-ipa/")
25
  async def generate_ipa(app_info: AppInfo, icon: UploadFile = File(...)):
26
  try:
27
+ # Use a temporary directory for storing the icon and IPA files
28
+ with tempfile.TemporaryDirectory() as temp_dir:
29
+ # Save the uploaded icon to the temporary directory
30
+ icon_filename = os.path.join(temp_dir, f"{app_info.app_name}_icon.png")
31
+ with open(icon_filename, "wb") as icon_file:
32
+ icon_file.write(await icon.read())
33
+
34
+ # Prepare the Fastlane command to create the IPA
35
+ fastlane_command = [
36
+ "fastlane", "your_lane", # Replace 'your_lane' with your Fastlane lane
37
+ "app_name=" + app_info.app_name,
38
+ "bundle_id=" + app_info.bundle_id,
39
+ "website_url=" + app_info.website_url,
40
+ "version=" + app_info.version,
41
+ "build_number=" + app_info.build_number,
42
+ "fullscreen=" + str(app_info.fullscreen),
43
+ "orientation=" + app_info.orientation,
44
+ "status_bar_style=" + app_info.status_bar_style,
45
+ "hide_status_bar=" + str(app_info.hide_status_bar),
46
+ "icon_path=" + icon_filename # Pass the icon path to Fastlane
47
+ ]
48
+
49
+ # Run the Fastlane command to generate the IPA
50
+ result = subprocess.run(fastlane_command, capture_output=True, text=True)
51
+
52
+ if result.returncode != 0:
53
+ raise HTTPException(status_code=500, detail=f"Fastlane error: {result.stderr}")
54
+
55
+ # Assuming Fastlane generates the IPA in the temp directory or specified builds folder
56
+ ipa_filename = os.path.join(temp_dir, f"{app_info.app_name}.ipa")
57
+
58
+ # Return success message and the path to the generated IPA
59
+ return JSONResponse(content={
60
+ "message": "IPA generated successfully.",
61
+ "ipa_file": ipa_filename
62
+ }, status_code=200)
63
+
64
  except Exception as e:
65
  raise HTTPException(status_code=500, detail=f"Error occurred: {str(e)}")
66
 
 
80
 
81
 
82
 
83
+