添加删除过期脚本选项

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,13 +302,22 @@ import {fileURLToPath, pathToFileURL} from 'url';
} }
} }
for (let script of fs.readdirSync(`${abspath}/parse/${item}`)) { for (let script of fs.readdirSync(`${abspath}/parse/${item}`)) {
try { if (delList.includes(script)) {
if (script.match(/\w+\_\w+\_\w/)) { for (let obj of cronData) {
let imp = await if (obj.command.includes(script)) {
import (`${abspath}/parse/${item}/${script}`) console.log(`🦊🐼 删除任务:`, script)
let psyDuck = new imp.Main() await this.delCron(obj)
let crontab = psyDuck.crontab() }
let code = ` }
}
else {
try {
if (script.match(/\w+\_\w+\_\w/)) {
let imp = await
import (`${abspath}/parse/${item}/${script}`)
let psyDuck = new imp.Main()
let crontab = psyDuck.crontab()
let code = `
import path from 'path'; import path from 'path';
import {fileURLToPath, pathToFileURL} from 'url'; import {fileURLToPath, pathToFileURL} from 'url';
!(async () => { !(async () => {
@ -323,30 +352,31 @@ import {fileURLToPath, pathToFileURL} from 'url';
} }
process.exit() process.exit()
})` })`
fs.writeFile(`${abspath}/${script}`, code, function(err, data) { fs.writeFile(`${abspath}/${script}`, code, function(err, data) {
if (err) { if (err) {
throw err; throw err;
} }
console.log(`🐯‍❄️ 写入成功: ${script}`) console.log(`🐯‍❄️ 写入成功: ${script}`)
}) })
if (!data[script]) { if (!data[script]) {
dicts[script] = { dicts[script] = {
name: `PsyDuck_${psyDuck.profile.title}`, name: `PsyDuck_${psyDuck.profile.title}`,
schedule: crontab, schedule: crontab,
command: `task qitoqito_psyduck/${script}`, command: `task qitoqito_psyduck/${script}`,
// labels: label ? [`PsyDuck`] : '' // labels: label ? [`PsyDuck`] : ''
} }
if (label) { if (label) {
dicts[script].labels = [`PsyDuck`] dicts[script].labels = [`PsyDuck`]
}
} }
} }
} catch (e) {
console.log(`🐽🐽️ 写入失败: ${script}`)
} }
} catch (e) {
console.log(`🐽🐽️ 写入失败: ${script}`)
} }
} }
} }
}) }.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) {