-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathutils.js
105 lines (100 loc) · 3.49 KB
/
utils.js
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
const { exec } = require("child_process");
const util = require("util");
const execPromise = util.promisify(exec);
const fs = require('fs');
const path = require('path');
function makeKey(le)
{
var res = '';
var chars = `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890`;
var cl = chars.length;
for (var i = 0; i < le; i++) {
res += chars.charAt(Math.floor(Math.random() * cl));
}
return res;
}
async function execAwait(cmd) {
try {
var meow = await execPromise(cmd);
var output = meow.stdout;
var slicedoutput = output.split(' ');
var bundleid = slicedoutput.indexOf('BundleId:');
var abundleid = slicedoutput[bundleid+1].replace(/\s+/g, ' ').trim();
abundleid = abundleid.replace('>>>', '');
abundleid = abundleid.replace(' ', '');
return abundleid
}catch(err) {
if(err.stdout.toLowerCase().includes("password")) {
return true
}else{
throw new Error(err)
}
}
}
async function makePlist(bid, uuid, nya, domain)
{
const plist = `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>items</key>
<array>
<dict>
<key>assets</key>
<array>
<dict>
<key>kind</key>
<string>software-package</string>
<key>url</key>
<string>${domain}/apps/${uuid}.ipa</string>
</dict>
<dict>
<key>kind</key>
<string>display-image</string>
<key>needs-shine</key>
<false/>
<key>url</key>
<string>https://sign.apptesters.org/assets/apptesters-iconx1024.png</string>
</dict>
<dict>
<key>kind</key>
<string>full-size-image</string>
<key>needs-shine</key>
<false/>
<key>url</key>
<string>https://sign.apptesters.org/assets/apptesters-iconx1024.png</string>
</dict>
</array>
<key>metadata</key>
<dict>
<key>bundle-identifier</key>
<string>${bid ? bid : nya}</string>
<key>bundle-version</key>
<string>1.0.1</string>
<key>kind</key>
<string>software</string>
<key>title</key>
<string>${uuid}</string>
</dict>
</dict>
</array>
</dict>
</plist>`;
return plist;
}
async function deleteFiles(uuid) {
try {
await fs.unlinkSync(path.join(__dirname, 'files', 'temp', `${uuid}.ipa`));
await fs.unlinkSync(path.join(__dirname, 'files', 'certs', `${uuid}.p12`));
await fs.unlinkSync(path.join(__dirname, 'files', 'certs', `${uuid}.mobileprovision`));
} catch (e) {
console.log(e)
}
}
module.exports = {
makeKey,
execAwait,
makePlist,
deleteFiles
}