diff --git a/sendNotify.js b/sendNotify.js index 3c132cb..d4c6074 100644 --- a/sendNotify.js +++ b/sendNotify.js @@ -2125,21 +2125,28 @@ function GetnickName2() { } const got = require('got'); require('dotenv').config(); -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 fs.readFileSync(authFile);