gabefromsimplebit commited on
Commit
9c20c41
·
verified ·
1 Parent(s): 2d59936

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +34 -15
app.py CHANGED
@@ -3,10 +3,12 @@ from flask_cors import CORS
3
  import subprocess
4
  import os
5
  import uuid
 
6
 
7
  app = Flask(__name__)
8
  CORS(app)
9
 
 
10
  BASE_URL = "https://gabefromsimplebit-simplebit-signer.hf.space"
11
 
12
  @app.route('/')
@@ -18,36 +20,47 @@ def sign():
18
  job_id = str(uuid.uuid4())[:8]
19
  os.makedirs(job_id, exist_ok=True)
20
 
21
- # Input names from your HTML
22
  ipa = request.files['ipa']
23
  p12 = request.files['p12']
24
  prov = request.files['provision']
25
  password = request.form.get('password', '1234')
26
 
 
27
  ipa_path = os.path.join(job_id, "app.ipa")
28
  p12_path = os.path.join(job_id, "cert.p12")
29
  prov_path = os.path.join(job_id, "prov.mobileprovision")
30
  out_path = os.path.join(job_id, "signed.ipa")
31
 
 
32
  ipa.save(ipa_path)
33
  p12.save(p12_path)
34
  prov.save(prov_path)
35
 
36
- # Optimization: -z 0 for instant repacking
37
  command = [
38
- "zsign",
39
- "-k", p12_path,
40
- "-p", password,
41
- "-m", prov_path,
42
- "-o", out_path,
43
  "-z", "0",
44
  ipa_path
45
  ]
46
 
47
  try:
48
- subprocess.run(command, check=True)
 
 
 
 
 
 
 
 
 
 
49
  plist_url = f"{BASE_URL}/plist/{job_id}"
50
- # This triggers the iOS 'Install' popup
51
  return redirect(f"itms-services://?action=download-manifest&url={plist_url}")
52
 
53
  except Exception as e:
@@ -55,9 +68,15 @@ def sign():
55
 
56
  @app.route('/plist/<job_id>')
57
  def serve_plist(job_id):
 
 
 
 
 
 
 
58
  ipa_direct_url = f"{BASE_URL}/download/{job_id}"
59
 
60
- # Manifest required by iOS to install apps over the air
61
  plist_content = f"""<?xml version="1.0" encoding="UTF-8"?>
62
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
63
  <plist version="1.0">
@@ -77,7 +96,7 @@ def serve_plist(job_id):
77
  <key>metadata</key>
78
  <dict>
79
  <key>bundle-identifier</key>
80
- <string>com.simplebit.signed</string>
81
  <key>bundle-version</key>
82
  <string>1.0</string>
83
  <key>kind</key>
@@ -98,13 +117,13 @@ def serve_plist(job_id):
98
 
99
  @app.route('/download/<job_id>')
100
  def download_ipa(job_id):
101
- # iOS needs the correct MIME type to treat this as an app
102
  return send_file(
103
- f"{job_id}/signed.ipa",
104
  mimetype='application/octet-stream',
105
- as_attachment=True,
106
- download_name="signed.ipa"
107
  )
108
 
109
  if __name__ == "__main__":
 
110
  app.run(host="0.0.0.0", port=7860)
 
3
  import subprocess
4
  import os
5
  import uuid
6
+ import re
7
 
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('/')
 
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
 
66
  except Exception as e:
 
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()
75
+ except:
76
+ bundle_id = "com.simplebit.fallback"
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">
 
96
  <key>metadata</key>
97
  <dict>
98
  <key>bundle-identifier</key>
99
+ <string>{bundle_id}</string>
100
  <key>bundle-version</key>
101
  <string>1.0</string>
102
  <key>kind</key>
 
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',
124
+ as_attachment=True
 
125
  )
126
 
127
  if __name__ == "__main__":
128
+ # Hugging Face standard port
129
  app.run(host="0.0.0.0", port=7860)