sudo-soldier commited on
Commit
6ba901b
·
verified ·
1 Parent(s): bb67b0f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -19
app.py CHANGED
@@ -1,16 +1,11 @@
1
- import os
2
- import logging
3
  from fastapi import FastAPI, Form, UploadFile, File
4
  from fastapi.responses import JSONResponse
5
  from pydantic import BaseModel
 
6
 
7
  # Initialize FastAPI app
8
  app = FastAPI()
9
 
10
- # Configure logging for debugging
11
- logging.basicConfig(level=logging.INFO)
12
- logger = logging.getLogger(__name__)
13
-
14
  # Model for incoming data
15
  class AppInfo(BaseModel):
16
  app_name: str
@@ -27,24 +22,16 @@ class AppInfo(BaseModel):
27
  @app.post("/generate-ipa/")
28
  async def generate_ipa(app_info: AppInfo, icon: UploadFile = File(...)):
29
  try:
30
- # Log the incoming request data
31
- logger.info(f"Received data: {app_info.dict()}")
32
-
33
- # Save the icon to a folder (for now, simulating it)
34
  icon_filename = f"icons/{app_info.app_name}_icon.png"
35
  os.makedirs(os.path.dirname(icon_filename), exist_ok=True)
36
-
37
- # Save the uploaded file to the specified directory
38
  with open(icon_filename, "wb") as icon_file:
39
  icon_file.write(await icon.read())
40
 
41
- logger.info(f"Icon saved as {icon_filename}")
42
-
43
  # Simulate IPA creation process
44
- # Placeholder logic for actual IPA generation
45
- logger.info(f"Simulating IPA creation for app {app_info.app_name} with icon {icon_filename}")
46
 
47
- # Simulate a delay for the build process (e.g., with Fastlane or Xcode in real-world scenarios)
48
  return JSONResponse(content={
49
  "message": "Successfully received data, simulating IPA generation.",
50
  "app_info": app_info.dict(),
@@ -52,15 +39,19 @@ async def generate_ipa(app_info: AppInfo, icon: UploadFile = File(...)):
52
  }, status_code=200)
53
 
54
  except Exception as e:
55
- logger.error(f"Error in generating IPA: {str(e)}")
56
  return JSONResponse(content={"error": str(e)}, status_code=500)
57
 
58
  # Root route to check if the server is running
59
  @app.get("/")
60
  def read_root():
61
- logger.info("Root endpoint hit")
62
  return {"message": "Welcome to the Web IPA Creator Backend!"}
63
 
 
 
 
 
 
 
64
 
65
 
66
 
 
 
 
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
 
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(),
 
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
+ # Add a check to run with Uvicorn directly
50
+ if __name__ == "__main__":
51
+ import uvicorn
52
+ uvicorn.run(app, host="0.0.0.0", port=8000)
53
+
54
+
55
 
56
 
57