This commit is contained in:
Faker
2025-03-10 07:30:59 +08:00
parent 3b1e8e15e7
commit 7dea09e2d3
7 changed files with 213 additions and 274 deletions

File diff suppressed because one or more lines are too long

View File

@ -5,22 +5,28 @@ require('dotenv').config();
const { readFile } = require('fs/promises');
const path = require('path');
const fs = require('fs');
let Fileexists280 = fs.existsSync('/ql/data/db/keyv.sqlite');
let Fileexists = fs.existsSync('/ql/data/config/auth.json');
let authFile = "";
if (Fileexists280)
authFile = "/ql/data/db/keyv.sqlite"
else if (Fileexists)
authFile = "/ql/data/config/auth.json"
else
authFile = "/ql/config/auth.json"
const tokenFileList = ['/ql/data/db/keyv.sqlite', '/ql/data/config/auth.json', '/ql/config/auth.json'];
let authFile = getLatestFile(tokenFileList);
const api = got.extend({
prefixUrl: 'http://127.0.0.1:5600',
retry: { limit: 0 },
});
function getLatestFile(files) {
let latestFile = null;
let latestMtime = 0;
for (const file of files) {
try {
const stats = fs.statSync(file);
const mtime = stats.mtimeMs;
if (mtime > latestMtime) {
latestMtime = mtime;
latestFile = file;
}
} catch (e) {
}
}
return latestFile;
}
async function getToken() {
const authConfig = await readFile(authFile);
// console.log(authConfig.toString().match(/"token":"(.*?)",/)[1])