mirror of
https://github.com/shufflewzc/faker2.git
synced 2025-06-28 19:05:08 +08:00
Compare commits
No commits in common. "405c8040b7cbed57b9e1f938a55965d124de7f71" and "0b2d8539364e4818aaece6d691536b462aad3bdd" have entirely different histories.
405c8040b7
...
0b2d853936
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
135
ql.js
135
ql.js
@ -1,6 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const got = require('got');
|
const got = require('got');
|
||||||
|
const sqlite3 = require('sqlite3').verbose();
|
||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
const { readFile } = require('fs/promises');
|
const { readFile } = require('fs/promises');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
@ -22,6 +23,8 @@ module.exports.getVersion = () => {
|
|||||||
Accept: 'application/json',
|
Accept: 'application/json',
|
||||||
},
|
},
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
|
//console.log('Response Status Code:', response.statusCode);
|
||||||
|
//console.log('Response Body:', response.body);
|
||||||
return response.body.data.version;
|
return response.body.data.version;
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.error('Error fetching version:', error.response ? error.response.body : error.message);
|
console.error('Error fetching version:', error.response ? error.response.body : error.message);
|
||||||
@ -34,19 +37,20 @@ let authFile = "";
|
|||||||
(function initialize() {
|
(function initialize() {
|
||||||
global.versionPromise = module.exports.getVersion();
|
global.versionPromise = module.exports.getVersion();
|
||||||
global.versionPromise.then(version => {
|
global.versionPromise.then(version => {
|
||||||
console.log('当前青龙版本:', version + "\n");
|
console.log('当前青龙版本:', version+"\n");
|
||||||
if (version) {
|
if (version >= '2.18.0') {
|
||||||
if (version >= '2.18.0') {
|
|
||||||
authFile = "/ql/data/db/keyv.sqlite";
|
authFile = "/ql/data/db/keyv.sqlite";
|
||||||
} else if (version < '2.12.0') {
|
|
||||||
authFile = "/ql/config/auth.json";
|
} else if(version < '2.12.0'){
|
||||||
} else {
|
|
||||||
authFile = "/ql/data/config/auth.json";
|
authFile = "/ql/config/auth.json";
|
||||||
}
|
|
||||||
} else {
|
}else {
|
||||||
// 当检测不到版本号时,采用 version < '2.12.0' 的操作
|
|
||||||
authFile = "/ql/config/auth.json";
|
authFile = "/ql/data/config/auth.json";
|
||||||
}
|
|
||||||
|
}
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.error('Error after initialization:', error);
|
console.error('Error after initialization:', error);
|
||||||
});
|
});
|
||||||
@ -55,11 +59,9 @@ let authFile = "";
|
|||||||
async function getAuthFile() {
|
async function getAuthFile() {
|
||||||
await global.versionPromise;
|
await global.versionPromise;
|
||||||
return authFile;
|
return authFile;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getTokenFromSqlite(dbPath) {
|
async function getTokenFromSqlite(dbPath) {
|
||||||
const sqlite3 = require('sqlite3').verbose();
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const db = new sqlite3.Database(dbPath, (err) => {
|
const db = new sqlite3.Database(dbPath, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -103,17 +105,24 @@ async function getTokenFromSqlite(dbPath) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getToken() {
|
async function getToken() {
|
||||||
const authFilePath = await getAuthFile();
|
|
||||||
if (authFilePath.endsWith('keyv.sqlite')) {
|
|
||||||
return getTokenFromSqlite(authFilePath);
|
|
||||||
} else {
|
|
||||||
const authConfig = JSON.parse(await readFile(authFilePath));
|
|
||||||
return authConfig.token;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports.getEnvs = async () => {
|
const authFilePath = await getAuthFile();
|
||||||
|
if (authFilePath.endsWith('keyv.sqlite')) {
|
||||||
|
|
||||||
|
return getTokenFromSqlite(authFilePath);
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
const authConfig = JSON.parse(await readFile(authFilePath));
|
||||||
|
return authConfig.token;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.getEnvs = async () => {
|
||||||
const token = await getToken();
|
const token = await getToken();
|
||||||
|
//console.log('当前token:', token);
|
||||||
const body = await api({
|
const body = await api({
|
||||||
url: 'api/envs',
|
url: 'api/envs',
|
||||||
searchParams: {
|
searchParams: {
|
||||||
@ -200,7 +209,7 @@ module.exports.DisableCk = async (eid) => {
|
|||||||
const body = await api({
|
const body = await api({
|
||||||
method: 'put',
|
method: 'put',
|
||||||
url: 'api/envs/disable',
|
url: 'api/envs/disable',
|
||||||
params: { t: Date.now() },
|
params: { t: Date.now() },
|
||||||
body: JSON.stringify([eid]),
|
body: JSON.stringify([eid]),
|
||||||
headers: {
|
headers: {
|
||||||
Accept: 'application/json',
|
Accept: 'application/json',
|
||||||
@ -216,7 +225,7 @@ module.exports.EnableCk = async (eid) => {
|
|||||||
const body = await api({
|
const body = await api({
|
||||||
method: 'put',
|
method: 'put',
|
||||||
url: 'api/envs/enable',
|
url: 'api/envs/enable',
|
||||||
params: { t: Date.now() },
|
params: { t: Date.now() },
|
||||||
body: JSON.stringify([eid]),
|
body: JSON.stringify([eid]),
|
||||||
headers: {
|
headers: {
|
||||||
Accept: 'application/json',
|
Accept: 'application/json',
|
||||||
@ -227,50 +236,50 @@ module.exports.EnableCk = async (eid) => {
|
|||||||
return body;
|
return body;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.getstatus = async (eid) => {
|
module.exports.getstatus = async(eid) => {
|
||||||
const envs = await this.getEnvs();
|
const envs = await this.getEnvs();
|
||||||
var tempid = 0;
|
var tempid = 0;
|
||||||
for (let i = 0; i < envs.length; i++) {
|
for (let i = 0; i < envs.length; i++) {
|
||||||
tempid = 0;
|
tempid = 0;
|
||||||
if (envs[i]._id) {
|
if (envs[i]._id) {
|
||||||
tempid = envs[i]._id;
|
tempid = envs[i]._id;
|
||||||
|
}
|
||||||
|
if (envs[i].id) {
|
||||||
|
tempid = envs[i].id;
|
||||||
|
}
|
||||||
|
if (tempid == eid) {
|
||||||
|
return envs[i].status;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (envs[i].id) {
|
return 99;
|
||||||
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();
|
const envs = await this.getEnvs();
|
||||||
var tempid = 0;
|
var tempid = 0;
|
||||||
for (let i = 0; i < envs.length; i++) {
|
for (let i = 0; i < envs.length; i++) {
|
||||||
tempid = 0;
|
tempid = 0;
|
||||||
if (envs[i]._id) {
|
if (envs[i]._id) {
|
||||||
tempid = envs[i]._id;
|
tempid = envs[i]._id;
|
||||||
|
}
|
||||||
|
if (envs[i].id) {
|
||||||
|
tempid = envs[i].id;
|
||||||
|
}
|
||||||
|
if (tempid == eid) {
|
||||||
|
return envs[i].value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (envs[i].id) {
|
return "";
|
||||||
tempid = envs[i].id;
|
|
||||||
}
|
|
||||||
if (tempid == eid) {
|
|
||||||
return envs[i].value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.getEnvByPtPin = async (Ptpin) => {
|
module.exports.getEnvByPtPin = async (Ptpin) => {
|
||||||
const envs = await this.getEnvs();
|
const envs = await this.getEnvs();
|
||||||
for (let i = 0; i < envs.length; i++) {
|
for (let i = 0; i < envs.length; i++) {
|
||||||
var tempptpin = decodeURIComponent(envs[i].value.match(/pt_pin=([^; ]+)(?=;?)/) && envs[i].value.match(/pt_pin=([^; ]+)(?=;?)/)[1]);
|
var tempptpin = decodeURIComponent(envs[i].value.match(/pt_pin=([^; ]+)(?=;?)/) && envs[i].value.match(/pt_pin=([^; ]+)(?=;?)/)[1]);
|
||||||
if (tempptpin == Ptpin) {
|
if(tempptpin==Ptpin){
|
||||||
return envs[i];
|
return envs[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -288,4 +297,4 @@ module.exports.delEnv = async (eid) => {
|
|||||||
},
|
},
|
||||||
}).json();
|
}).json();
|
||||||
return body;
|
return body;
|
||||||
};
|
};
|
Loading…
x
Reference in New Issue
Block a user