diff --git a/jd/moving_env_enhance.js b/jd/moving_env_enhance.js new file mode 100644 index 0000000..c2179a7 --- /dev/null +++ b/jd/moving_env_enhance.js @@ -0,0 +1,71 @@ +/** + * cron: 59 23 *\/3 * * + * + * 京东Cookie辅助脚本(将JD CK进行重排序 保证所有账号都有助力与被助力的机会) + */ +const { Env } = require('../common'); +const $ = new Env('京东Cookie辅助脚本(将JD CK进行重排序)'); +const fs = require('fs').promises; +const fetch = require('node-fetch'); +const envName = 'JD_COOKIE'; +const qlPanelUrl = 'https://ql.zhuhjay.cn'; + + +!(async () => { + let token = JSON.parse(await fs.readFile('/ql/data/config/auth.json', 'utf-8'))?.token; + if(!token) return $.log('未登录'); + const rsp1 = await fetch(`${qlPanelUrl}/api/envs?t=${Date.now()}`, { + "headers": { + "authorization": `Bearer ${token}`, + "content-type": 'application/json' + }, + "body": null, + "method": "GET", + }); + const { data } = await rsp1.json(); + let cks = data.map((item, idx) => { + return { + idx, + item + } + }).filter(d => d.item.name === envName && d.item.status === 0); + + // 将最后一个放置到最前 + let moveingCk = cks[cks.length - 1]; + let toIdx = 0; + const rsp2 = await fetch(`${qlPanelUrl}/api/envs/${moveingCk.item.id}/move?t=${Date.now()}`, { + "headers": { + "authorization": `Bearer ${token}`, + "content-type": 'application/json' + }, + "body": JSON.stringify({ + fromIndex: moveingCk.idx, + toIndex: toIdx + }), + "method": "PUT", + }); + await rsp2.json(); + + // 将 第一个 ck 移动到最后一个即可 + + // let moveingCk = cks[0]; + // let toIdx = cks[cks.length - 1].idx; + // const rsp2 = await fetch(`${qlPanelUrl}/api/envs/${moveingCk.item.id}/move?t=${Date.now()}`, { + // "headers": { + // "authorization": `Bearer ${token}`, + // "content-type": 'application/json' + // }, + // "body": JSON.stringify({ + // fromIndex: moveingCk.idx, + // toIndex: toIdx + // }), + // "method": "PUT", + // }); + // await rsp2.json(); +})() + .catch((e) => { + $.logErr(e); + }) + .finally(() => { + $.done(); + });