wubianSynthesis.js 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  1. /*
  2. 无边星链合成兑换
  3. */
  4. const scriptName = `无边星链合成兑换`;
  5. const magicJS = MagicJS(scriptName, "INFO");
  6. const WuBianConstKey = {
  7. // 基础数据
  8. Token: 'WubianProToken',
  9. ActivityListData: 'WubianActivityListData',
  10. ActivityGoodsList: 'WubianActivityGoodsList',
  11. ActivityTaskCaptureEnabled: 'WubianActivityTaskCaptureEnabled',
  12. ActivityTagName: 'WubianActivityActivityTagName',
  13. ActivityIndexName: 'WubianActivityIndexName',
  14. ActivityId: 'WubianActivityId',
  15. SynthesisConcurrentMode: 'WubianSynthesisConcurrentMode',
  16. SynthesisRunsPerSecond: 'WubianSynthesisRunsPerSecond',
  17. SynthesisAmount: 'WubianSynthesisTargetAmount',
  18. SynthesisCompositeGoodsListReqTime: 'WubianSynthesisCompositeGoodsListReqTime',
  19. SynthesisConvertGoodsListReqTime: 'WubianSynthesisConvertGoodsListReqTime',
  20. SynthesisActivityDisabled: 'WubianSynthesisActivityDisabled',
  21. SynthesisAllowAdvanceTime: 'WubianSynthesisAllowAdvanceTime',
  22. SynthesisUseCacheEnabled: 'WubianSynthesisUseCacheEnabled',
  23. };
  24. const gUserAgent = `Mozilla/5.0 (iPhone; CPU iPhone OS 16_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 Html5Plus/1.0 (Immersed/20) uni-app`;
  25. const gHost = `api.wubian.pro`;
  26. let gToken = magicJS.data.read(WuBianConstKey.Token, '');
  27. const gCommonHeaders = {
  28. 'Accept': `*/*`,
  29. 'Accept-Encoding': `gzip, deflate, br`,
  30. 'Connection': `keep-alive`,
  31. 'Content-Type': `application/json`,
  32. 'Cookie': `token=${gToken}`,
  33. 'Host': gHost,
  34. 'User-Agent': gUserAgent,
  35. 'CLIENT-TYPE': `APP`,
  36. 'token': gToken,
  37. 'Accept-Language': `zh-CN,zh-Hans;q=0.9`
  38. };
  39. let gRetBody;
  40. let gSynthesizeResultList = [];
  41. let gSynthesizeResultDict = {};
  42. async function Main() {
  43. if (magicJS.isStrictRequest) {
  44. magicJS.checkRecordRequestBody();
  45. }
  46. if (magicJS.isRequest) {
  47. checkHandleRequest();
  48. } else {
  49. updateHeaders();
  50. await trySynthesize();
  51. }
  52. magicJS.notification.msg('');
  53. if (gRetBody) {
  54. magicJS.done({
  55. body: JSON.stringify(gRetBody)
  56. });
  57. } else {
  58. magicJS.done();
  59. }
  60. }
  61. function checkHandleRequest() {
  62. }
  63. function handleHeaders() {
  64. if ($request && $request.method != 'OPTIONS') {
  65. let headers = $request.headers;
  66. let newToken = headers['token'];
  67. let oldToken = magicJS.data.read(WuBianConstKey.Token, null);
  68. if (newToken) {
  69. if (newToken != oldToken) {
  70. magicJS.logger.info(`当前Token刷新到最新`);
  71. magicJS.notification.appendNotifyInfo(`🎉当前Token刷新到最新`);
  72. } else {
  73. magicJS.logger.info(`当前Token已经是最新无需更新`);
  74. }
  75. magicJS.data.write(WuBianConstKey.Token, newToken);
  76. } else {
  77. let newCookieStr = headers['Cookie'];
  78. if (newCookieStr) {
  79. let cookieDict = magicJS.parseCookies(newCookieStr);
  80. if (cookieDict['token'] != void 0) {
  81. newToken = ookieDict['token'];
  82. magicJS.data.write(WuBianConstKey.Token, newToken);
  83. magicJS.logger.info(`当前Token刷新到最新`);
  84. }
  85. }
  86. }
  87. }
  88. }
  89. function updateHeaders() {
  90. gToken = magicJS.data.read(WuBianConstKey.Token, '');
  91. gCommonHeaders['token'] = gToken;
  92. gCommonHeaders['cookie'] = `token=${gToken}`;
  93. }
  94. function getResponsePlainData() {
  95. let data = magicJS.getResponseBody();
  96. if (!data) {
  97. return;
  98. }
  99. try {
  100. return JSON.parse(data);
  101. } catch (err) {
  102. magicJS.logger.error(err);
  103. }
  104. }
  105. function getRequestPlainData() {
  106. let data = magicJS.getRequestBody();
  107. let reqData = null;
  108. if (data) {
  109. reqData = JSON.parse(data);
  110. } else {
  111. reqData = magicJS.parseQueryStr($request.url);
  112. }
  113. return reqData;
  114. }
  115. function getQueryPlainData() {
  116. let params = magicJS.parseQueryStr($request.url);
  117. return params;
  118. }
  119. function compareCookieStr(cookieStr1, cookieStr2) {
  120. let cookieDict1 = magicJS.parseCookies(cookieStr1);
  121. let cookieDict2 = magicJS.parseCookies(cookieStr2);
  122. let skipKeys = [];
  123. let retCode = 0;
  124. for (let key in cookieDict1) {
  125. if (!skipKeys.includes(key)) {
  126. if (cookieDict1[key] != void 0 && cookieDict2[key] != void 0 && cookieDict1[key] != cookieDict2[key]) {
  127. magicJS.logger.info(`${key}`);
  128. retCode = -1;
  129. break;
  130. }
  131. }
  132. }
  133. return retCode;
  134. }
  135. function appendCookieStr(newCookieStr) {
  136. let cookieStr = magicJS.data.read(WuBianConstKey.Cookie, null);
  137. let cookieDict = magicJS.parseCookies(cookieStr);
  138. let newCookieDict = magicJS.parseCookies(newCookieStr);
  139. for (let key in newCookieDict) {
  140. cookieDict[key] = newCookieDict[key];
  141. }
  142. cookieStr = magicJS.serializeCookies(cookieDict);
  143. magicJS.data.write(WuBianConstKey.Cookie, cookieStr);
  144. }
  145. function handleUserCollectList() {
  146. let rspData = getResponsePlainData();
  147. if (!rspData) {
  148. return;
  149. }
  150. if (rspData.code != 200) {
  151. return;
  152. }
  153. handleHeaders();
  154. }
  155. function handleInitData() {
  156. let rspData = getResponsePlainData();
  157. if (!rspData) {
  158. return;
  159. }
  160. if (rspData.code != 200) {
  161. return;
  162. }
  163. handleHeaders();
  164. }
  165. function getWillActivityTagName() {
  166. let tagName = magicJS.data.read(WuBianConstKey.ActivityTagName, '');
  167. return tagName;
  168. }
  169. function getWillActivityIndexName() {
  170. let indexName = magicJS.data.read(WuBianConstKey.ActivityIndexName, '');
  171. return indexName;
  172. }
  173. function getWillActivityId() {
  174. let activityId = magicJS.data.read(WuBianConstKey.ActivityId, '');
  175. return activityId;
  176. }
  177. function getActivityWillCount() {
  178. return 99999;
  179. }
  180. function isConcurrentMode() {
  181. let flag = magicJS.data.read(WuBianConstKey.SynthesisConcurrentMode, true);
  182. return flag;
  183. }
  184. function getRunsPreSecond() {
  185. let runs = magicJS.data.read(WuBianConstKey.SynthesisRunsPerSecond, 5);
  186. return runs;
  187. }
  188. async function getWillActivityData() {
  189. let tagName = getWillActivityTagName();
  190. let indexName = getWillActivityIndexName();
  191. let activityId = getWillActivityId();
  192. let activityType = getActivityType(tagName);
  193. let activityLstMap = await getActivityList(activityType);
  194. let activityData = null;
  195. magicJS.logger.info(`activityType=${activityType} activityId=${activityId}`);
  196. // magicJS.logger.info(`${JSON.stringify(activityLstMap)}`);
  197. for (let hashId in activityLstMap) {
  198. let item = activityLstMap[hashId];
  199. if ((item.activityId == activityId || item.hashId == activityId) || (indexName.length > 0 && item.name.indexOf(indexName) != -1)) {
  200. activityData = item;
  201. }
  202. }
  203. if (!activityData) {
  204. let key = `${WuBianConstKey.ActivityGoodsList}#${activityId}`;
  205. let retCvtData = magicJS.data.read(key, null);
  206. if (retCvtData) {
  207. activityData = retCvtData.activityInfo;
  208. }
  209. }
  210. return activityData;
  211. }
  212. function setCompositeGoodsListReqTime(time) {
  213. magicJS.data.write(WuBianConstKey.SynthesisCompositeGoodsListReqTime, time);
  214. }
  215. function setConvertGoodsListReqTime(time) {
  216. magicJS.data.write(WuBianConstKey.SynthesisConvertGoodsListReqTime, time);
  217. }
  218. function checkCompositeGoodsListReqForceNeed() {
  219. let time = magicJS.data.read(WuBianConstKey.SynthesisCompositeGoodsListReqTime, 0);
  220. let diffTime = Date.now() - Number(time);
  221. return diffTime > 10 * 1000;
  222. }
  223. function checkConvertGoodsListReqForceNeed() {
  224. let time = magicJS.data.read(WuBianConstKey.SynthesisConvertGoodsListReqTime, 0);
  225. let diffTime = Date.now() - Number(time);
  226. return diffTime > 10 * 1000;
  227. }
  228. function checkActivityDisable(activityId) {
  229. let key = `${WuBianConstKey.SynthesisActivityDisabled}#${activityId}`;
  230. let bDisable = magicJS.data.read(key, false);
  231. return bDisable;
  232. }
  233. function setActivityDisabled(activityId, bDisabled = true) {
  234. let key = `${WuBianConstKey.SynthesisActivityDisabled}#${activityId}`;
  235. magicJS.data.write(key, bDisabled);
  236. }
  237. function getSynthesisAmount() {
  238. let amount = magicJS.data.read(WuBianConstKey.SynthesisAmount, 10);
  239. return Number(amount);
  240. }
  241. function setSynthesisAmount(amount) {
  242. magicJS.data.write(WuBianConstKey.SynthesisAmount, amount);
  243. }
  244. function checkActivityAutoDisable(activityId) {
  245. for (let retData of gSynthesizeResultList) {
  246. if (retData && retData.code == 500) {
  247. if (retData.msg && (retData.msg.indexOf('库存不足') != -1 || retData.msg.indexOf('次数不足') != -1)) {
  248. setActivityDisabled(activityId, true);
  249. return true;
  250. }
  251. }
  252. }
  253. return false;
  254. }
  255. function getAllowAdvanceTime() {
  256. return magicJS.data.read(WuBianConstKey.SynthesisAllowAdvanceTime, 5);
  257. }
  258. function isSynthesisUseCacheEnabled() {
  259. return magicJS.data.read(WuBianConstKey.SynthesisUseCacheEnabled, false);
  260. }
  261. function checkIsSynthesizeTaskSkip(index) {
  262. let data = gSynthesizeResultDict[index];
  263. if (data && data.result) {
  264. let result = data.result;
  265. if (result.code == 200) {
  266. magicJS.logger.info(`序号[${index + 1}]任务已经执行成功过,无需再次执行[0]`);
  267. return true;
  268. }
  269. if (result.code == 500 && (result.msg.indexOf('单品状态发生变化') != -1)) {
  270. magicJS.logger.info(`序号[${index + 1}]任务已经执行成功过,无需再次执行[1]`);
  271. return true;
  272. }
  273. magicJS.logger.info(`序号[${index + 1}]任务上次执行发送异常,错误信息:${result.msg}`);
  274. }
  275. return false;
  276. }
  277. function checkUpdateActivityDataCache(activityId) {
  278. let key = `${WuBianConstKey.ActivityGoodsList}#${activityId}`;
  279. let activityData = magicJS.data.read(key, null);
  280. if (activityData) {
  281. let goodsListData = activityData.goodsList;
  282. let needUpdate = true;
  283. for (let index in gSynthesizeResultDict) {
  284. let detail = gSynthesizeResultDict[index];
  285. let result = detail.result;
  286. if (result) {
  287. if (result.code == 200 || (result.code == 500 && result.msg.indexOf('单品状态发生变化') != -1)) {
  288. let costGoodsList = detail.goodsList;
  289. let costGoodsDict = {};
  290. for (let goodsId of costGoodsList) {
  291. costGoodsDict[goodsId] = 1;
  292. }
  293. magicJS.logger.info(`costGoodsDict=${JSON.stringify(costGoodsDict)}`);
  294. magicJS.logger.info(`goodsListData=${JSON.stringify(goodsListData)}`);
  295. for (let i = 0; i < goodsListData.length; i++) {
  296. checkRemoveVerList(goodsListData[i].verList, costGoodsDict);
  297. }
  298. needUpdate = true;
  299. }
  300. }
  301. }
  302. if (needUpdate) {
  303. magicJS.data.write(key, activityData);
  304. let activityInfo = activityData.activityInfo;
  305. magicJS.logger.info(`更新活动[${activityInfo.name}]任务数据缓存成功`);
  306. }
  307. }
  308. }
  309. function checkRemoveVerList(srcVerList, removeData) {
  310. for (let i = srcVerList.length - 1; i >= 0; i--) {
  311. const verInfo = srcVerList[i];
  312. if (removeData[verInfo.goodsId]) {
  313. srcVerList.splice(i, 1);
  314. }
  315. }
  316. return srcVerList;
  317. }
  318. async function trySynthesize() {
  319. magicJS.logger.info(`[1]活动任务执行前检查...`);
  320. let activityData = await getWillActivityData();
  321. // magicJS.logger.info(`activityData=${JSON.stringify(activityData)}`);
  322. if (!activityData) {
  323. return;
  324. }
  325. let nowTime = Date.now() / 1000;
  326. let diffTimeSec = getAllowAdvanceTime();
  327. if (nowTime < activityData.startTime - diffTimeSec) {
  328. magicJS.notification.appendNotifyInfo(`⚠️活动[${activityData.name}]未开始,距离开始时间${Math.floor(activityData.startTime - nowTime)}秒,请在活动开始前${diffTimeSec}秒内执行!`);
  329. return;
  330. }
  331. magicJS.logger.info(`[2]活动任务执行前检查...`);
  332. let activityId = activityData.hashId || activityData.activityId;
  333. let retCvtData = null;
  334. if (isSynthesisUseCacheEnabled()) {
  335. magicJS.logger.info(`当前使用的活动数据来自缓存,如不需在设置中关闭使用缓存功能`);
  336. let key = `${WuBianConstKey.ActivityGoodsList}#${activityId}`;
  337. retCvtData = magicJS.data.read(key, null);
  338. }
  339. if (!retCvtData) {
  340. if (activityData.type == 0) {
  341. retCvtData = await doGetCompositeGoodsList(activityId, checkCompositeGoodsListReqForceNeed());
  342. } else if (activityData.type == 1) {
  343. retCvtData = await doGetConvertGoodsList(activityId, checkConvertGoodsListReqForceNeed());
  344. }
  345. }
  346. magicJS.logger.info(`[3]活动任务执行前检查...`);
  347. // magicJS.logger.info(`retCvtData=${JSON.stringify(retCvtData)}`);
  348. if (!retCvtData) {
  349. magicJS.notification.appendNotifyInfo(`⚠️活动[${activityData.name}]详细合成信息数据不存在`);
  350. return;
  351. }
  352. if (checkActivityDisable(activityId)) {
  353. magicJS.notification.appendNotifyInfo(`⚠️活动[${activityData.name}]已禁用,请重新配置`);
  354. return;
  355. }
  356. let willCount = getActivityWillCount();
  357. willCount = getSynthesisAmount();
  358. let combinationLst = getSynthesizeCombination(retCvtData);
  359. // magicJS.logger.info(`combinationLst=${JSON.stringify(combinationLst)}`);
  360. let nExcuteCount = Math.min(willCount, combinationLst.length);
  361. let tipsText = `[${activityData.activityType}]${activityData.name},执行结果如下:\n`;
  362. let nRuns = getRunsPreSecond();
  363. let ctrlMillSec = 1000 / nRuns;
  364. let isConcurrentExcute = isConcurrentMode();
  365. if (nExcuteCount == 0) {
  366. tipsText += `由于缺少可执行的材料组合,该活动自动禁用\n`;
  367. tipsText += `请检查活动重新配置,或购买相应材料,重新开启活动任务`;
  368. tipsText = `❌` + tipsText;
  369. setActivityDisabled(activityId, true);
  370. } else {
  371. if (isConcurrentExcute) {
  372. nowTime = Date.now() / 1000;
  373. let waittingMSec = Math.floor((activityData.startTime - nowTime) * 1000);
  374. if (waittingMSec > 0) {
  375. magicJS.logger.info(`等待${waittingMSec}毫秒后开始执行...`);
  376. await magicJS.utils.sleep(waittingMSec - 80);
  377. }
  378. magicJS.logger.info(`活动任务开始执行...`);
  379. for (let n = 0; n < nRuns; n++) {
  380. let startTime = Date.now();
  381. for (let i = 0; i < nExcuteCount; i++) {
  382. let oneCombination = combinationLst[i];
  383. let goodsList = getCombinationGoodsList(oneCombination);
  384. magicJS.logger.info(`第${n}-${i}趟开始执行...`);
  385. if (checkIsSynthesizeTaskSkip(i)) {
  386. magicJS.logger.info(`第${n}-${i}趟跳过执行...`);
  387. continue;
  388. }
  389. if (activityData.type == 0) {
  390. doCreateCompositeOrder(i, activityId, goodsList);
  391. } else if (activityData.type == 1) {
  392. doCreateConvertOrder(i, activityId, goodsList);
  393. }
  394. }
  395. let costTime = Date.now() - startTime;
  396. if (costTime < ctrlMillSec) {
  397. await magicJS.utils.sleep(ctrlMillSec - costTime);
  398. }
  399. if (checkActivityAutoDisable()) {
  400. break;
  401. }
  402. }
  403. let nSuccCount = 0;
  404. let nFailCount = 0;
  405. for (let retData of gSynthesizeResultList) {
  406. if (retData && retData.code == 200) {
  407. nSuccCount += 1;
  408. } else {
  409. if (retData.code == 500 && retData.msg && retData.msg.indexOf('库存不足') != -1) {
  410. setActivityDisabled(activityId, true);
  411. }
  412. nFailCount += 1;
  413. }
  414. magicJS.logger.info(`序号[${retData.index}]执行结果:${retData?.msg || '未知'}`);
  415. }
  416. tipsText += `成功兑换次数:${nSuccCount}\n`;
  417. tipsText += `失败兑换次数:${nFailCount}\n`;
  418. tipsText += `未知结果次数:${nExcuteCount * nRuns - nSuccCount - nFailCount}\n`;
  419. if (nSuccCount >= willCount) {
  420. tipsText += `由于兑换次数已达到配置的次数,该活动自动禁用\n`;
  421. setActivityDisabled(activityId, true);
  422. } else {
  423. setSynthesisAmount(willCount - nSuccCount);
  424. if (isSynthesisUseCacheEnabled()) {
  425. checkUpdateActivityDataCache(activityId);
  426. }
  427. }
  428. if (nSuccCount > 0) {
  429. tipsText = `🎉` + tipsText;
  430. } else {
  431. tipsText = `❌` + tipsText;
  432. }
  433. } else {
  434. nowTime = Date.now() / 1000;
  435. let waittingMSec = Math.floor((activityData.startTime - nowTime) * 1000);
  436. if (waittingMSec > 0) {
  437. magicJS.logger.info(`等待${waittingMSec}毫秒后开始执行...`);
  438. await magicJS.utils.sleep(waittingMSec - 80);
  439. }
  440. let nSuccCount = 0;
  441. let nFailCount = 0;
  442. for (let n = 0; n < nRuns; n++) {
  443. let startTime = Date.now();
  444. for (let i = 0; i < nExcuteCount; i++) {
  445. let oneCombination = combinationLst[i];
  446. let goodsList = getCombinationGoodsList(oneCombination);
  447. let retData = null;
  448. if (activityData.type == 0) {
  449. retData = await doCreateCompositeOrder(i, activityId, goodsList);
  450. } else if (activityData.type == 1) {
  451. retData = await doCreateConvertOrder(i, activityId, goodsList);
  452. }
  453. let errMsg = '';
  454. if (retData && retData.code == 200) {
  455. nSuccCount += 1;
  456. errMsg = `序号[${i + 1}]使用材料[${getCombinationGoodsLstText(oneCombination)}]兑换成功`;
  457. } else {
  458. nFailCount += 1;
  459. errMsg = `序号[${i + 1}]使用材料[${getCombinationGoodsLstText(oneCombination)}]${retData?.msg || '兑换失败'}`;
  460. }
  461. tipsText += `${errMsg}\n`;
  462. }
  463. let costTime = Date.now() - startTime;
  464. if (costTime < ctrlMillSec) {
  465. await magicJS.utils.sleep(ctrlMillSec - costTime);
  466. }
  467. }
  468. if (nSuccCount >= willCount) {
  469. tipsText += `由于兑换次数已达到配置的次数,该活动自动禁用\n`;
  470. setActivityDisabled(activityId, true);
  471. } else {
  472. setSynthesisAmount(willCount - nSuccCount);
  473. }
  474. if (nSuccCount > 0) {
  475. tipsText = `🎉` + tipsText;
  476. } else {
  477. tipsText = `❌` + tipsText;
  478. }
  479. }
  480. }
  481. magicJS.logger.info(`活动任务执行结束`);
  482. magicJS.notification.appendNotifyInfo(tipsText);
  483. }
  484. function getCombinationGoodsList(combination) {
  485. let retList = [];
  486. for (let item of combination) {
  487. retList.push(item.goodsId);
  488. }
  489. return retList;
  490. }
  491. function getCombinationGoodsLstText(combination) {
  492. let text = '';
  493. for (let item of combination) {
  494. text += `${item.title}#${item.ver},`;
  495. }
  496. return text.substring(0, text.length - 1);
  497. }
  498. function getSynthesizeCombination(retCvtData) {
  499. let goodsList = retCvtData.goodsList;
  500. let activityInfo = retCvtData.activityInfo;
  501. let ruleList = retCvtData.ruleList;
  502. if (!ruleList) {
  503. if (typeof activityInfo.limit == 'number') {
  504. if (activityInfo.articleId && activityInfo.articleId.length > 0) {
  505. ruleList = [{
  506. num: activityInfo.limit,
  507. desc: '',
  508. matchArtIdList: [activityInfo.articleId],
  509. }];
  510. } else {
  511. ruleList = [{
  512. num: activityInfo.limit,
  513. desc: '',
  514. matchArtIdList: [goodsList[0].artHashId],
  515. }];
  516. }
  517. }
  518. }
  519. let retAllList = [];
  520. let isContinus = true;
  521. while (isContinus) {
  522. let retOneList = [];
  523. // magicJS.logger.info(`ruleList${JSON.stringify(ruleList)}`);
  524. // magicJS.logger.info(`goodsList:${JSON.stringify(goodsList)}`);
  525. for (let i = 0; i < ruleList.length; i++) {
  526. let limitCount = ruleList[i].num;
  527. let matchArtIdList = ruleList[i].matchArtIdList;
  528. // magicJS.logger.info(`limitCount:${limitCount}`);
  529. // magicJS.logger.info(`matchArtIdList:${JSON.stringify(matchArtIdList)}`);
  530. let oneData = goodsList[i];
  531. let matchArtList = getSubGoodsList(goodsList, matchArtIdList, limitCount);
  532. if (matchArtList && matchArtList.length == limitCount) {
  533. // magicJS.logger.info(`matchArtList:${JSON.stringify(matchArtList)}`);
  534. for (let j = 0; j < matchArtList.length; j++) {
  535. retOneList.push(matchArtList[j]);
  536. }
  537. } else {
  538. isContinus = false;
  539. break;
  540. }
  541. }
  542. if (isContinus) {
  543. retAllList.push(retOneList);
  544. }
  545. }
  546. return retAllList;
  547. }
  548. function getSubGoodsList(goodsList, matchArtIdList, num) {
  549. let retList = [];
  550. for (let i = 0; i < goodsList.length; i++) {
  551. const item = goodsList[i];
  552. if (matchArtIdList.includes(item.artHashId)) {
  553. let neddNum = num - retList.length;
  554. let diffNum = item.verList.length - neddNum;
  555. if (diffNum >= 0) {
  556. let tmpLst = item.verList.splice(item.verList.length - num, neddNum);
  557. // retList = retList.concat(tmpLst);
  558. for (let j = 0; j < tmpLst.length; j++) {
  559. tmpLst[j].title = item.title;
  560. retList.push(tmpLst[j]);
  561. }
  562. break;
  563. } else {
  564. let tmpLst = item.verList.splice(0, retList.length);
  565. // retList = retList.concat(tmpLst);
  566. for (let j = 0; j < tmpLst.length; j++) {
  567. tmpLst[j].title = item.title;
  568. retList.push(tmpLst[j]);
  569. }
  570. }
  571. neddNum = num - retList.length;
  572. if (neddNum == 0) {
  573. break;
  574. }
  575. }
  576. }
  577. return retList;
  578. }
  579. function getActivityType(key) {
  580. let nType = 0;
  581. if (!key || key.length == 0) {
  582. return nType;
  583. }
  584. let typeMap = {
  585. 1: '合成活动',
  586. 2: '置换活动',
  587. 3: '分解活动',
  588. 4: '兑换活动'
  589. };
  590. for (let k in typeMap) {
  591. if (typeMap[k].indexOf(key) != -1) {
  592. nType = parseInt(k);
  593. break;
  594. }
  595. }
  596. return nType;
  597. }
  598. function isObjectEmpty(obj) {
  599. return Object.keys(obj).length === 0;
  600. }
  601. async function getActivityList(activityType, noCache) {
  602. let key = `${WuBianConstKey.ActivityListData}#${activityType}`;
  603. let dataDict = magicJS.data.read(key, null);
  604. if (!dataDict || isObjectEmpty(dataDict) || noCache) {
  605. dataDict = await queryAllActivityList(activityType);
  606. magicJS.data.write(key, dataDict);
  607. }
  608. return dataDict;
  609. }
  610. async function queryAllActivityList(activityType, status = 0) {
  611. let dataDict = {};
  612. for (let i = 1; i < 3; i++) {
  613. let ret = await queryActivityList(activityType, i, status);
  614. if (ret && ret.code == 200) {
  615. magicJS.logger.info(`获取活动列表成功,当前页数:${i}`);
  616. const iData = ret.data;
  617. const itemList = iData.list;
  618. for (let item of itemList) {
  619. dataDict[item.hashId] = item;
  620. }
  621. if (iData.next == 0) {
  622. break;
  623. }
  624. }
  625. }
  626. return dataDict;
  627. }
  628. async function queryActivityList(activityType, page, status = 0) {
  629. const url = `https://api.wubian.pro/vmf/app/synthesis/activityList`;
  630. const reqData = {
  631. page: page,
  632. status: status,
  633. };
  634. if (activityType && activityType > 0) {
  635. reqData.activityType = String(activityType);
  636. }
  637. let options = {
  638. url: url,
  639. headers: gCommonHeaders,
  640. body: JSON.stringify(reqData),
  641. };
  642. let result = await magicJS.http.post(options).then(response => {
  643. try {
  644. let rspData = response.body;
  645. magicJS.logger.info(`rspData=${JSON.stringify(rspData)}`);
  646. return rspData;
  647. } catch (e) {
  648. magicJS.logger.error(e);
  649. }
  650. }).catch(err => {
  651. const msg = `请求活动列表数据异常\n${JSON.stringify(err)}`;
  652. magicJS.logger.error(msg);
  653. });
  654. return result;
  655. }
  656. async function doGetConvertGoodsList(activityId, noCache) {
  657. let key = `${WuBianConstKey.ActivityGoodsList}#${activityId}`;
  658. let data = magicJS.data.read(key, null);
  659. if (!data || noCache) {
  660. setConvertGoodsListReqTime(Date.now());
  661. let ret = await queryConvertGoodsList(activityId);
  662. if (ret && ret.code == 200) {
  663. data = ret.data;
  664. magicJS.data.write(key, data);
  665. }
  666. }
  667. return data;
  668. }
  669. async function queryConvertGoodsList(activityId) {
  670. const url = `https://api.wubian.pro/vmf/app/synthesis/convertGoodsList`;
  671. const reqData = {
  672. activityId: activityId,
  673. };
  674. let options = {
  675. url: url,
  676. headers: gCommonHeaders,
  677. body: JSON.stringify(reqData),
  678. };
  679. let result = await magicJS.http.post(options).then(response => {
  680. try {
  681. let rspData = response.body;
  682. magicJS.logger.info(`rspData=${JSON.stringify(rspData)}`);
  683. return rspData;
  684. } catch (e) {
  685. magicJS.logger.error(e);
  686. }
  687. }).catch(err => {
  688. const msg = `请求兑换消耗产品列表异常\n${JSON.stringify(err)}`;
  689. magicJS.logger.error(msg);
  690. });
  691. return result;
  692. }
  693. async function doGetCompositeGoodsList(activityId, noCache) {
  694. let key = `${WuBianConstKey.ActivityGoodsList}#${activityId}`;
  695. let data = magicJS.data.read(key, null);
  696. if (!data || noCache) {
  697. setCompositeGoodsListReqTime(Date.now());
  698. let ret = await queryCompositeGoodsList(activityId);
  699. if (ret && ret.code == 200) {
  700. data = ret.data;
  701. magicJS.data.write(key, data);
  702. }
  703. }
  704. return data;
  705. }
  706. async function queryCompositeGoodsList(activityId) {
  707. const url = `https://api.wubian.pro/vmf/app/synthesis/compositeGoodsList`;
  708. const reqData = {
  709. id: activityId,
  710. };
  711. let options = {
  712. url: url,
  713. headers: gCommonHeaders,
  714. body: JSON.stringify(reqData),
  715. };
  716. let result = await magicJS.http.post(options).then(response => {
  717. try {
  718. let rspData = response.body;
  719. magicJS.logger.info(`rspData=${JSON.stringify(rspData)}`);
  720. return rspData;
  721. } catch (e) {
  722. magicJS.logger.error(e);
  723. }
  724. }).catch(err => {
  725. const msg = `请求合成消耗产品列表异常\n${JSON.stringify(err)}`;
  726. magicJS.logger.error(msg);
  727. });
  728. return result;
  729. }
  730. async function doCreateConvertOrder(index, activityId, goodsList) {
  731. const url = `https://api.wubian.pro/vmf/app/synthesis/createConvertOrder`;
  732. const reqData = {
  733. activityId: activityId,
  734. goodsList: goodsList,
  735. };
  736. let options = {
  737. url: url,
  738. headers: gCommonHeaders,
  739. body: JSON.stringify(reqData),
  740. };
  741. let result = await magicJS.http.post(options).then(response => {
  742. try {
  743. let rspData = response.body;
  744. magicJS.logger.info(`rspData=${JSON.stringify(rspData)}`);
  745. rspData.index = index;
  746. gSynthesizeResultList.push(rspData);
  747. gSynthesizeResultDict[index] = { activityId: activityId, result: rspData, goodsList: goodsList };
  748. return rspData;
  749. } catch (e) {
  750. magicJS.logger.error(e);
  751. }
  752. }).catch(err => {
  753. const msg = `请求兑换异常\n${JSON.stringify(err)}`;
  754. magicJS.logger.error(msg);
  755. });
  756. return result;
  757. }
  758. async function doCreateCompositeOrder(index, activityId, goodsList) {
  759. const url = `https://api.wubian.pro/vmf/app/synthesis/createCompositeOrder`;
  760. const reqData = {
  761. activityId: activityId,
  762. goodsList: goodsList,
  763. };
  764. let options = {
  765. url: url,
  766. headers: gCommonHeaders,
  767. body: JSON.stringify(reqData),
  768. };
  769. let result = await magicJS.http.post(options).then(response => {
  770. try {
  771. let rspData = response.body;
  772. magicJS.logger.info(`rspData=${JSON.stringify(rspData)}`);
  773. gSynthesizeResultList.push(rspData);
  774. gSynthesizeResultDict[index] = { activityId: activityId, result: rspData, goodsList: goodsList };
  775. return rspData;
  776. } catch (e) {
  777. magicJS.logger.error(e);
  778. }
  779. }).catch(err => {
  780. const msg = `请求合成异常\n${JSON.stringify(err)}`;
  781. magicJS.logger.error(msg);
  782. });
  783. return result;
  784. }
  785. Main().catch((e) => magicJS.logger.log(`-\n ${e}`)).finally(() => magicJS.done());
  786. //---SyncByPyScript---MagicJS3-start
  787. function MagicJS(e = "MagicJS", t = "INFO") { const n = () => { const e = "undefined" != typeof $loon, t = "undefined" != typeof $task, r = "undefined" != typeof module, n = "undefined" != typeof $httpClient && !e, o = "undefined" != typeof $storm, i = "undefined" != typeof $environment && void 0 !== $environment["stash-build"]; var s = n || e || o || i; const a = "undefined" != typeof importModule; return { isLoon: e, isQuanX: t, isNode: r, isSurge: n, isStorm: o, isStash: i, isSurgeLike: s, isScriptable: a, get name() { return e ? "Loon" : t ? "QuantumultX" : r ? "NodeJS" : n ? "Surge" : a ? "Scriptable" : "unknown" }, get build() { return n ? $environment["surge-build"] : i ? $environment["stash-build"] : o ? $storm.buildVersion : void 0 }, get language() { if (n || i) return $environment.language }, get version() { return n ? $environment["surge-version"] : i ? $environment["stash-version"] : o ? $storm.appVersion : r ? process.version : void 0 }, get system() { return n ? $environment.system : r ? process.platform : void 0 }, get systemVersion() { if (o) return $storm.systemVersion }, get deviceName() { if (o) return $storm.deviceName } } }, o = (r, e = "INFO") => { let n = e, t = "\n"; const o = { SNIFFER: 6, DEBUG: 5, INFO: 4, NOTIFY: 3, WARNING: 2, ERROR: 1, CRITICAL: 0, NONE: -1 }, i = { SNIFFER: "", DEBUG: "", INFO: "", NOTIFY: "", WARNING: "❗ ", ERROR: "❌ ", CRITICAL: "❌ ", NONE: "" }, s = (e, t = "INFO") => { o[n] < o[t.toUpperCase()] || console.log(`██[${r}][${t}]` + i[t.toUpperCase()] + e + "\n") }; return { getLevel: () => n, setLevel: e => { n = e }, sniffer: (...e) => { e = e.join(t); s(e, "SNIFFER") }, log: (...e) => { e = e.join(t); console.log(`██[${r}]` + e + "\n") }, debug: (...e) => { e = e.join(t); s(e, "DEBUG") }, info: (...e) => { e = e.join(t); s(e, "INFO") }, notify: (...e) => { e = e.join(t); s(e, "NOTIFY") }, warning: (...e) => { e = e.join(t); s(e, "WARNING") }, error: (...e) => { e = e.join(t); s(e, "ERROR") }, retry: (...e) => { e = e.join(t); s(e, "RETRY") } } }; return new class { constructor(e, t) { var r; this._startTime = Date.now(), this.version = "3.0.0", this.scriptName = e, this.env = n(), this.logger = o(e, t), this.http = "function" == typeof MagicHttp ? MagicHttp(this.env, this.logger) : void 0, this.data = "function" == typeof MagicData ? MagicData(this.env, this.logger) : void 0, this.notification = "function" == typeof MagicNotification ? MagicNotification(this.scriptName, this.env, this.logger, this.http) : void 0, this.utils = "function" == typeof MagicUtils ? MagicUtils(this.env, this.logger) : void 0, this.qinglong = "function" == typeof MagicQingLong ? MagicQingLong(this.env, this.data, this.logger) : void 0, void 0 !== this.data && (t = this.data.read("magic_loglevel"), r = this.data.read("magic_bark_url"), t && this.logger.setLevel(t.toUpperCase()), r) && this.notification.setBark(r), this.logger.info(e + ", 开始执行!") } get isRequest() { return "undefined" != typeof $request } get isStrictRequest() { return "undefined" != typeof $request && "undefined" == typeof $response } get isResponse() { return "undefined" != typeof $response } get isDebug() { return "DEBUG" === this.logger.level } get request() { return "undefined" != typeof $request ? $request : void 0 } get response() { if ("undefined" != typeof $response) return $response.hasOwnProperty("status") && ($response.statusCode = $response.status), $response.hasOwnProperty("statusCode") && ($response.status = $response.statusCode), $response } log(...e) { this.logger.log(e) } toStr(e, t = null) { try { return JSON.stringify(e) } catch { return t } } toObj(e, t = null) { try { return JSON.parse(e) } catch { return t } } checkRecordRequestBody() { if (this.isRequest) { var t = $request.body; if (t) { var r = this.env, n = $request.path; let e = this.scriptName + "#" + n.replace("/", "_"); e = e.replace("?", "#"), r.isQuanX && $prefs.setValueForKey(t, e), (r.isLoon || r.isSurge) && $persistentStore.write(t, e), r.isNode && require("fs").writeFileSync(e + ".json", t, { flag: "w" }, e => console.log(e)) } } } getRequestBody() { var e = this.env, t = $request.path; let r = this.scriptName + "#" + t.replace("/", "_"); if (r = r.replace("?", "#"), e.isSurge || e.isLoon) return $persistentStore.read(r); if (e.isQuanX) return $prefs.valueForKey(r); if (e.isNode) { t = r + ".json", e = require("fs"); if (!e.existsSync(t)) return JSON.parse(e.readFileSync(t)) } } getResponseBody() { if ($response) return $response.body } parseCookies(e, t = !1) { let r = {}; return t ? e && e.split(";").forEach(function (e) { e = e.split("="); r[e.shift().trim()] = decodeURIComponent(e.join("=")) }) : e && e.split(";").forEach(function (e) { e = e.split("="); r[e.shift().trim()] = e.join("=") }), r } serializeCookies(e, t = !1) { var r = []; if (t) for (var n in e) { var o = e[n], n = n + "=" + encodeURIComponent(o); r.push(n) } else for (var i in e) { var s = e[i], i = i + "=" + s; r.push(i) } return r.join("; ") } parseSetCookies(e) { var t = e.split(/,\s*/).map(e => { var e = e.trim().split(/;\s*(?=[^=]+=[^;]*)/), t = e[0].split("=").map(e => e.trim()); const r = { name: t[0], value: t[1] }; return e.slice(1).forEach(e => { var [e, t] = e.split("=").map(e => e.trim()); r[e] = t || !0 }), r }), r = []; let n = 0; for (; n < t.length;) { var o, i = t[n]; r.push(i), i.Expires ? ((o = t[n + 1]) && (i.Expires = i.Expires + "," + o.name), n += 2) : n += 1 } return r } objToQueryStr(t, r) { let n = ""; for (const o in t) { let e = t[o]; null != e && "" !== e && ("object" == typeof e ? e = JSON.stringify(e) : r && (e = encodeURIComponent(e)), n += `${o}=${e}&`) } return n = n.substring(0, n.length - 1) } parseQueryStr(e) { var t = {}, r = (e = -1 < e.indexOf("?") ? e.split("?")[1] : e).split("&"); for (let e = 0; e < r.length; e++) { var n = r[e].split("="); t[n[0]] = n[1] } return t } deepClone(e, t) { for (var r in t = t || {}, e) "object" == typeof e[r] ? (t[r] = e[r].constructor === Array ? [] : {}, this.deepClone(e[r], t[r])) : t[r] = e[r]; return t } formatDate(e, t) { var r, n = { "M+": e.getMonth() + 1, "d+": e.getDate(), "H+": e.getHours(), "m+": e.getMinutes(), "s+": e.getSeconds(), "q+": Math.floor((e.getMonth() + 3) / 3), S: e.getMilliseconds() }; for (r in /(y+)/.test(t) && (t = t.replace(RegExp.$1, (e.getFullYear() + "").substr(4 - RegExp.$1.length))), n) new RegExp("(" + r + ")").test(t) && (t = t.replace(RegExp.$1, 1 == RegExp.$1.length ? n[r] : ("00" + n[r]).substr(("" + n[r]).length))); return t } parseDate(a, e) { let l = { y: 0, M: 1, d: 0, H: 0, h: 0, m: 0, s: 0, S: 0 }; (e = e || "yyyy-MM-dd").replace(/([^yMdHmsS]*?)(([yMdHmsS])\3*)([^yMdHmsS]*?)/g, function (e, t, r, n, o, i, s) { return a = a.replace(new RegExp(t + "(\\d{" + r.length + "})" + o), function (e, t) { return l[n] = parseInt(t), "" }), "" }), l.M--; e = new Date(l.y, l.M, l.d, l.H, l.m, l.s); return 0 !== l.S && e.setMilliseconds(l.S), e } getBaseDoneHeaders(e = {}) { return Object.assign({ "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Methods": "POST,GET,OPTIONS,PUT,DELETE", "Access-Control-Allow-Headers": "Origin, X-Requested-With, Content-Type, Accept" }, e) } getHtmlDoneHeaders() { return this.getBaseDoneHeaders({ "Content-Type": "text/html;charset=UTF-8" }) } getJsonDoneHeaders() { return this.getBaseDoneHeaders({ "Content-Type": "text/json; charset=utf-8", Connection: "keep-alive" }) } doWxpusherSend(e) { var t = this.getJsonDoneHeaders(), t = (t.Host = "wxpusher.zjiecode.com", t["Content-Type"] = "application/json;charset=UTF-8", { url: "https://wxpusher.zjiecode.com/api/send/message", headers: t, body: JSON.stringify(e) }); return this.http.post(t) } fastWxpusherSend(e, t = "", r = "") { return this.doWxpusherSend({ appToken: "AT_7wDWqSoT8xpJCQqJtHpshKhw7kXc0XCW", content: e, summary: t, contentType: 1, topicIds: [], uids: ["UID_6P4B00X6Zv8U2oKC0I2R09emxtqq"], url: r, verifyPay: !1, verifyPayType: 0 }) } isEmpty(e) { return void 0 === e || null == e || "" == e || "null" == e || "undefined" == e || 0 === e.length } base64Encode(e) { var t, r, n, o = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; let i, s, a; for (a = e.length, s = 0, i = ""; s < a;) { if (t = 255 & e.charCodeAt(s++), s == a) { i = (i += o.charAt(t >> 2)) + o.charAt((3 & t) << 4) + "=="; break } if (r = e.charCodeAt(s++), s == a) { i = (i = (i += o.charAt(t >> 2)) + o.charAt((3 & t) << 4 | (240 & r) >> 4)) + o.charAt((15 & r) << 2) + "="; break } n = e.charCodeAt(s++), i = (i = (i = (i += o.charAt(t >> 2)) + o.charAt((3 & t) << 4 | (240 & r) >> 4)) + o.charAt((15 & r) << 2 | (192 & n) >> 6)) + o.charAt(63 & n) } return i } base64Decode(e) { var t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; if (/([^\s]+[^0-9a-zA-Z\+\/\=]|[^0-9a-zA-Z\+\/\=]\s+)/.test(e)) throw new Error("Invalid base64 input"); var r, n, o, i, s, a, l = e.replace(/\s/g, ""); let u = "", c = 0; for (; c < l.length;)o = t.indexOf(l.charAt(c++)), r = (15 & (i = t.indexOf(l.charAt(c++)))) << 4 | (s = t.indexOf(l.charAt(c++))) >> 2, n = (3 & s) << 6 | (a = t.indexOf(l.charAt(c++))), u += String.fromCharCode(o << 2 | i >> 4), 64 !== s && (u += String.fromCharCode(r)), 64 !== a && (u += String.fromCharCode(n)); return u = this.utf8Decode(u) } utf8Decode(t) { let e = [], r = 0, n = 0, o = 0; for (t = t.replace(/\r\n/g, "\n"); r < t.length;) { n = 255 & t.charCodeAt(r), o = 0, o = n <= 191 ? (n &= 127, 1) : n <= 223 ? (n &= 31, 2) : n <= 239 ? (n &= 15, 3) : (n &= 7, 4); for (let e = 1; e < o; ++e)n = n << 6 | 63 & t.charCodeAt(e + r); 4 === o ? (n -= 65536, e.push(String.fromCharCode(55296 | n >> 10 & 1023)), e.push(String.fromCharCode(56320 | 1023 & n))) : e.push(String.fromCharCode(n)), r += o } return e.join("") } parseJwt(e) { try { var t = e.split("."), r = t[0].replace(/-/g, "+").replace(/_/g, "/"), n = this.base64Decode(r).replace(/\0/g, ""), o = JSON.parse(n), i = t[1].replace(/-/g, "+").replace(/_/g, "/"), s = this.base64Decode(i).replace(/\0/g, ""); return { header: o, payload: JSON.parse(s), signature: t[2] } } catch (e) { return this.log(e), null } } costTime() { var e = this.scriptName + "执行完毕!", t = (this._endTime = (new Date).getTime(), this._endTime - this._startTime); this.logger.info(e + `耗时【${t / 1e3}】秒`) } done = (e = {}) => { this.costTime(), "undefined" != typeof $done && $done(e) } }(e, t) } function MagicHttp(d, p) { var e; let g; d.isNode && (e = require("axios"), g = e.create()); class t { constructor(e = !0) { this.handlers = [], this.isRequest = e } use(e, t, r) { return "function" == typeof e && p.debug("Register fulfilled " + e.name), "function" == typeof t && p.debug("Register rejected " + t.name), this.handlers.push({ fulfilled: e, rejected: t, synchronous: !(!r || "boolean" != typeof r.synchronous) && r.synchronous, runWhen: r ? r.runWhen : null }), this.handlers.length - 1 } eject(e) { this.handlers[e] && (this.handlers[e] = null) } forEach(t) { this.handlers.forEach(e => { null !== e && t(e) }) } } function f(e) { let r = { ...e }; return r.params && !d.isNode && (e = Object.keys(r.params).map(e => { var t = encodeURIComponent(e); return r.url = r.url.replace(new RegExp(e + "=[^&]*", "ig"), ""), r.url = r.url.replace(new RegExp(t + "=[^&]*", "ig"), ""), t + "=" + encodeURIComponent(r.params[e]) }).join("&"), r.url.indexOf("?") < 0 && (r.url += "?"), /(&|\?)$/g.test(r.url) || (r.url += "&"), r.url += e, delete r.params, p.debug("Params to QueryString: " + r.url)), r } const h = (e, t = null) => { if (e) { t = { ...e, config: e.config || t, status: e.statusCode || e.status, body: e.body || e.data, headers: e.headers || e.header }; if ("string" == typeof t.body) try { t.body = JSON.parse(t.body) } catch { } return delete t.data, t } return e }; const y = (e, t = null) => { if (e && 400 <= e.status) return p.debug("Raise exception when status code is " + e.status), { name: "RequestException", message: "Request failed with status code " + e.status, config: t || e.config, response: e } }, m = { request: new t, response: new t(!1) }; let v = [], b = [], S = !0; function N(e) { return e = f(e), p.debug(`HTTP ${e.method.toUpperCase()}:` + "\n" + JSON.stringify(e)), e } function E(t) { try { t = t && h(t), p.sniffer(`HTTP ${t.config.method.toUpperCase()}:` + "\n" + JSON.stringify(t.config) + "\nSTATUS CODE:\n" + t.status + "\nRESPONSE:\n" + ("object" == typeof t.body ? JSON.stringify(t.body) : t.body)); var e = y(t); return e ? Promise.reject(e) : t } catch (e) { return p.error(e), t } } const r = (e, r) => { let n; r = ((e, t) => { let r = "object" == typeof t ? { headers: {}, ...t } : { url: t, headers: {} }; return r.method || (r.method = e), !0 === (r = f(r)).rewrite && (d.isSurge ? (r.headers["X-Surge-Skip-Scripting"] = !1, delete r.rewrite) : d.isQuanX && (r.hints = !1, delete r.rewrite)), d.isSurgeLike ? (t = r.headers["content-type"] || r.headers["Content-Type"], "GET" !== r.method && t && 0 <= t.indexOf("application/json") && r.body instanceof Array && (r.body = JSON.stringify(r.body), p.debug("Convert Array object to String: " + r.body))) : d.isQuanX ? (r.hasOwnProperty("body") && "string" != typeof r.body && (r.body = JSON.stringify(r.body)), r.method = e) : d.isNode && ("POST" === e || "PUT" === e || "PATCH" === e || "DELETE" === e ? r.data = r.data || r.body : "GET" === e && (r.params = r.params || r.body), delete r.body), r })(e.toUpperCase(), r), n = d.isNode ? g : d.isSurgeLike ? i => new Promise((n, o) => { $httpClient[e.toLowerCase()](i, (e, t, r) => { e ? (e = { name: e.name || e, message: e.message || e, stack: e.stack || e, config: i, response: h(t) }, o(e)) : (t.config = i, t.body = r, n(t)) }) }) : n => new Promise((r, t) => { $task.fetch(n).then(e => { e = h(e, n); var t = y(e, n); if (t) return Promise.reject(t); r(e) }).catch(e => { e = { name: e.message || e.error, message: e.message || e.error, stack: e.error, config: n, response: e.response ? h(e.response) : null }; t(e) }) }); let o; var t = r; try { v = [], b = [], m.request.forEach(e => { "function" == typeof e.runWhen && !1 === e.runWhen(t) || (S = S && e.synchronous, v.unshift(e.fulfilled, e.rejected)) }), m.response.forEach(e => { b.push(e.fulfilled, e.rejected) }) } catch (e) { p.error(`Failed to register interceptors: ${e}.`) } var i = [N, void 0], s = [E, void 0]; if (S) { for (p.debug("Interceptors are executed in synchronous mode"), Array.prototype.unshift.apply(v, i), v = v.concat([N, void 0]); v.length;) { var a = v.shift(), l = v.shift(); try { "function" == typeof a && p.debug("Executing request fulfilled " + a.name), r = a(r) } catch (e) { "function" == typeof l && p.debug("Executing request rejected " + l.name), l(e); break } } try { o = (!d.isNode && r.timeout ? c : n)(r) } catch (e) { return Promise.reject(e) } for (Array.prototype.unshift.apply(b, s); b.length;)o = o.then(b.shift(), b.shift()); return o } { p.debug("Interceptors are executed in asynchronous mode"); let t = [n, void 0]; for (Array.prototype.unshift.apply(t, i), Array.prototype.unshift.apply(t, v), t = (t = t.concat(s)).concat(b), o = Promise.resolve(r); t.length;)try { let e = t.shift(); var u = t.shift(); "function" == typeof (e = !d.isNode && r.timeout && e === n ? c : e) && p.debug("Executing request fulfilled " + e.name), "function" == typeof u && p.debug("Executing request rejected " + u.name), o = o.then(e, u) } catch (e) { p.error("request exception: " + e) } return o } function c(r) { try { var e = new Promise((e, t) => { setTimeout(() => { var e = { message: `timeout of ${r.timeout}ms exceeded.`, config: r }; t(e) }, r.timeout) }); return Promise.race([n(r), e]) } catch (e) { p.error(`Request Timeout exception: ${e}.`) } } }; return { request: r, interceptors: m, convertHeadersToLowerCase: r => Object.keys(r).reduce((e, t) => (e[t.toLowerCase()] = r[t], e), {}), convertHeadersToCamelCase: r => Object.keys(r).reduce((e, t) => { return e[t.split("-").map(e => e[0].toUpperCase() + e.slice(1)).join("-")] = r[t], e }, {}), modifyResponse: h, get: e => r("GET", e), post: e => r("POST", e), put: e => r("PUT", e), patch: e => r("PATCH", e), delete: e => r("DELETE", e), head: e => r("HEAD", e), options: e => r("OPTIONS", e) } } function MagicData(d, p) { let g = { fs: void 0, data: {} }; if (d.isNode) { g.fs = require("fs"); try { g.fs.accessSync("./magic.json", g.fs.constants.R_OK | g.fs.constants.W_OK) } catch (e) { g.fs.writeFileSync("./magic.json", "{}", { encoding: "utf8" }) } g.data = require("./magic.json") } const s = (e, t) => "object" != typeof t && e === t, a = e => "true" === e || "false" !== e && (void 0 === e ? null : e), l = (e, t, r, n) => { if (r) try { e = !0 === (e = "string" == typeof e ? JSON.parse(e) : e).magic_session ? e[r] : null } catch { e = null } if ("string" == typeof e && "null" !== e) try { e = JSON.parse(e) } catch { } return null == (e = !1 === n && e && !0 === e.magic_session ? null : e) && null != t && (e = t), e = a(e) }, f = t => { if ("string" != typeof t) return t instanceof Array || null == t || t != t || "boolean" == typeof t ? {} : t; { let e = {}; try { var r = typeof (e = JSON.parse(t)); ("object" != r || e instanceof Array || "bool" == r || null === e) && (e = {}) } catch { } return e } }, u = (e, t = null, r = "", n = !1, o = null) => { let i = ""; return i = o || d.isNode ? ((e, t = null, r = "", n = !1, o = null) => { o = o || g.data; return val = o && void 0 !== o[e] && null !== o[e] ? o[e] : r ? {} : null, val = l(val, t, r, n) })(e, t, r, n, o) : (d.isSurgeLike ? i = $persistentStore.read(e) : d.isQuanX && (i = $prefs.valueForKey(e)), l(i, t, r, n)), p.debug(`READ DATA [${e}]${r ? `[${r}]` : ""} <${typeof i}>` + "\n" + JSON.stringify(i)), i }, c = (e, t, r = "", n = null) => { if (void 0 === t || t != t) return !1; d.isNode || "boolean" != typeof t && "number" != typeof t || (t = String(t)); let o = ""; var i, s, a, l, u, c; if (n || d.isNode ? o = ([i, s, a = "", l = null] = [e, t, r, n], c = l || g.data, c = f(c), a ? ((u = f(c[i])).magic_session = !0, u[a] = s, c[i] = u) : c[i] = s, null !== l && (l = c), c) : r ? (d.isSurgeLike ? o = $persistentStore.read(e) ? $persistentStore.read(e) : o : d.isQuanX && (o = $prefs.valueForKey(e) ? $prefs.valueForKey(e) : o), (o = f(o)).magic_session = !0, o[r] = t) : o = t, o && "object" == typeof o && (o = JSON.stringify(o, null, 4)), p.debug(`WRITE DATA [${e}]${r ? `[${r}]` : ""} <${typeof t}>` + "\n" + JSON.stringify(t)), !n) { if (d.isSurgeLike) return $persistentStore.write(o, e); if (d.isQuanX) return $prefs.setValueForKey(o, e); if (d.isNode) try { g.fs.writeFileSync("./magic.json", o) } catch (e) { return p.error(e), !1 } } return !0 }; return { read: u, write: c, del: (e, t = "", r = null) => { let n = {}; if (r || d.isNode) n = (o = e, i = t, s = r || g.data, s = f(s), i ? (delete (obj = f(s[o]))[i], s[o] = obj) : delete s[o], s), r ? r = n : g.fs.writeFileSync("./magic.json", JSON.stringify(n, null, 4)); else if (t) { d.isSurgeLike ? n = $persistentStore.read(e) : d.isQuanX && (n = $prefs.valueForKey(e)), delete (n = f(n))[t]; i = JSON.stringify(n, null, 4); c(e, i) } else { if (d.isStorm) return $persistentStore.remove(e); if (d.isSurgeLike) return $persistentStore.write(null, e); if (d.isQuanX) return $prefs.removeValueForKey(e) } var o, i, s; p.debug(`DELETE KEY [${e}]` + (t ? `[${t}]` : "")) }, update: (e, t, r, n = s, o = null) => { var i; return t = a(t), !0 !== n(u(e, null, r, !1, o), t) && (i = c(e, t, r, o), e = u(e, null, r, !1, o), n === s && "object" == typeof e ? i : n(t, e)) }, allSessions: (e, t = null) => { let r = {}; t = u(e, null, null, !0, t); return !0 === (t = f(t)).magic_session && delete (r = { ...t }).magic_session, p.debug(`READ ALL SESSIONS [${e}] <${typeof r}>` + "\n" + JSON.stringify(r, null, 4)), r }, allSessionNames: (e, t = null) => { let r = []; t = u(e, null, null, !0, t), t = f(t); return r = !0 !== t.magic_session ? [] : Object.keys(t).filter(e => "magic_session" !== e), p.debug(`READ ALL SESSIONS [${e}] <${typeof r}>` + "\n" + JSON.stringify(r, null, 4)), r }, defaultValueComparator: s, convertToObject: f } } function MagicNotification(i, o, s, a) { let l = null, u = null, c = []; function d(e = i, t = "", r = "", n = "") { n = (t => { try { let e = {}; var r; return "string" == typeof t ? 0 < t.length && (o.isLoon ? e = { openUrl: t } : o.isQuanX ? e = { "open-url": t } : o.isSurge && (e = { url: t })) : "object" == typeof t && (o.isLoon ? (e.openUrl = t["open-url"] || "", e.mediaUrl = t["media-url"] || "") : o.isQuanX ? e = t["open-url"] || t["media-url"] ? t : {} : o.isSurge && (r = t["open-url"] || t.openUrl, e = r ? { url: r } : {})), e } catch (e) { s.error("通知选项转换失败" + e) } return t })(n), 1 === arguments.length && (e = i, t = "", r = arguments[0]), s.notify("\ntitle:" + e + "\nsubTitle:" + t + "\nbody:" + r + "\noptions:" + ("object" == typeof n ? JSON.stringify(n) : n)), o.isSurge ? $notification.post(e, t, r, n) : o.isLoon ? n ? $notification.post(e, t, r, n) : $notification.post(e, t, r) : o.isQuanX && $notify(e, t, r, n), l && u && p(e, t, r) } function p(e = i, t = "", r = "", n) { if (void 0 === a || void 0 === a.post) throw "Bark notification needs to import MagicHttp module."; e = { url: l, headers: { "content-type": "application/json; charset=utf-8" }, body: { title: e, body: t ? t + "\n" + r : r, device_key: u } }; a.post(e).catch(e => { s.error("Bark notify error: " + e) }) } return { post: d, debug: function (e = i, t = "", r = "", n = "") { "DEBUG" === s.getLevel() && (1 === arguments.length && (e = i, t = "", r = arguments[0]), this.post(e, t, r, n)) }, bark: p, setBark: e => { try { var t = e.replace(/\/+$/g, ""); l = /^https?:\/\/([^/]*)/.exec(t)[0] + "/push", u = /\/([^\/]+)\/?$/.exec(t)[1] } catch (e) { s.error(`Bark url error: ${e}.`) } }, appendNotifyInfo: function (e, t) { 1 == t ? c = e : c.push(e) }, prependNotifyInfo: function (e) { c.splice(0, 0, e) }, msg: function (e, t, r, n) { var o = {}; r && (o["open-url"] = r), n && (o["media-url"] = n), (t = t && 0 != t.length ? t : Array.isArray(c) ? c.join("\n") : c) && 0 < t.length && d(i, "", t, o) } } } function MagicUtils(n, u) { const e = (e, t = "yyyy-MM-dd hh:mm:ss") => { var r, n = { "M+": e.getMonth() + 1, "d+": e.getDate(), "h+": e.getHours(), "m+": e.getMinutes(), "s+": e.getSeconds(), "q+": Math.floor((e.getMonth() + 3) / 3), S: e.getMilliseconds() }; for (r in /(y+)/.test(t) && (t = t.replace(RegExp.$1, (e.getFullYear() + "").substr(4 - RegExp.$1.length))), n) new RegExp("(" + r + ")").test(t) && (t = t.replace(RegExp.$1, 1 === RegExp.$1.length ? n[r] : ("00" + n[r]).substr(("" + n[r]).length))); return t }; return { retry: (i, s = 5, a = 0, l = null) => (...e) => new Promise((r, n) => { function o(...t) { Promise.resolve().then(() => i.apply(this, t)).then(e => { "function" == typeof l ? Promise.resolve().then(() => l(e)).then(() => { r(e) }).catch(e => { 1 <= s ? 0 < a ? setTimeout(() => o.apply(this, t), a) : o.apply(this, t) : n(e), s-- }) : r(e) }).catch(e => { u.error(e), 1 <= s && 0 < a ? setTimeout(() => o.apply(this, t), a) : 1 <= s ? o.apply(this, t) : n(e), s-- }) } o.apply(this, e) }), formatTime: e, now: () => e(new Date, "yyyy-MM-dd hh:mm:ss"), today: () => e(new Date, "yyyy-MM-dd"), sleep: t => new Promise(e => setTimeout(e, t)), assert: (e, t = null) => { var r; n.isNode ? (r = require("assert"), t ? r(e, t) : r(e)) : !0 !== e && u.error("AssertionError: " + (t || "The expression evaluated to a falsy value.")) } } } function MagicQingLong(e, a, o) { let i = "", s = "", l = "", u = "", c = "", t = ""; const d = "magic.json", p = MagicHttp(e, o); async function r() { return l = l || a.read("magic_qlclient"), u = u || a.read("magic_qlsecrt"), s = s || a.read("magic_qlname"), c = c || a.read("magic_qlpwd"), i && l && u ? (o.info("Get token from QingLong Panel"), await p.get({ url: "/open/auth/token", headers: { "content-type": "application/json" }, params: { client_id: l, client_secret: u } }).then(e => { if (!(0 < Object.keys(e.body).length && e.body.data && e.body.data.token)) throw new Error("Get QingLong Panel token failed."); o.info("Successfully logged in to QingLong Panel"), t = e.body.data.token, a.write("magic_qltoken", t) }).catch(e => { o.error("Error logging in to QingLong Panel.\n" + (e.message || e)) })) : i && s && c && await p.post({ url: "/api/user/login", headers: { "content-type": "application/json" }, body: { username: s, password: c } }).then(e => { o.info("Successfully logged in to QingLong Panel"), t = e.body.data.token, a.write("magic_qltoken", t) }).catch(e => { o.error("Error logging in to QingLong Panel.\n" + (e.message || e)) }), t } async function g(e) { let t = []; return await p.post({ url: "/api/envs", headers: { "content-type": "application/json" }, body: e }).then(e => { 200 === e.body.code ? e.body.data.forEach(e => { o.debug(`QINGLONG ADD ENV ${e.name} <${typeof e.value}> (${e.id})` + "\n" + JSON.stringify(e)), t.push(e.id) }) : o.error("Error adding environments variable from QingLong Panel.\n" + JSON.stringify(e)) }).catch(e => { o.error("Error adding environments variable from QingLong Panel.\n" + (e.message || e)) }), t } async function n(n = null, e = "", t) { let o = []; return await p.get({ url: "/api/envs", headers: { "content-type": "application/json" }, params: { searchValue: e } }).then(e => { if (200 !== e.body.code) throw new Error("Error reading environment variable from QingLong Panel.\n" + JSON.stringify(e)); e = e.body.data; if (n) { var t = []; for (const r of e) r.name === n && o.push(r); o = t } o = e }).catch(e => { throw new Error("Error reading environments variable from QingLong Panel.\n" + (e.message || e)) }), o } async function f(e, t = "") { let r = ""; return await p.get({ url: "/api/scripts/" + e, params: { path: t } }).then(e => { if (200 !== e.body.code) throw new Error("Error reading data from QingLong Panel.\n" + JSON.stringify(e)); r = e.body.data }).catch(e => { throw new Error("Error reading data from QingLong Panel.\n" + (e.message || e)) }), r } async function h(e, t = "", r = "") { let n = !1; return await p.put({ url: "/api/scripts", headers: { "content-type": "application/json" }, body: { filename: e, path: t, content: r } }).then(e => { 200 === e.body.code ? n = !0 : o.error("Error reading data from QingLong Panel.\n" + JSON.stringify(e)) }).catch(e => { o.error("Error reading data from QingLong Panel.\n" + (e.message || e)) }), n } return p.interceptors.request.use(function (e) { return i = i || a.read("magic_qlurl"), e.url.indexOf(i) < 0 && (e.url = "" + i + e.url), { ...e, timeout: 3e3 } }, void 0), p.interceptors.request.use(function (e) { return (l = l || a.read("magic_qlclient")) && (e.url = e.url.replace("/api/", "/open/")), e }, void 0, { runWhen: e => e.url.indexOf("api/user/login") < 0 && e.url.indexOf("open/auth/token") < 0 }), p.interceptors.request.use(async function (e) { return (t = t || a.read("magic_qltoken", "")) || await r(), e.headers.authorization = "Bearer " + t, e }, void 0, { runWhen: e => e.url.indexOf("api/user/login") < 0 && e.url.indexOf("open/auth/token") < 0 }), p.interceptors.request.use(function (e) { return e.params = { ...e.params, t: Date.now() }, e }, void 0, { runWhen: e => e.url.indexOf("open/auth/token") < 0 }), p.interceptors.request.use(function (e) { return i = i || a.read("magic_qlurl"), t = t || a.read("magic_qltoken"), o.debug("QingLong url: " + i + "\nQingLong token: " + t), e }, void 0), p.interceptors.response.use(void 0, async function (e) { try { var t = e.message || e.error || JSON.stringify(e); return (0 <= t.indexOf("NSURLErrorDomain") && 0 <= t.indexOf("-1012") || e.response && 401 === e.response.status) && e.config && !0 !== e.config.refreshToken ? (o.warning("QingLong Panel token has expired"), o.info("Refreshing the QingLong Panel token"), await r(), e.config.refreshToken = !0, o.info("Call the previous method again"), await p.request(e.config.method, e.config)) : Promise.reject(e) } catch (e) { return Promise.reject(e) } }), { url: i || a.read("magic_qlurl"), init: (e, t, r, n, o) => { i = e, l = t, u = r, s = n, c = o }, getToken: r, setEnv: async function (t, r, n = null) { if (i = i || a.read("magic_qlurl"), null === n) { var e = await g([{ name: t, value: r }]); if (e && 1 === e.length) return e[0] } else await p.put({ url: "/api/envs", headers: { "content-type": "application/json" }, body: { name: t, value: r, id: n } }).then(e => { if (200 === e.body.code) return o.debug(`QINGLONG UPDATE ENV ${t} <${typeof r}> (${n})` + "\n" + JSON.stringify(r)), !0; o.error("Error adding environment variable from QingLong Panel.\n" + JSON.stringify(e)) }).catch(e => (o.error("Error adding environment variable from QingLong Panel.\n" + (e.message || e)), !1)) }, setEnvs: g, getEnv: async function (e) { let t = null; for (const r of await n()) if (r.id === e) { t = r; break } return t }, getEnvs: n, delEnvs: async function (t) { return p.delete({ url: "/api/envs", headers: { accept: "application/json", "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6", connection: "keep-alive", "content-type": "application/json;charset=UTF-8", "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36 Edg/102.0.1245.30" }, body: t }).then(e => 200 === e.body.code ? (o.debug("QINGLONG DELETE ENV IDS: " + t), !0) : (o.error("Error deleting environments variable from QingLong Panel.\n" + JSON.stringify(e)), !1)).catch(e => { o.error("Error deleting environments variable from QingLong Panel.\n" + (e.message || e)) }) }, disableEnvs: async function (t) { let r = !1; return await p.put({ url: "/api/envs/disable", headers: { accept: "application/json", "accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6", connection: "keep-alive", "content-type": "application/json;charset=UTF-8", "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36 Edg/102.0.1245.30" }, body: t }).then(e => { 200 === e.body.code ? (o.debug("QINGLONG DISABLED ENV IDS: " + t), r = !0) : o.error("Error disabling environments variable from QingLong Panel.\n" + JSON.stringify(e)) }).catch(e => { o.error("Error disabling environments variable from QingLong Panel.\n" + (e.message || e)) }), r }, enableEnvs: async function (t) { let r = !1; return await p.put({ url: "/api/envs/enable", headers: { accept: "application/json", "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6", connection: "keep-alive", "content-type": "application/json;charset=UTF-8", "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36 Edg/102.0.1245.30" }, body: t }).then(e => { 200 === e.body.code ? (o.debug("QINGLONG ENABLED ENV IDS: " + t), r = !0) : o.error("Error enabling environments variable from Qilong panel.\n" + JSON.stringify(e)) }).catch(e => { o.error("Error enabling environments variable from Qilong panel.\n" + (e.message || e)) }), r }, addScript: async function (e, t = "", r = "") { let n = !1; return await p.post({ url: "/api/scripts", headers: { "content-type": "application/json" }, body: { filename: e, path: t, content: r } }).then(e => { 200 === e.body.code ? n = !0 : o.error("Error reading data from QingLong Panel.\n" + JSON.stringify(e)) }).catch(e => { o.error("Error reading data from QingLong Panel.\n" + (e.message || e)) }), n }, getScript: f, editScript: h, delScript: async function (e, t = "") { let r = !1; return await p.delete({ url: "/api/scripts", headers: { "content-type": "application/json" }, body: { filename: e, path: t } }).then(e => { 200 === e.body.code ? r = !0 : o.error("Error reading data from QingLong Panel.\n" + JSON.stringify(e)) }).catch(e => { o.error("Error reading data from QingLong Panel.\n" + (e.message || e)) }), r }, write: async function (e, t, r = "") { var n = await f(d, ""), o = a.convertToObject(n), e = a.write(e, t, r, o), n = JSON.stringify(o, null, 4); return await h(d, "", n) && e }, read: async function (e, t, r = "", n = !1) { var o = await f(d, ""), o = a.convertToObject(o); return a.read(e, t, r, n, o) }, del: async function (e, t = "") { var r = await f(d, ""), n = a.convertToObject(r), e = a.del(e, t, n), r = JSON.stringify(n, null, 4), t = await h(d, "", r); return e && t }, update: async function (e, t, r, n = a.defaultValueComparator) { var o = await f(d, ""), i = a.convertToObject(o), e = a.update(e, t, r, n, i); let s = !1; return !0 === e && (o = JSON.stringify(i, null, 4), s = await h(d, "", o)), e && s }, batchWrite: async function (...e) { var t, r = await f(d, ""), n = a.convertToObject(r); for (t of e) a.write(t[0], t[1], void 0 !== t[2] ? t[2] : "", n); return r = JSON.stringify(n, null, 4), h(d, "", r) }, batchRead: async function (...e) { var t, r = await f(d, ""), n = a.convertToObject(r), o = []; for (t of e) { var i = a.read(t[0], t[1], void 0 !== t[2] ? t[2] : "", "boolean" == typeof t[3] && t[3], n); o.push(i) } return o }, batchUpdate: async function (...e) { var t, r = await f(d, ""), n = a.convertToObject(r); for (t of e) a.update(t[0], t[1], void 0 !== t[2] ? t[2] : "", void 0 !== t[3] ? t.comparator : a.defaultValueComparator, n); return r = JSON.stringify(n, null, 4), h(d, "", r) }, batchDel: async function (...e) { var t, r = await f(d, ""), n = a.convertToObject(r); for (t of e) a.del(t[0], void 0 !== t[1] ? t[1] : "", n); return r = JSON.stringify(n, null, 4), h(d, "", r) }, allSessions: async function (e) { var t = await f(d, ""), t = a.convertToObject(t); return a.allSessions(e, t) }, allSessionNames: async function (e) { var t = await f(d, ""), t = a.convertToObject(t); return a.allSessionNames(e, t) } } }
  788. //---SyncByPyScript---MagicJS3-end