From 50b5b4f6bdfb3dd6f2350a254fa1c12f2035d410 Mon Sep 17 00:00:00 2001 From: 2024 Date: Sun, 9 Mar 2025 20:52:09 +0800 Subject: [PATCH] 1 --- function/ql.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/function/ql.js b/function/ql.js index a1dfde0..03dcd26 100644 --- a/function/ql.js +++ b/function/ql.js @@ -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&&process.env.QL_BRANCH.slice(1,5)>=2.18) - 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])