Skip to content

Commit

Permalink
添加tf autojoin
Browse files Browse the repository at this point in the history
  • Loading branch information
ldh committed Mar 12, 2024
1 parent c83d511 commit 207f2d5
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 1 deletion.
3 changes: 2 additions & 1 deletion qx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,5 @@ https://anaer.github.io/qx/rewrite/substore.conf, tag=Sub Store, update-interval
[task_local]
event-interaction https://anaer.github.io/qx/task/geo_location.js, tag=GeoIP查询, img-url=location.fill.viewfinder.system
event-interaction https://anaer.github.io/qx/task/streaming-ui-check.js, tag=流媒体解锁检测, img-url=https://anaer.github.io/qx/icon/GMedia.png, enabled=true
event-interaction https://anaer.github.io/qx/task/NodeLinkCheck.js, tag=Env代理链路检测, img-url=https://anaer.github.io/qx/icon/Stack.png, enabled=true
event-interaction https://anaer.github.io/qx/task/NodeLinkCheck.js, tag=Env代理链路检测, img-url=https://anaer.github.io/qx/icon/Stack.png, enabled=true
*/1 * * * * * https://anaer.github.io/qx/task/apple-tf-autojoin.js, tag=tf自动加入, img-url=https://raw.githubusercontent.com/Orz-3/mini/master/Color/testflight.png
4 changes: 4 additions & 0 deletions rewrite/apple.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
# TestFlight 下载修正
^https?:\/\/testflight\.apple\.com\/v\d\/accounts\/.+?\/install$ url script-request-body https://anaer.github.io/qx/rewrite/js/apple-tf-download.js

^https:\/\/testflight\.apple\.com\/v\d\/accounts/.*\/apps$ url script-request-header https://anaer.github.io/qx/rewrite/js/apple-tf-keys.js

^https://testflight.apple.com/join/(.*) url script-request-header https://anaer.github.io/qx/rewrite/js/apple-tf-keys.js

hostname = buy.itunes.apple.com, testflight.apple.com
42 changes: 42 additions & 0 deletions rewrite/js/apple-tf-keys.js
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));
}
72 changes: 72 additions & 0 deletions task/apple-tf-autojoin.js
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();
}
}
);
});
}

0 comments on commit 207f2d5

Please sign in to comment.