From 4cb35f87c5c6bebe357650407400181aecd6a579 Mon Sep 17 00:00:00 2001 From: YYDS Date: Tue, 12 Apr 2022 15:51:07 +0800 Subject: [PATCH] update --- function/ql.js | 85 +++++++++++++++++++++++++++++++++++++++++--------- ql.js | 11 +++++-- 2 files changed, 79 insertions(+), 17 deletions(-) diff --git a/function/ql.js b/function/ql.js index db832c9..31e4883 100644 --- a/function/ql.js +++ b/function/ql.js @@ -6,10 +6,17 @@ const { readFile } = require('fs/promises'); const path = require('path'); const qlDir = '/ql'; -const authFile = path.join(qlDir, 'config/auth.json'); +const fs = require('fs'); +let Fileexists = fs.existsSync('/ql/data/config/auth.json'); +let authFile=""; +if (Fileexists) + authFile="/ql/data/config/auth.json" +else + authFile="/ql/config/auth.json" +//const authFile = path.join(qlDir, 'config/auth.json'); const api = got.extend({ - prefixUrl: 'http://localhost:5600', + prefixUrl: 'http://127.0.0.1:5600', retry: { limit: 0 }, }); @@ -18,7 +25,7 @@ async function getToken() { return authConfig.token; } -module.exports.getEnvs = async () => { +module.exports.getEnvs = async () => { const token = await getToken(); const body = await api({ url: 'api/envs', @@ -80,6 +87,27 @@ module.exports.updateEnv = async (cookie, eid, remarks) => { return body; }; +module.exports.updateEnv11 = 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({ @@ -112,21 +140,48 @@ module.exports.EnableCk = async (eid) => { 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.getstatus = async(eid) => { + const envs = await this.getEnvs(); + var tempid = 0; + for (let i = 0; i < envs.length; i++) { + tempid = 0; + if (envs[i]._id) { + tempid = envs[i]._id; + } + if (envs[i].id) { + tempid = envs[i].id; + } + if (tempid == eid) { + return envs[i].status; + } + } + return 99; }; -module.exports.getEnvById = async (eid) => { +module.exports.getEnvById = async(eid) => { + const envs = await this.getEnvs(); + var tempid = 0; + for (let i = 0; i < envs.length; i++) { + tempid = 0; + if (envs[i]._id) { + tempid = envs[i]._id; + } + if (envs[i].id) { + tempid = envs[i].id; + } + if (tempid == eid) { + return envs[i].value; + } + } + return ""; +}; + +module.exports.getEnvByPtPin = async (Ptpin) => { const envs = await this.getEnvs(); - for (let i = 0; i < envs.length; i++) { - if(envs[i]._id==eid){ - return envs[i].value; + for (let i = 0; i < envs.length; i++) { + var tempptpin = decodeURIComponent(envs[i].value.match(/pt_pin=([^; ]+)(?=;?)/) && envs[i].value.match(/pt_pin=([^; ]+)(?=;?)/)[1]); + if(tempptpin==Ptpin){ + return envs[i]; } } return ""; diff --git a/ql.js b/ql.js index 802d1a6..31e4883 100644 --- a/ql.js +++ b/ql.js @@ -6,7 +6,14 @@ const { readFile } = require('fs/promises'); const path = require('path'); const qlDir = '/ql'; -const authFile = path.join(qlDir, 'config/auth.json'); +const fs = require('fs'); +let Fileexists = fs.existsSync('/ql/data/config/auth.json'); +let authFile=""; +if (Fileexists) + authFile="/ql/data/config/auth.json" +else + authFile="/ql/config/auth.json" +//const authFile = path.join(qlDir, 'config/auth.json'); const api = got.extend({ prefixUrl: 'http://127.0.0.1:5600', @@ -18,7 +25,7 @@ async function getToken() { return authConfig.token; } -module.exports.getEnvs = async () => { +module.exports.getEnvs = async () => { const token = await getToken(); const body = await api({ url: 'api/envs',