gabefromsimplebit commited on
Commit
2d59936
·
verified ·
1 Parent(s): 0ddf5d5

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +86 -13
app.py CHANGED
@@ -1,9 +1,14 @@
1
- from flask import Flask, request, send_file
2
  from flask_cors import CORS
3
- import subprocess, os, uuid
 
 
4
 
5
  app = Flask(__name__)
6
- CORS(app) # This allows your GitHub site to talk to your Hugging Face engine
 
 
 
7
  @app.route('/')
8
  def home():
9
  return "SimpleBit Engine is Online!"
@@ -13,25 +18,93 @@ def sign():
13
  job_id = str(uuid.uuid4())[:8]
14
  os.makedirs(job_id, exist_ok=True)
15
 
 
16
  ipa = request.files['ipa']
17
  p12 = request.files['p12']
18
  prov = request.files['provision']
19
  password = request.form.get('password', '1234')
20
 
21
- ipa_path = f"{job_id}/app.ipa"
 
 
 
 
22
  ipa.save(ipa_path)
23
- p12.save(f"{job_id}/cert.p12")
24
- prov.save(f"{job_id}/prov.mobileprovision")
25
 
26
- output_path = f"{job_id}/signed.ipa"
27
- cmd = f"zsign -k {job_id}/cert.p12 -p {password} -m {job_id}/prov.mobileprovision -o {output_path} {ipa_path}"
 
 
 
 
 
 
 
 
28
 
29
- result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
- if os.path.exists(output_path):
32
- return send_file(output_path, as_attachment=True)
33
- else:
34
- return f"Error signing: {result.stderr}", 500
 
 
 
 
 
 
 
 
 
 
 
35
 
36
  if __name__ == "__main__":
37
  app.run(host="0.0.0.0", port=7860)
 
1
+ from flask import Flask, request, send_file, redirect
2
  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('/')
13
  def home():
14
  return "SimpleBit Engine is Online!"
 
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:
54
+ return f"Signing failed: {str(e)}", 500
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">
64
+ <dict>
65
+ <key>items</key>
66
+ <array>
67
+ <dict>
68
+ <key>assets</key>
69
+ <array>
70
+ <dict>
71
+ <key>kind</key>
72
+ <string>software-package</string>
73
+ <key>url</key>
74
+ <string>{ipa_direct_url}</string>
75
+ </dict>
76
+ </array>
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>
84
+ <string>software</string>
85
+ <key>title</key>
86
+ <string>SimpleBit Signed App</string>
87
+ </dict>
88
+ </dict>
89
+ </array>
90
+ </dict>
91
+ </plist>"""
92
 
93
+ plist_path = os.path.join(job_id, "manifest.plist")
94
+ with open(plist_path, "w") as f:
95
+ f.write(plist_content)
96
+
97
+ return send_file(plist_path, mimetype='text/xml')
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)