添加删除过期脚本选项

This commit is contained in:
可达鸭 2025-06-18 16:36:51 +08:00
parent 68fc78376d
commit 3d94c8a1a8
2 changed files with 68 additions and 25 deletions

13
config/panel.json Normal file
View File

@ -0,0 +1,13 @@
{
"script": {
"jd": {
"delete": [
"jd_task_niuniu.js",
"jd_task_bSignin.js",
"jd_task_dsSignin.js",
"jd_task_baoxian.js",
"jd_task_laputaSignin.js"
]
}
}
}

View File

@ -14,6 +14,7 @@ class Ql {
const abspath = path.dirname(dirpath) const abspath = path.dirname(dirpath)
let iniText = fs.readFileSync(`${abspath}/config/config.ini`, 'UTF-8') let iniText = fs.readFileSync(`${abspath}/config/config.ini`, 'UTF-8')
let obj = ini.parse(iniText) let obj = ini.parse(iniText)
this.panelJson = JSON.parse(fs.readFileSync(`${abspath}/config/panel.json`, 'UTF-8'))
this.env = obj.env this.env = obj.env
if (this.env.QINGLONG_ClientId) { if (this.env.QINGLONG_ClientId) {
this.config = { this.config = {
@ -175,6 +176,22 @@ class Ql {
} }
} }
async delCron(command) {
const token = this.token
try {
const response = await axios.delete(`${this.config.baseURL}/open/crons`, {
data: [command.id || command._id],
headers: {
'Authorization': `Bearer ${token}`
}
});
return response.data;
} catch (error) {
console.error('[Error] 删除定时任务失败:', error);
throw error;
}
}
async wait(t) { async wait(t) {
return new Promise(e => setTimeout(e, t)) return new Promise(e => setTimeout(e, t))
} }
@ -207,7 +224,10 @@ class Ql {
} }
let dicts = {} let dicts = {}
let dir = fs.readdirSync(`${abspath}/parse`); let dir = fs.readdirSync(`${abspath}/parse`);
let panelJson = this.panelJson
dir.forEach(async function(item, index) { dir.forEach(async function(item, index) {
let config = panelJson.script[item] || {}
let delList = config.delete || []
let stat = fs.lstatSync(`${abspath}/parse/` + item) let stat = fs.lstatSync(`${abspath}/parse/` + item)
if (stat.isDirectory() === true) { if (stat.isDirectory() === true) {
if (fs.existsSync(`${iniPath}/${item}.ini`)) { if (fs.existsSync(`${iniPath}/${item}.ini`)) {
@ -282,6 +302,15 @@ import {fileURLToPath, pathToFileURL} from 'url';
} }
} }
for (let script of fs.readdirSync(`${abspath}/parse/${item}`)) { for (let script of fs.readdirSync(`${abspath}/parse/${item}`)) {
if (delList.includes(script)) {
for (let obj of cronData) {
if (obj.command.includes(script)) {
console.log(`🦊🐼 删除任务:`, script)
await this.delCron(obj)
}
}
}
else {
try { try {
if (script.match(/\w+\_\w+\_\w/)) { if (script.match(/\w+\_\w+\_\w/)) {
let imp = await let imp = await
@ -346,7 +375,8 @@ import {fileURLToPath, pathToFileURL} from 'url';
} }
} }
} }
}) }
}.bind(this))
await this.wait(20000) await this.wait(20000)
let commands = Object.values(dicts) let commands = Object.values(dicts)
for (let i in dicts) { for (let i in dicts) {