mirror of
https://github.com/shufflewzc/faker3.git
synced 2025-03-13 22:24:45 +08:00
Update ql.js
This commit is contained in:
parent
a9b4c62f30
commit
c21e57ca3a
23
ql.js
23
ql.js
@ -1,7 +1,6 @@
|
|||||||
'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');
|
||||||
@ -23,8 +22,6 @@ 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);
|
||||||
@ -38,18 +35,17 @@ let authFile = "";
|
|||||||
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') {
|
} else if (version < '2.12.0') {
|
||||||
|
|
||||||
authFile = "/ql/config/auth.json";
|
authFile = "/ql/config/auth.json";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
authFile = "/ql/data/config/auth.json";
|
authFile = "/ql/data/config/auth.json";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 当检测不到版本号时,采用 version < '2.12.0' 的操作
|
||||||
|
authFile = "/ql/config/auth.json";
|
||||||
}
|
}
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.error('Error after initialization:', error);
|
console.error('Error after initialization:', error);
|
||||||
@ -59,9 +55,11 @@ 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) {
|
||||||
@ -105,24 +103,17 @@ async function getTokenFromSqlite(dbPath) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getToken() {
|
async function getToken() {
|
||||||
|
|
||||||
const authFilePath = await getAuthFile();
|
const authFilePath = await getAuthFile();
|
||||||
if (authFilePath.endsWith('keyv.sqlite')) {
|
if (authFilePath.endsWith('keyv.sqlite')) {
|
||||||
|
|
||||||
return getTokenFromSqlite(authFilePath);
|
return getTokenFromSqlite(authFilePath);
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
const authConfig = JSON.parse(await readFile(authFilePath));
|
const authConfig = JSON.parse(await readFile(authFilePath));
|
||||||
return authConfig.token;
|
return authConfig.token;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.getEnvs = async () => {
|
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: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user