Files
ql-scripts/jd/moving_env_enhance.js
zhuhjay 6d5e28bcf3 feat(jd): 添加京东CK重排序脚本
- 实现了京东Cookie的自动重排序功能
- 通过QL面板API获取并操作环境变量
- 支持将指定CK移动到指定位置
- 添加了对CK状态的过滤处理
- 集成了错误处理和日志记录机制
- 配置了定时执行的cron表达式
2025-11-02 17:41:47 +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();
});