Files
ql-scripts/jd/scrip_moving_env_enhance.js
zhuhjay 90f9ad9a5d chore(config): 更新开发脚本和文档说明
- 更新 README 中的快速开始指南,使用 ql repo 命令替代手动克隆步骤
- 移除旧的环境配置说明
- 添加新的订阅方式说明
2025-11-02 18:14:49 +08:00

72 lines
2.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 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();
});