File size: 2,892 Bytes
b90440c
d06c28a
 
6ba901b
b90440c
d9992d2
b90440c
8ae7ccc
d06c28a
 
1161094
d06c28a
 
 
 
 
 
 
 
 
 
 
1161094
d06c28a
 
8ae7ccc
d9992d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8ae7ccc
b90440c
d06c28a
 
 
 
 
8ae7ccc
b90440c
6ba901b
 
b90440c
 
00df26b
6ba901b
 
8ae7ccc
36d7463
be1afa9
d9992d2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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)