-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ldh
committed
Mar 12, 2024
1 parent
c83d511
commit 207f2d5
Showing
4 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const reg1 = /^https:\/\/testflight\.apple\.com\/v3\/accounts\/(.*)\/apps$/; | ||
const reg2 = /^https:\/\/testflight\.apple\.com\/join\/(.*)/; | ||
|
||
if (reg1.test($request.url)) { | ||
$prefs.setValueForKey(null, "request_id"); | ||
let url = $request.url; | ||
let key = url.replace(/(.*accounts\/)(.*)(\/apps)/, "$2"); | ||
const headers = Object.keys($request.headers).reduce((t, i) => ((t[i.toLowerCase()] = $request.headers[i]), t), {}); | ||
|
||
let session_id = headers["x-session-id"]; | ||
let session_digest = headers["x-session-digest"]; | ||
let request_id = headers["x-request-id"]; | ||
$prefs.setValueForKey(key, "key"); | ||
$prefs.setValueForKey(session_id, "session_id"); | ||
$prefs.setValueForKey(session_digest, "session_digest"); | ||
$prefs.setValueForKey(request_id, "request_id"); | ||
if ($prefs.valueForKey("request_id") !== null) { | ||
$notify("TestFlight自动加入", "信息获取成功", ""); | ||
} else { | ||
$notify("TestFlight自动加入", "信息获取失败", "请添加testflight.apple.com"); | ||
} | ||
$done({}); | ||
} else if (reg2.test($request.url)) { | ||
let appId = $prefs.valueForKey("APP_ID"); | ||
if (!appId) { | ||
appId = ""; | ||
} | ||
let arr = appId.split(","); | ||
const id = reg2.exec($request.url)[1]; | ||
arr.push(id); | ||
arr = unique(arr).filter((a) => a); | ||
if (arr.length > 0) { | ||
appId = arr.join(","); | ||
} | ||
$prefs.setValueForKey(appId, "APP_ID"); | ||
$notify("TestFlight自动加入", `已添加APP_ID: ${id}`, `当前ID: ${appId}`); | ||
$done({}); | ||
} | ||
|
||
function unique(arr) { | ||
return Array.from(new Set(arr)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
!(async () => { | ||
ids = $prefs.valueForKey("APP_ID"); | ||
if (ids == "") { | ||
$notify("所有TF已加入完毕", "请手动关闭", ""); | ||
$done(); | ||
} else { | ||
ids = ids.split(","); | ||
try { | ||
for await (const ID of ids) { | ||
await autoPost(ID); | ||
} | ||
} catch (error) { | ||
console.log(error); | ||
$done(); | ||
} | ||
} | ||
$done(); | ||
})(); | ||
|
||
function autoPost(ID) { | ||
let Key = $prefs.valueForKey("key"); | ||
let testurl = "https://testflight.apple.com/v3/accounts/" + Key + "/ru/"; | ||
let header = { | ||
"X-Session-Id": `${$prefs.valueForKey("session_id")}`, | ||
"X-Session-Digest": `${$prefs.valueForKey("session_digest")}`, | ||
"X-Request-Id": `${$prefs.valueForKey("request_id")}`, | ||
}; | ||
return new Promise(function (resolve) { | ||
$task.fetch({ url: testurl + ID, method: "GET", headers: header }).then( | ||
(resp) => { | ||
const { body: data } = resp; | ||
if (resp.status == 404) { | ||
ids = $prefs.valueForKey("APP_ID").split(","); | ||
ids = ids.filter((ids) => ids !== ID); | ||
$prefs.setValueForKey(ids.toString(), "APP_ID"); | ||
console.log(ID + " " + "不存在该TF,已自动删除该APP_ID"); | ||
$notify(ID, "不存在该TF", "已自动删除该APP_ID"); | ||
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 { | ||
$task.fetch({ url: testurl + ID + "/accept", method: "POST", headers: header }).then((res) => { | ||
const { body } = res; | ||
let jsonBody = JSON.parse(body); | ||
$notify(jsonBody.data.name, "TestFlight加入成功", ""); | ||
console.log(jsonBody.data.name + " TestFlight加入成功"); | ||
ids = $prefs.valueForKey("APP_ID").split(","); | ||
ids = ids.filter((ids) => ids !== ID); | ||
$prefs.setValueForKey(ids.toString(), "APP_ID"); | ||
resolve(); | ||
}); | ||
} | ||
} | ||
}, | ||
(error) => { | ||
if (error == "The request timed out.") { | ||
resolve(); | ||
} else { | ||
$notify("自动加入TF", error, ""); | ||
console.log(ID + " " + error); | ||
resolve(); | ||
} | ||
} | ||
); | ||
}); | ||
} |