Skip to content

Commit

Permalink
feat: update TestFlight scripts and modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiiwoo committed Oct 19, 2024
1 parent a7c04ec commit c685760
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Modules/TestFlight.sgmodule
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!name=Automatically Join TestFlight
#!desc=Automatically Join TestFlight.
#!system=ios
#!category=🎒 TestFlight

[Script]
TestFlight=type=cron, cronexp=0 */30 * * * *,script-path=https://ruleset.tiiwoo.moe/Script/testflight.js,wake-system=0,timeout=180

[MITM]
hostname = %APPEND% testflight.apple.com
10 changes: 10 additions & 0 deletions Modules/TestFlight_get_key.sgmodule
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!name=TestFlight Get Key
#!desc=Get TestFlight Keys.
#!system=ios
#!category=🎒 TestFlight

[Script]
TestFlight_Get_Key=type=http-request,pattern=^https:\/\/testflight\.apple\.com\/v3\/accounts/.*\/apps$,requires-body=0,script-path=https://ruleset.tiiwoo.moe/Script/testflight_get_key.js

[MITM]
hostname = %APPEND% testflight.apple.com
88 changes: 88 additions & 0 deletions Script/testflight.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
!(async () => {
ids = $persistentStore.read('APP_ID');
if (ids == '') {
$notification.post(
'All TestFlights have been joined',
'Module has been automatically disabled',
''
);
$done($httpAPI('POST', '/v1/modules', { TestFlight: 'false' }));
} else {
ids = ids.split(',');
for await (const ID of ids) {
await autoPost(ID);
}
}
$done();
})();

function autoPost(ID) {
let Key = $persistentStore.read('key');
let testurl = 'https://testflight.apple.com/v3/accounts/' + Key + '/ru/';
let header = {
'X-Session-Id': `${$persistentStore.read('session_id')}`,
'X-Session-Digest': `${$persistentStore.read('session_digest')}`,
'X-Request-Id': `${$persistentStore.read('request_id')}`,
};
return new Promise(function (resolve) {
$httpClient.get(
{ url: testurl + ID, headers: header },
function (error, resp, data) {
if (error === null) {
if (resp.status == 404) {
ids = $persistentStore.read('APP_ID').split(',');
ids = ids.filter((ids) => ids !== ID);
$persistentStore.write(ids.toString(), 'APP_ID');
console.log(
ID +
' ' +
'This TestFlight does not exist, APP_ID has been automatically removed'
);
$notification.post(
ID,
'This TestFlight does not exist',
'APP_ID has been automatically removed'
);
resolve();
} else {
let jsonData = JSON.parse(data);
if (jsonData.data == null) {
console.log(ID + ' ' + jsonData.messages[0].message);
resolve();
} else if (jsonData.data.status == 'FULL') {
console.log(ID + ' ' + jsonData.data.message);
resolve();
} else {
$httpClient.post(
{ url: testurl + ID + '/accept', headers: header },
function (error, resp, body) {
let jsonBody = JSON.parse(body);
$notification.post(
jsonBody.data.name,
'TestFlight joined successfully',
''
);
console.log(
jsonBody.data.name + ' TestFlight joined successfully'
);
ids = $persistentStore.read('APP_ID').split(',');
ids = ids.filter((ids) => ids !== ID);
$persistentStore.write(ids.toString(), 'APP_ID');
resolve();
}
);
}
}
} else {
if (error == 'The request timed out.') {
resolve();
} else {
$notification.post('Automatically join TestFlight', error, '');
console.log(ID + ' ' + error);
resolve();
}
}
}
);
});
}
24 changes: 24 additions & 0 deletions Script/testflight_get_key.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
$persistentStore.write(null, 'request_id');
let url = $request.url;
let key = url.replace(/(.*accounts\/)(.*)(\/apps)/, '$2');
let session_id = $request.headers['x-session-id'];
let session_digest = $request.headers['x-session-digest'];
let request_id = $request.headers['x-request-id'];
$persistentStore.write(key, 'key');
$persistentStore.write(session_id, 'session_id');
$persistentStore.write(session_digest, 'session_digest');
$persistentStore.write(request_id, 'request_id');
if ($persistentStore.read('request_id') !== null) {
$notification.post(
'[SUCCESS] Please stop the script',
'Information retrieved successfully',
''
);
} else {
$notification.post(
'[FAIL] Information retrieval failed',
'Please enable the MITM H2 switch and add testflight.apple.com',
''
);
}
$done({});

0 comments on commit c685760

Please sign in to comment.