gabefromsimplebit commited on
Commit
036f684
·
verified ·
1 Parent(s): 9c20c41

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +23 -17
app.py CHANGED
@@ -8,7 +8,7 @@ import re
8
  app = Flask(__name__)
9
  CORS(app)
10
 
11
- # Your Hugging Face Space URL
12
  BASE_URL = "https://gabefromsimplebit-simplebit-signer.hf.space"
13
 
14
  @app.route('/')
@@ -17,49 +17,54 @@ def home():
17
 
18
  @app.route('/sign', methods=['POST'])
19
  def sign():
 
20
  job_id = str(uuid.uuid4())[:8]
21
  os.makedirs(job_id, exist_ok=True)
22
 
23
- # Files from your GitHub Pages HTML form
24
  ipa = request.files['ipa']
25
  p12 = request.files['p12']
26
  prov = request.files['provision']
27
  password = request.form.get('password', '1234')
28
 
29
- # Define internal paths
30
  ipa_path = os.path.join(job_id, "app.ipa")
31
  p12_path = os.path.join(job_id, "cert.p12")
32
  prov_path = os.path.join(job_id, "prov.mobileprovision")
33
  out_path = os.path.join(job_id, "signed.ipa")
34
 
35
- # Save uploads to the MacBook-Air or Space environment
36
  ipa.save(ipa_path)
37
  p12.save(p12_path)
38
  prov.save(prov_path)
39
 
40
- # Use -z 0 for "instant" repacking on the server
 
 
41
  command = [
42
- "zsign",
43
- "-k", p12_path,
44
- "-p", password,
45
- "-m", prov_path,
46
- "-o", out_path,
47
- "-z", "0",
 
48
  ipa_path
49
  ]
50
 
51
  try:
52
- # Run zsign and capture output to find the real Bundle ID
53
  result = subprocess.run(command, capture_output=True, text=True, check=True)
54
 
55
- # Regex to find "Bundle Id: com.example.app" in the logs
56
  match = re.search(r"Bundle Id:\s+([\w\.-]+)", result.stdout)
57
  bundle_id = match.group(1) if match else "com.simplebit.dynamic"
58
 
59
- # Store the ID so the plist route can access it
60
  with open(os.path.join(job_id, "bundle_id.txt"), "w") as f:
61
  f.write(bundle_id)
62
 
 
63
  plist_url = f"{BASE_URL}/plist/{job_id}"
64
  return redirect(f"itms-services://?action=download-manifest&url={plist_url}")
65
 
@@ -68,7 +73,7 @@ def sign():
68
 
69
  @app.route('/plist/<job_id>')
70
  def serve_plist(job_id):
71
- # Retrieve the dynamic bundle ID
72
  try:
73
  with open(os.path.join(job_id, "bundle_id.txt"), "r") as f:
74
  bundle_id = f.read().strip()
@@ -77,6 +82,7 @@ def serve_plist(job_id):
77
 
78
  ipa_direct_url = f"{BASE_URL}/download/{job_id}"
79
 
 
80
  plist_content = f"""<?xml version="1.0" encoding="UTF-8"?>
81
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
82
  <plist version="1.0">
@@ -117,7 +123,7 @@ def serve_plist(job_id):
117
 
118
  @app.route('/download/<job_id>')
119
  def download_ipa(job_id):
120
- # Set mimetype to octet-stream so iOS knows it is a binary file
121
  return send_file(
122
  os.path.join(job_id, "signed.ipa"),
123
  mimetype='application/octet-stream',
@@ -125,5 +131,5 @@ def download_ipa(job_id):
125
  )
126
 
127
  if __name__ == "__main__":
128
- # Hugging Face standard port
129
  app.run(host="0.0.0.0", port=7860)
 
8
  app = Flask(__name__)
9
  CORS(app)
10
 
11
+ # Base URL for your Hugging Face Space
12
  BASE_URL = "https://gabefromsimplebit-simplebit-signer.hf.space"
13
 
14
  @app.route('/')
 
17
 
18
  @app.route('/sign', methods=['POST'])
19
  def sign():
20
+ # 1. Create a unique folder for this signing job
21
  job_id = str(uuid.uuid4())[:8]
22
  os.makedirs(job_id, exist_ok=True)
23
 
24
+ # 2. Get files from the form
25
  ipa = request.files['ipa']
26
  p12 = request.files['p12']
27
  prov = request.files['provision']
28
  password = request.form.get('password', '1234')
29
 
30
+ # 3. Define paths
31
  ipa_path = os.path.join(job_id, "app.ipa")
32
  p12_path = os.path.join(job_id, "cert.p12")
33
  prov_path = os.path.join(job_id, "prov.mobileprovision")
34
  out_path = os.path.join(job_id, "signed.ipa")
35
 
36
+ # 4. Save uploaded files
37
  ipa.save(ipa_path)
38
  p12.save(p12_path)
39
  prov.save(prov_path)
40
 
41
+ # 5. Run zsign command with optimizations
42
+ # -z 0: No compression (Fastest)
43
+ # -e: Inject entitlements (Fixes "Unable to Install")
44
  command = [
45
+ "zsign",
46
+ "-k", p12_path,
47
+ "-p", password,
48
+ "-m", prov_path,
49
+ "-o", out_path,
50
+ "-z", "0",
51
+ "-e",
52
  ipa_path
53
  ]
54
 
55
  try:
56
+ # Run zsign and capture output to extract the real Bundle ID
57
  result = subprocess.run(command, capture_output=True, text=True, check=True)
58
 
59
+ # Regex to find the real Bundle ID in zsign's logs
60
  match = re.search(r"Bundle Id:\s+([\w\.-]+)", result.stdout)
61
  bundle_id = match.group(1) if match else "com.simplebit.dynamic"
62
 
63
+ # Save the Bundle ID to a file so the /plist route can find it
64
  with open(os.path.join(job_id, "bundle_id.txt"), "w") as f:
65
  f.write(bundle_id)
66
 
67
+ # 6. Redirect to the itms-services protocol
68
  plist_url = f"{BASE_URL}/plist/{job_id}"
69
  return redirect(f"itms-services://?action=download-manifest&url={plist_url}")
70
 
 
73
 
74
  @app.route('/plist/<job_id>')
75
  def serve_plist(job_id):
76
+ # Read the dynamic bundle ID we extracted during signing
77
  try:
78
  with open(os.path.join(job_id, "bundle_id.txt"), "r") as f:
79
  bundle_id = f.read().strip()
 
82
 
83
  ipa_direct_url = f"{BASE_URL}/download/{job_id}"
84
 
85
+ # Manifest required by iOS to install apps over-the-air
86
  plist_content = f"""<?xml version="1.0" encoding="UTF-8"?>
87
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
88
  <plist version="1.0">
 
123
 
124
  @app.route('/download/<job_id>')
125
  def download_ipa(job_id):
126
+ # Direct link for iOS to grab the signed IPA
127
  return send_file(
128
  os.path.join(job_id, "signed.ipa"),
129
  mimetype='application/octet-stream',
 
131
  )
132
 
133
  if __name__ == "__main__":
134
+ # Standard port for Hugging Face Spaces
135
  app.run(host="0.0.0.0", port=7860)