1 Star 1 Fork 1

Wl_Lnay/jd_scirpt_JDWXX

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ql.js 3.16 KB
一键复制 编辑 原始数据 按行查看 历史
Wl_Lnay 提交于 2022-02-09 15:46 . init
'use strict';
const got = require('got');
require('dotenv').config();
const { readFile } = require('fs/promises');
const path = require('path');
const qlDir = process.env.QL_DIR || '/ql';
const authFile = path.join(qlDir, 'config/auth.json');
const api = got.extend({
prefixUrl: process.env.QL_URL || 'http://localhost:5600',
retry: { limit: 0 },
});
async function getToken() {
const authConfig = JSON.parse(await readFile(authFile));
return authConfig.token;
}
module.exports.getEnvs = async () => {
const token = await getToken();
const body = await api({
url: 'api/envs',
searchParams: {
searchValue: 'JD_COOKIE',
t: Date.now(),
},
headers: {
Accept: 'application/json',
authorization: `Bearer ${token}`,
},
}).json();
return body.data;
};
module.exports.getEnvsCount = async () => {
const data = await this.getEnvs();
return data.length;
};
module.exports.addEnv = async (cookie, remarks) => {
const token = await getToken();
const body = await api({
method: 'post',
url: 'api/envs',
params: { t: Date.now() },
json: [{
name: 'JD_COOKIE',
value: cookie,
remarks,
}],
headers: {
Accept: 'application/json',
authorization: `Bearer ${token}`,
'Content-Type': 'application/json;charset=UTF-8',
},
}).json();
return body;
};
module.exports.updateEnv = async (cookie, eid, remarks) => {
const token = await getToken();
const body = await api({
method: 'put',
url: 'api/envs',
params: { t: Date.now() },
json: {
name: 'JD_COOKIE',
value: cookie,
_id: eid,
remarks,
},
headers: {
Accept: 'application/json',
authorization: `Bearer ${token}`,
'Content-Type': 'application/json;charset=UTF-8',
},
}).json();
return body;
};
module.exports.DisableCk = async (eid) => {
const token = await getToken();
const body = await api({
method: 'put',
url: 'api/envs/disable',
params: { t: Date.now() },
body: JSON.stringify([eid]),
headers: {
Accept: 'application/json',
authorization: `Bearer ${token}`,
'Content-Type': 'application/json;charset=UTF-8',
},
}).json();
return body;
};
module.exports.EnableCk = async (eid) => {
const token = await getToken();
const body = await api({
method: 'put',
url: 'api/envs/enable',
params: { t: Date.now() },
body: JSON.stringify([eid]),
headers: {
Accept: 'application/json',
authorization: `Bearer ${token}`,
'Content-Type': 'application/json;charset=UTF-8',
},
}).json();
return body;
};
module.exports.getstatus = async (eid) => {
const envs = await this.getEnvs();
for (let i = 0; i < envs.length; i++) {
if(envs[i]._id==eid){
return envs[i].status;
}
}
return 99;
};
module.exports.delEnv = async (eid) => {
const token = await getToken();
const body = await api({
method: 'delete',
url: 'api/envs',
params: { t: Date.now() },
body: JSON.stringify([eid]),
headers: {
Accept: 'application/json',
authorization: `Bearer ${token}`,
'Content-Type': 'application/json;charset=UTF-8',
},
}).json();
return body;
};
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/wulang_7895409/jd_scirpt_JDWXX.git
git@gitee.com:wulang_7895409/jd_scirpt_JDWXX.git
wulang_7895409
jd_scirpt_JDWXX
jd_scirpt_JDWXX
master

搜索帮助