nenMoScript.js 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053
  1. /*
  2. 嫩模助手
  3. [Script]
  4. # > 嫩模助手
  5. ^https?:\/\/mo\.10coo\.com url script-request-body https://git.jojo21.top/shawenguan/Quantumult-X/raw/master/Scripts/mangguo/nenMoScript.js
  6. ^https?:\/\/mo\.10coo\.com url script-response-body https://git.jojo21.top/shawenguan/Quantumult-X/raw/master/Scripts/mangguo/nenMoScript.js
  7. [MITM]
  8. hostname = mo.10coo.com
  9. */
  10. const scriptName = `嫩模助手`;
  11. const magicJS = MagicJS(scriptName, "INFO");
  12. const MoConstKey = {
  13. Cookie: `mo_cookie`,
  14. };
  15. const gUserAgent = `Mozilla/5.0 (iPhone; CPU iPhone OS 16_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1`;
  16. const gHost = `mo.10coo.com`;
  17. const gCommonHeaders = {
  18. 'X-Requested-With': `XMLHttpRequest`,
  19. 'Sec-Fetch-Dest': `empty`,
  20. 'Connection': `keep-alive`,
  21. 'Accept-Encoding': `gzip, deflate, br`,
  22. 'Content-Type': `application/x-www-form-urlencoded`,
  23. 'Sec-Fetch-Site': `same-origin`,
  24. 'Origin': `https://mo.10coo.com`,
  25. 'User-Agent': gUserAgent,
  26. 'Sec-Fetch-Mode': `cors`,
  27. 'Host': gHost,
  28. 'Cookie': ``,
  29. 'Referer': `https://mo.10coo.com/`,
  30. 'Accept-Language': `zh-CN,zh-Hans;q=0.9`,
  31. 'Accept': `*/*`
  32. };
  33. let gRetBody;
  34. async function Main() {
  35. if (magicJS.isStrictRequest) {
  36. magicJS.checkRecordRequestBody();
  37. }
  38. if (magicJS.isRequest) {
  39. checkHandleRequest();
  40. } else {
  41. updateHeaders();
  42. await tryExecuteAfkTask();
  43. }
  44. magicJS.notification.msg('');
  45. if (gRetBody) {
  46. magicJS.done({
  47. body: JSON.stringify(gRetBody)
  48. });
  49. } else {
  50. magicJS.done();
  51. }
  52. }
  53. function checkHandleRequest() {
  54. const url = $request.url;
  55. const path = $request.path;
  56. magicJS.logger.info(`请求url=${url}#${$request.method}`);
  57. magicJS.logger.info(`请求body=${magicJS.getRequestBody()}`);
  58. if ($request && $request.method != 'OPTIONS') {
  59. switch (path) {
  60. case '/goLogin':
  61. handleLogin();
  62. break;
  63. case '/getConfig':
  64. handleConfig();
  65. break;
  66. case '/order/queryToBePaidStatusOrderList':
  67. break;
  68. case '/preStartTask':
  69. handlePreStartTask();
  70. break;
  71. case '/order/dashboard':
  72. handleOrderDashBoard();
  73. break;
  74. case '/order/list':
  75. handleOrderList();
  76. break;
  77. default:
  78. if (path.indexOf('/listValidXmAccount') != -1) {
  79. handleListValidXmAccount();
  80. }
  81. break;
  82. }
  83. }
  84. }
  85. function handleHeaders() {
  86. if ($request && $request.method != 'OPTIONS') {
  87. let headers = $request.headers;
  88. let newCookieStr = headers['Cookie'];
  89. let oldCookieStr = magicJS.data.read(MoConstKey.Cookie, null);
  90. if (oldCookieStr != newCookieStr) {
  91. magicJS.logger.info(`当前Cookie刷新到最新`);
  92. magicJS.notification.appendNotifyInfo(`🎉当前Cookie刷新到最新`);
  93. } else {
  94. magicJS.logger.info(`当前Cookie已经是最新无需更新`);
  95. }
  96. magicJS.data.write(MoConstKey.Cookie, newCookieStr);
  97. }
  98. }
  99. function updateHeaders() {
  100. let cookieStr = magicJS.data.read(MoConstKey.Cookie, ``);
  101. gCommonHeaders['Cookie'] = cookieStr;
  102. }
  103. function getResponsePlainData() {
  104. let data = magicJS.getResponseBody();
  105. if (!data) {
  106. return;
  107. }
  108. try {
  109. return JSON.parse(data);
  110. } catch (err) {
  111. magicJS.logger.error(err);
  112. }
  113. }
  114. function getRequestPlainData() {
  115. let data = magicJS.getRequestBody();
  116. let reqData = null;
  117. if (data) {
  118. reqData = magicJS.parseQueryStr(data);
  119. } else {
  120. reqData = magicJS.parseQueryStr($request.url);
  121. }
  122. return reqData;
  123. }
  124. function handleLogin() {
  125. let rspData = getResponsePlainData();
  126. if (!rspData) {
  127. return;
  128. }
  129. if (rspData.code != 0) {
  130. return;
  131. }
  132. }
  133. function handleConfig() {
  134. let rspData = getResponsePlainData();
  135. if (!rspData) {
  136. return;
  137. }
  138. if (rspData.code != 0) {
  139. return;
  140. }
  141. handleHeaders();
  142. }
  143. function handleListValidXmAccount() {
  144. let rspData = getResponsePlainData();
  145. if (!rspData) {
  146. return;
  147. }
  148. if (rspData.code != 0) {
  149. return;
  150. }
  151. handleHeaders();
  152. }
  153. function handlePreStartTask() {
  154. let rspData = getResponsePlainData();
  155. if (!rspData) {
  156. return;
  157. }
  158. rspData.code = 0;
  159. gRetBody = rspData;
  160. }
  161. function handleOrderDashBoard() {
  162. let rspData = getResponsePlainData();
  163. if (!rspData) {
  164. return;
  165. }
  166. if (rspData.code != 0) {
  167. return;
  168. }
  169. handleHeaders();
  170. }
  171. function handleOrderList() {
  172. let rspData = getResponsePlainData();
  173. if (!rspData) {
  174. return;
  175. }
  176. if (rspData.code != 0) {
  177. return;
  178. }
  179. handleHeaders();
  180. }
  181. async function tryExecuteAfkTask() {
  182. let needReLogin = false;
  183. let cookieStr = magicJS.data.read(MoConstKey.Cookie, ``);
  184. magicJS.logger.info(`cookieStr:${cookieStr}`);
  185. if (cookieStr && cookieStr.length > 0) {
  186. let cookieDict = magicJS.parseCookies(cookieStr);
  187. let jwtData = magicJS.parseJwt(cookieDict.au);
  188. // magicJS.logger.info(`token:${ookieDict.au}`);
  189. if (jwtData) {
  190. let payload = jwtData.payload;
  191. let expDate = new Date(payload.exp * 1000);
  192. let expTimeStr = magicJS.formatDate(expDate, 'yyyy-MM-dd HH:mm:ss');
  193. magicJS.logger.info(`token过期时间:${expTimeStr}`);
  194. if (Date.now() > expDate.getTime()) {
  195. needReLogin = true;
  196. }
  197. } else {
  198. needReLogin = true;
  199. }
  200. } else {
  201. needReLogin = true;
  202. }
  203. if (needReLogin) {
  204. return;
  205. }
  206. let username = '10191';
  207. let password = 'Sjojo510520';
  208. if (needReLogin) {
  209. let retLogin = await doLogin(username, password);
  210. if (!retLogin || retLogin.code != 0) {
  211. magicJS.logger.info(`登录失败!`);
  212. magicJS.notification.appendNotifyInfo(`登录失败!`);
  213. return;
  214. }
  215. }
  216. let retConfig = await getConfig();
  217. if (retConfig && retConfig.code == 4001) {//没有登录
  218. magicJS.logger.info(`没有登录,尝试重新登录`);
  219. let retLogin = await doLogin(username, password);
  220. if (!retLogin || retLogin.code != 0) {
  221. magicJS.logger.info(`登录失败!`);
  222. magicJS.notification.appendNotifyInfo(`登录失败!`);
  223. return;
  224. }
  225. retConfig = await getConfig();
  226. }
  227. if (!retConfig || retConfig.code != 0) {
  228. magicJS.logger.info(`获取配置数据失败,原因:${retConfig.message}`);
  229. magicJS.notification.appendNotifyInfo(`获取配置数据失败,原因:${retConfig.message}`);
  230. return;
  231. }
  232. let configData = retConfig.data;
  233. if (configData.hasNotice) {
  234. magicJS.notification.appendNotifyInfo(configData.noticeContent);
  235. }
  236. let monitorTip = ``;
  237. if (configData.runStatus == 1) {
  238. if (configData.maxQuantity && configData.maxQuantity > 0) {
  239. monitorTip = `${configData.occNodeNum}个账号正在监控中, 当前1号${configData.maxQuantity || 0}单`;
  240. } else {
  241. monitorTip = `${configData.occNodeNum}个账号正在监控中`;
  242. }
  243. magicJS.logger.info(monitorTip);
  244. magicJS.notification.appendNotifyInfo(monitorTip);
  245. } else {
  246. monitorTip = `当前未开启监控`;
  247. magicJS.logger.info(monitorTip);
  248. }
  249. if (configData.runStatus == 1 && configData.occNodeNum >= configData.xmNodeNum) {
  250. magicJS.logger.info(`正在检测是否存在待支付订单...`);
  251. await checkExistOrderNoPay();
  252. } else {
  253. magicJS.logger.info(`正在启动最大账号数监控任务...`);
  254. await checkAutoStartMonitorTask(configData);
  255. }
  256. }
  257. async function checkAutoStartMonitorTask(configData) {
  258. let retAccList = await listValidXmAccount();
  259. if (!retAccList || retAccList.code != 0) {
  260. magicJS.logger.info(`获取账号列表数据失败!`);
  261. magicJS.notification.appendNotifyInfo(`获取账号列表数据失败!`);
  262. return;
  263. }
  264. await checkAutoLoginTask();
  265. await checkAutoRefreshAddress();
  266. let accountList = retAccList.data;
  267. accountList.reverse();
  268. accountList.sort((a, b) => {
  269. return a.orderedQuantity - b.orderedQuantity;
  270. });
  271. magicJS.logger.info(`可用账号列表:\n` + JSON.stringify(accountList, null, 4));
  272. let taskAccIds = [];
  273. let maxTaskCount = configData.xmNodeNum || 3;
  274. let lastEndInex = Math.min(maxTaskCount, accountList.length);
  275. let startedLst = [];
  276. let willStartLst = [];
  277. let notLoingLst = [];
  278. for (let i = 0; i < lastEndInex; i++) {
  279. let accountInfo = accountList[i];
  280. if (accountInfo.realTimeStatus && accountInfo.oldLink != 1) {
  281. // oldLink: 选择了红色字体标记的账号,可能会没单,因为当前有这种账号最近下过单的老链接在,会被平台限购
  282. startedLst.push(accountInfo);
  283. } else {
  284. if (accountInfo.enable == 1 && (accountInfo.loginStatus != 1 && accountInfo.loginStatus != 2)) {
  285. // 未登录
  286. notLoingLst.push(accountInfo);
  287. }
  288. if (accountInfo.enable == 1 && accountInfo.loginStatus == 1) {
  289. // 已登录
  290. taskAccIds.push(accountInfo.id);
  291. willStartLst.push(accountInfo);
  292. }
  293. }
  294. }
  295. let msgTipsText = ``;
  296. if (taskAccIds.length > 0) {
  297. let retCheck = await preStartTask();
  298. if (!retCheck) {
  299. magicJS.notification.appendNotifyInfo(`任务启动环境检查失败!`);
  300. return;
  301. }
  302. if (retCheck) {
  303. if (retCheck.code == 0) {
  304. magicJS.logger.info(`任务启动环境检查成功!`);
  305. } else {
  306. magicJS.logger.info(retCheck.message);
  307. magicJS.notification.appendNotifyInfo(retCheck.message);
  308. return;
  309. }
  310. }
  311. let nowTimeStr = magicJS.formatDate(new Date(), 'HH:mm:ss');
  312. if (nowTimeStr >= configData.startTime && nowTimeStr <= configData.endTime) {
  313. let retStart = await startTask(taskAccIds);
  314. if (retStart && retStart.code == 0) {
  315. startedLst = startedLst.concat(willStartLst);
  316. let resData = retStart.data;
  317. let taskRetText = `启动监控任务结果概览:\n`;
  318. taskRetText += `新增:${resData.addCount}\n`;
  319. taskRetText += `关闭:${resData.closeCount}\n`;
  320. taskRetText += `失败:${resData.failCount}\n`;
  321. taskRetText += `现存账号数:${resData.occNodeNum}\n`;
  322. magicJS.logger.info(taskRetText);
  323. msgTipsText += taskRetText + '\n';
  324. }
  325. } else {
  326. msgTipsText += `当前时间不在运行时间段内,不执行任务!\n`;
  327. }
  328. }
  329. let retFastData = await getCommonFastTrackAccount();
  330. if (!retFastData || retFastData.code != 0) {
  331. magicJS.logger.info(`获取神秘空间账号列表数据失败!`);
  332. return;
  333. }
  334. let left = retFastData.data.left;
  335. if (left > 0) {
  336. let fastAccountIds = [];
  337. if (retFastData.data.account) {
  338. fastAccountIds = retFastData.data.account.split(',');
  339. }
  340. msgTipsText += `神秘空间剩余可用名额:${left},启动结果如下:\n`;
  341. for (let i = 0; i < startedLst.length; i++) {
  342. let accountInfo = startedLst[i];
  343. if (fastAccountIds.includes(accountInfo.xmAccount)) {
  344. continue;
  345. }
  346. let retSet = await setCommonFastTrackAccount(accountInfo.xmAccount);
  347. if (retSet && retSet.code == 0) {
  348. msgTipsText += `账号[${accountInfo.xmAccount}}]添加成功\n`;
  349. left -= 1;
  350. if (left <= 0) {
  351. break;
  352. }
  353. } else {
  354. msgTipsText += `账号[${accountInfo.xmAccount}}]添加失败\n`;
  355. }
  356. }
  357. }
  358. if (msgTipsText.length > 0) {
  359. magicJS.notification.appendNotifyInfo(msgTipsText);
  360. await doCustomWxpusherSend(`小芒嫩模助手监控任务开启`, msgTipsText, 'https://mo.10coo.com/');
  361. }
  362. }
  363. async function doLogin(username, password) {
  364. const url = `https://mo.10coo.com/goLogin`;
  365. const reqData = {
  366. username: username,
  367. password: password,
  368. };
  369. let headers = { ...gCommonHeaders };
  370. headers['Referer'] = `https://mo.10coo.com/login`;
  371. let options = {
  372. url: url,
  373. headers: headers,
  374. body: magicJS.objToQueryStr(reqData),
  375. };
  376. let result = await magicJS.http.post(options).then(response => {
  377. try {
  378. let rspData = response.body;
  379. if (rspData.code == 0) {
  380. let cookieSetStr = headers['Set-Cookie'];
  381. magicJS.data.write(MoConstKey.Cookie, cookieSetStr);
  382. updateHeaders();
  383. }
  384. magicJS.logger.info(`rspData=${JSON.stringify(rspData)}`);
  385. return rspData;
  386. } catch (e) {
  387. magicJS.logger.error(e);
  388. }
  389. }).catch(err => {
  390. const msg = `请求登录异常\n${JSON.stringify(err)}`;
  391. magicJS.logger.error(msg);
  392. });
  393. return result;
  394. }
  395. async function getConfig() {
  396. const url = `https://mo.10coo.com/getConfig`;
  397. let options = {
  398. url: url,
  399. headers: gCommonHeaders,
  400. body: ``,
  401. };
  402. let result = await magicJS.http.get(options).then(response => {
  403. try {
  404. let rspData = response.body;
  405. magicJS.logger.info(`rspData=${JSON.stringify(rspData)}`);
  406. return rspData;
  407. } catch (e) {
  408. magicJS.logger.error(e);
  409. }
  410. }).catch(err => {
  411. const msg = `请求配置信息异常\n${JSON.stringify(err)}`;
  412. magicJS.logger.error(msg);
  413. });
  414. return result;
  415. }
  416. async function listValidXmAccount(size = 500) {
  417. const url = `https://mo.10coo.com/listValidXmAccount?size=${size}`;
  418. let options = {
  419. url: url,
  420. headers: gCommonHeaders,
  421. body: ``,
  422. };
  423. let result = await magicJS.http.get(options).then(response => {
  424. try {
  425. let rspData = response.body;
  426. magicJS.logger.info(`rspData=${JSON.stringify(rspData)}`);
  427. return rspData;
  428. } catch (e) {
  429. magicJS.logger.error(e);
  430. }
  431. }).catch(err => {
  432. const msg = `请求账号列表异常\n${JSON.stringify(err)}`;
  433. magicJS.logger.error(msg);
  434. });
  435. return result;
  436. }
  437. async function preStartTask() {
  438. const url = `https://mo.10coo.com/preStartTask`;
  439. let options = {
  440. url: url,
  441. headers: gCommonHeaders,
  442. body: ``,
  443. };
  444. let result = await magicJS.http.get(options).then(response => {
  445. try {
  446. let rspData = response.body;
  447. magicJS.logger.info(`rspData=${JSON.stringify(rspData)}`);
  448. return rspData;
  449. } catch (e) {
  450. magicJS.logger.error(e);
  451. }
  452. }).catch(err => {
  453. const msg = `请求启动前检查异常\n${JSON.stringify(err)}`;
  454. magicJS.logger.error(msg);
  455. });
  456. return result;
  457. }
  458. async function startTask(ids) {
  459. const url = `https://mo.10coo.com/start?ids=${ids.join(',')}`;
  460. let options = {
  461. url: url,
  462. headers: gCommonHeaders,
  463. body: ``,
  464. };
  465. let result = await magicJS.http.get(options).then(response => {
  466. try {
  467. let rspData = response.body;
  468. magicJS.logger.info(`rspData=${JSON.stringify(rspData)}`);
  469. return rspData;
  470. } catch (e) {
  471. magicJS.logger.error(e);
  472. }
  473. }).catch(err => {
  474. const msg = `请求启动任务异常\n${JSON.stringify(err)}`;
  475. magicJS.logger.error(msg);
  476. });
  477. return result;
  478. }
  479. async function saveGroupAccountChild(groupId, idArray) {
  480. const url = `https://mo.10coo.com/saveGroupAccountChild`;
  481. let reqData = {
  482. groupId: groupId,
  483. xmAccountIds: idArray.join(','),
  484. };
  485. let options = {
  486. url: url,
  487. headers: gCommonHeaders,
  488. body: magicJS.objToQueryStr(reqData),
  489. };
  490. let result = await magicJS.http.post(options).then(response => {
  491. try {
  492. let rspData = response.body;
  493. magicJS.logger.info(`rspData=${JSON.stringify(rspData)}`);
  494. return rspData;
  495. } catch (e) {
  496. magicJS.logger.error(e);
  497. }
  498. }).catch(err => {
  499. const msg = `提交动态调整设置异常\n${JSON.stringify(err)}`;
  500. magicJS.logger.error(msg);
  501. });
  502. return result;
  503. }
  504. async function getCommonFastTrackAccount() {
  505. const url = `https://mo.10coo.com/getCommonFastTrackAccount`;
  506. let options = {
  507. url: url,
  508. headers: gCommonHeaders,
  509. body: ``,
  510. };
  511. let result = await magicJS.http.get(options).then(response => {
  512. try {
  513. let rspData = response.body;
  514. magicJS.logger.info(`rspData=${JSON.stringify(rspData)}`);
  515. return rspData;
  516. } catch (e) {
  517. magicJS.logger.error(e);
  518. }
  519. }).catch(err => {
  520. const msg = `请求神秘空间加速账号列表异常\n${JSON.stringify(err)}`;
  521. magicJS.logger.error(msg);
  522. });
  523. return result;
  524. }
  525. async function setCommonFastTrackAccount(account) {
  526. const url = `https://mo.10coo.com/setCommonFastTrackAccount`;
  527. let reqData = {
  528. account: account,
  529. };
  530. let options = {
  531. url: url,
  532. headers: gCommonHeaders,
  533. body: magicJS.objToQueryStr(reqData),
  534. };
  535. let result = await magicJS.http.post(options).then(response => {
  536. try {
  537. let rspData = response.body;
  538. magicJS.logger.info(`rspData=${JSON.stringify(rspData)}`);
  539. return rspData;
  540. } catch (e) {
  541. magicJS.logger.error(e);
  542. }
  543. }).catch(err => {
  544. const msg = `请求设置神秘空间加速账号异常\n${JSON.stringify(err)}`;
  545. magicJS.logger.error(msg);
  546. });
  547. return result;
  548. }
  549. async function checkAutoLoginTask() {
  550. let resData = await listXmAccount();
  551. if (!resData.data || !resData.code != 0) {
  552. return;
  553. }
  554. let list = resData.data.data;
  555. for (let i = 0; i < list.length; i++) {
  556. const item = list[i];
  557. if (item.loginStatus != 1 && item.loginStatus != 2) {// 1:已登录,2:登录中,其他:未登录
  558. let retAccInfo = await getXmAccount(item.id);
  559. if (retAccInfo.code == 0 && (retAccInfo.data.loginStatus != 1 && retAccInfo.data.loginStatus != 2)) {
  560. let retAdd = await addLoginTask(item.id);
  561. if (retAdd && retAdd.code == 0) {
  562. magicJS.logger.info(`账号[${item.xmAccount}]自动登录任务添加成功`);
  563. } else {
  564. magicJS.logger.info(`账号[${item.xmAccount}]自动登录任务添加失败`);
  565. }
  566. }
  567. }
  568. }
  569. }
  570. async function listXmAccount(page = 0, size = 500) {
  571. const url = `https://mo.10coo.com/listXmAccount`;
  572. let reqData = {
  573. page: page,
  574. size: size,
  575. };
  576. let options = {
  577. url: url,
  578. headers: gCommonHeaders,
  579. body: magicJS.objToQueryStr(reqData),
  580. };
  581. let result = await magicJS.http.post(options).then(response => {
  582. try {
  583. let rspData = response.body;
  584. magicJS.logger.info(`rspData=${JSON.stringify(rspData)}`);
  585. return rspData;
  586. } catch (e) {
  587. magicJS.logger.error(e);
  588. }
  589. }).catch(err => {
  590. const msg = `获取账号列表异常\n${JSON.stringify(err)}`;
  591. magicJS.logger.error(msg);
  592. });
  593. return result;
  594. }
  595. async function getXmAccount(id) {
  596. const url = `https://mo.10coo.com/getXmAccount`;
  597. let reqData = {
  598. id: id,
  599. };
  600. let options = {
  601. url: url,
  602. headers: gCommonHeaders,
  603. body: magicJS.objToQueryStr(reqData),
  604. };
  605. let result = await magicJS.http.post(options).then(response => {
  606. try {
  607. let rspData = response.body;
  608. magicJS.logger.info(`rspData=${JSON.stringify(rspData)}`);
  609. return rspData;
  610. } catch (e) {
  611. magicJS.logger.error(e);
  612. }
  613. }).catch(err => {
  614. const msg = `获取账号信息异常\n${JSON.stringify(err)}`;
  615. magicJS.logger.error(msg);
  616. });
  617. return result;
  618. }
  619. async function addLoginTask(id) {
  620. const url = `https://mo.10coo.com/addLoginTask`;
  621. let reqData = {
  622. id: id,
  623. };
  624. let options = {
  625. url: url,
  626. headers: gCommonHeaders,
  627. body: magicJS.objToQueryStr(reqData),
  628. };
  629. let result = await magicJS.http.post(options).then(response => {
  630. try {
  631. let rspData = response.body;
  632. magicJS.logger.info(`rspData=${JSON.stringify(rspData)}`);
  633. return rspData;
  634. } catch (e) {
  635. magicJS.logger.error(e);
  636. }
  637. }).catch(err => {
  638. const msg = `请求启动任务异常\n${JSON.stringify(err)}`;
  639. magicJS.logger.error(msg);
  640. });
  641. return result;
  642. }
  643. async function checkAutoRefreshAddress() {
  644. let resData = await listXmAccount();
  645. if (!resData.data || !resData.code != 0) {
  646. return;
  647. }
  648. let list = resData.data.data;
  649. for (let i = 0; i < list.length; i++) {
  650. const item = list[i];
  651. let retAccInfo = await getXmAccount(item.id);
  652. if (retAccInfo.code == 0 && (retAccInfo.data.enable == 1)) {
  653. let retChange = await doChangeAddress(retAccInfo);
  654. if (retChange && retChange.code == 0) {
  655. magicJS.logger.info(`账号[${item.xmAccount}]自动刷新地址成功`);
  656. } else {
  657. magicJS.logger.info(`账号[${item.xmAccount}]自动刷新地址失败`);
  658. }
  659. }
  660. }
  661. }
  662. async function doChangeAddress(accountInfo) {
  663. let id = accountInfo.id;
  664. let retAddress = await getAddress(id);
  665. if (!retAddress || retAddress.code != 0) {
  666. return false;
  667. }
  668. let addressId = accountInfo.addressId;
  669. let addressObj = JSON.parse(retAddress.data);
  670. let itemList = [];
  671. if (addressObj.code == 200) {
  672. itemList = addressObj.data || [];
  673. }
  674. let ret = null;
  675. let isUseNewAddress = false;
  676. if (itemList.length < 10 && Math.random() > 0.9) {
  677. isUseNewAddress = true;
  678. }
  679. if (isUseNewAddress) {
  680. let retRandAddrData = await getRandXmAddress(accountInfo.id);
  681. let retCreate = await createAddress(accountInfo.id, retRandAddrData);
  682. if (retCreate && retCreate.code == 0) {
  683. let createObj = JSON.parse(retCreate.data);
  684. if (createObj.code == 200) {
  685. ret = await setXmAddress(createObj.data);;
  686. }
  687. }
  688. } else {
  689. for (let i = 0; i < itemList.length; i++) {
  690. const itemInfo = itemList[i];
  691. if (itemInfo.address_id != addressId) {
  692. ret = await setXmAddress(itemInfo);
  693. break;
  694. }
  695. }
  696. }
  697. return ret;
  698. }
  699. async function getAddress(id) {
  700. const url = `https://mo.10coo.com/getAddress`;
  701. let reqData = {
  702. id: id,
  703. };
  704. let options = {
  705. url: url,
  706. headers: gCommonHeaders,
  707. body: magicJS.objToQueryStr(reqData),
  708. };
  709. let result = await magicJS.http.post(options).then(response => {
  710. try {
  711. let rspData = response.body;
  712. magicJS.logger.info(`rspData=${JSON.stringify(rspData)}`);
  713. return rspData;
  714. } catch (e) {
  715. magicJS.logger.error(e);
  716. }
  717. }).catch(err => {
  718. const msg = `获取地址异常\n${JSON.stringify(err)}`;
  719. magicJS.logger.error(msg);
  720. });
  721. return result;
  722. }
  723. async function setXmAddress(data) {
  724. const url = `https://mo.10coo.com/setXmAddress`;
  725. // 数据示例:
  726. // data = {
  727. // "address_id": 7496453,
  728. // "uuid": "0f2c12b8871c573ebf4a938fddc9a373",
  729. // "consignee": "孙芸思",
  730. // "province": "湖南省",
  731. // "city": "长沙市",
  732. // "district": "天心区",
  733. // "address": "芙蓉南路7号",
  734. // "mobile": "15575110716",
  735. // "is_default": 0,
  736. // "tag": ""
  737. // }
  738. let reqData = data;
  739. let options = {
  740. url: url,
  741. headers: gCommonHeaders,
  742. body: magicJS.objToQueryStr(reqData),
  743. };
  744. let result = await magicJS.http.post(options).then(response => {
  745. try {
  746. let rspData = response.body;
  747. magicJS.logger.info(`rspData=${JSON.stringify(rspData)}`);
  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 getRandXmAddress(id) {
  759. const url = `https://mo.10coo.com/getRandXmAddress?xmAccountId=${id}`;
  760. let options = {
  761. url: url,
  762. headers: gCommonHeaders,
  763. body: ``,
  764. };
  765. let result = await magicJS.http.get(options).then(response => {
  766. try {
  767. let rspData = response.body;
  768. magicJS.logger.info(`rspData=${JSON.stringify(rspData)}`);
  769. return rspData;
  770. } catch (e) {
  771. magicJS.logger.error(e);
  772. }
  773. }).catch(err => {
  774. const msg = `请求随机地址异常\n${JSON.stringify(err)}`;
  775. magicJS.logger.error(msg);
  776. });
  777. return result;
  778. }
  779. async function createAddress(xmAccountId, data) {
  780. const url = `https://mo.10coo.com/createAddress`;
  781. let reqData = {
  782. id: data.id,
  783. xmAccountId: xmAccountId,
  784. consignee: data.consignee,
  785. mobile: data.mobile,
  786. province: data.province,
  787. city: data.city,
  788. district: data.district,
  789. address: data.address,
  790. };
  791. let options = {
  792. url: url,
  793. headers: gCommonHeaders,
  794. body: magicJS.objToQueryStr(reqData),
  795. };
  796. let result = await magicJS.http.post(options).then(response => {
  797. try {
  798. let rspData = response.body;
  799. magicJS.logger.info(`rspData=${JSON.stringify(rspData)}`);
  800. return rspData;
  801. } catch (e) {
  802. magicJS.logger.error(e);
  803. }
  804. }).catch(err => {
  805. const msg = `创建地址异常\n${JSON.stringify(err)}`;
  806. magicJS.logger.error(msg);
  807. });
  808. return result;
  809. }
  810. /**
  811. * 编辑账号
  812. * @param {*} xmAccountId
  813. * @param {*} xmAccount 账号手机号
  814. * @param {*} xmPassword 账号密码-可编辑
  815. * @param {*} alias 别名-可编辑
  816. * @returns
  817. */
  818. async function editAccount(xmAccountId, xmAccount, xmPassword, alias) {
  819. const url = `https://mo.10coo.com/editAccount`;
  820. let reqData = {
  821. xmId: xmAccountId,
  822. xmAccount: xmAccount,
  823. xmPassword: xmPassword,
  824. alias: alias,
  825. };
  826. let options = {
  827. url: url,
  828. headers: gCommonHeaders,
  829. body: magicJS.objToQueryStr(reqData),
  830. };
  831. let result = await magicJS.http.post(options).then(response => {
  832. try {
  833. let rspData = response.body;
  834. magicJS.logger.info(`rspData=${JSON.stringify(rspData)}`);
  835. return rspData;
  836. } catch (e) {
  837. magicJS.logger.error(e);
  838. }
  839. }).catch(err => {
  840. const msg = `编辑账号异常\n${JSON.stringify(err)}`;
  841. magicJS.logger.error(msg);
  842. });
  843. return result;
  844. }
  845. function expireDateFormat(date) {
  846. if (!date) {
  847. return "未知";
  848. }
  849. let currentTime = new Date();
  850. // 获取订单时间
  851. let orderTime = new Date(date);
  852. // 将当前时间增加30分钟
  853. let expirationTime = new Date(orderTime.getTime() + 30 * 60 * 1000);
  854. // 计算剩余时间(以毫秒为单位)
  855. let remainingTime = expirationTime - currentTime;
  856. // 将剩余时间转换为分钟和秒数
  857. let remainingMinutes = Math.floor(remainingTime / 1000 / 60);
  858. let remainingSeconds = Math.floor((remainingTime / 1000) % 60);
  859. if (remainingSeconds < 0) {
  860. return "可能已过期";
  861. }
  862. // 输出剩余时间
  863. if (remainingMinutes === 0) {
  864. return remainingSeconds + "秒后过期";
  865. }
  866. return remainingMinutes + "分" + remainingSeconds + "秒后过期";
  867. }
  868. async function checkExistOrderNoPay() {
  869. let retOrderList = await queryToBePaidStatusOrderList();
  870. if (retOrderList && retOrderList.code == 0) {
  871. let msgTipsText = '';
  872. let nopayCount = 0;
  873. let orderList = retOrderList.data;
  874. for (let i = 0; i < orderList.length; i++) {
  875. let d = list[i];
  876. let orderId = d.id;
  877. let xmAccount = d.xmAccount;
  878. let alias = d.alias ? "(" + d.alias + ")" : "";
  879. let createDate = (d.orderTime ? Date(d.orderTime) : Date(d.createTime));
  880. let expireStr = (d.orderTime ? expireDateFormat(d.orderTime) : expireDateFormat(d.createTime));
  881. let goodsStr = d.goodsName + d.skuStr;
  882. let priceStr = `¥${d.amount}`;
  883. let payStatus = await doPayResultCheck(orderId);
  884. if (payStatus) {
  885. msgTipsText += `账号[${xmAccount}](${alias})下单的${goodsStr}(${priceStr})已付款,无需处理\n`;
  886. } else {
  887. msgTipsText += `账号[${xmAccount}](${alias})下单的${goodsStr}(${priceStr})未付款,请尽快去付款!过期时间:${expireStr}\n`;
  888. nopayCount += 1;
  889. }
  890. }
  891. magicJS.logger.info(msgTipsText);
  892. if (nopayCount > 0) {
  893. await doCustomWxpusherSend(`存在待付订单(${nopayCount})`, msgTipsText, 'https://mo.10coo.com/');
  894. }
  895. }
  896. }
  897. async function doCustomWxpusherSend(title, content, url = '') {
  898. let data = {
  899. appToken: "AT_7wDWqSoT8xpJCQqJtHpshKhw7kXc0XCW",
  900. content: content,// 这是主体内容
  901. summary: title,// 该参数可选,默认为 msg 的前10个字符
  902. contentType: 1,
  903. // topicIds: [32852],
  904. topicIds: [],
  905. uids: [
  906. "UID_6P4B00X6Zv8U2oKC0I2R09emxtqq"
  907. ],
  908. url: url,
  909. verifyPay: false,
  910. verifyPayType: 0,
  911. };
  912. return await magicJS.doWxpusherSend(data);
  913. }
  914. async function queryToBePaidStatusOrderList() {
  915. const url = `https://mo.10coo.com/order/queryToBePaidStatusOrderList`;
  916. let options = {
  917. url: url,
  918. headers: gCommonHeaders,
  919. body: ``,
  920. };
  921. let result = await magicJS.http.get(options).then(response => {
  922. try {
  923. let rspData = response.body;
  924. magicJS.logger.info(`rspData=${JSON.stringify(rspData)}`);
  925. return rspData;
  926. } catch (e) {
  927. magicJS.logger.error(e);
  928. }
  929. }).catch(err => {
  930. const msg = `请求等待付款订单列表异常\n${JSON.stringify(err)}`;
  931. magicJS.logger.error(msg);
  932. });
  933. return result;
  934. }
  935. async function doPayResultCheck(id) {
  936. let ret = await queryOfficialStatus(id);
  937. if (ret && ret.code == 0) {
  938. ret = await checkPayResult(id);
  939. return ret;
  940. }
  941. return false;
  942. }
  943. async function queryOfficialStatus(id) {
  944. const url = `https://mo.10coo.com/order/queryOfficialStatus?orderId=${id}`;
  945. let options = {
  946. url: url,
  947. headers: gCommonHeaders,
  948. body: ``,
  949. };
  950. let result = await magicJS.http.get(options).then(response => {
  951. try {
  952. let rspData = response.body;
  953. magicJS.logger.info(`rspData=${JSON.stringify(rspData)}`);
  954. return rspData;
  955. } catch (e) {
  956. magicJS.logger.error(e);
  957. }
  958. }).catch(err => {
  959. const msg = `检测支付结果异常\n${JSON.stringify(err)}`;
  960. magicJS.logger.error(msg);
  961. });
  962. return result;
  963. }
  964. async function checkPayResult(id) {
  965. const url = `https://mo.10coo.com/order/batchQueryOrderStatus?orderIds=${id}`;
  966. let options = {
  967. url: url,
  968. headers: gCommonHeaders,
  969. body: ``,
  970. };
  971. let result = await magicJS.http.get(options).then(response => {
  972. try {
  973. let rspData = response.body;
  974. magicJS.logger.info(`rspData=${JSON.stringify(rspData)}`);
  975. if (rspData.data[0][1] == 1 || rspData.data[0][1] == 2 || rspData.data[0][1] == 3 || rspData.data[0][1] == 4) {
  976. return true;
  977. } else if (rspData.data[0][1] == -3 || rspData.data[0][1] == 0) {
  978. magicJS.logger.info(`未检测到支付`);
  979. return false;
  980. }
  981. return false;
  982. } catch (e) {
  983. magicJS.logger.error(e);
  984. }
  985. }).catch(err => {
  986. const msg = `检测支付结果异常\n${JSON.stringify(err)}`;
  987. magicJS.logger.error(msg);
  988. });
  989. return result;
  990. }
  991. Main().catch((e) => magicJS.logger.log(`-\n ${e}`)).finally(() => magicJS.done());
  992. //---SyncByPyScript---MagicJS3-start
  993. 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) } } }
  994. //---SyncByPyScript---MagicJS3-end