From b4e5db9da940388ac38f870d4a4a8b07635fc3ca Mon Sep 17 00:00:00 2001 From: whyour Date: Sun, 30 Jul 2023 21:15:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=AE=A2=E9=98=85=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E8=87=AA=E5=8A=A8=E5=88=A0=E9=99=A4=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=92=8C=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/api/subscription.ts | 6 +++++- back/services/subscription.ts | 21 ++++++++++++++++++--- src/layouts/index.less | 2 +- src/locales/en-US.json | 15 ++++++++++++++- src/locales/zh-CN.json | 4 +++- src/pages/dependence/index.tsx | 2 +- src/pages/script/editModal.tsx | 4 ++-- src/pages/subscription/index.tsx | 16 +++++++++++++++- 8 files changed, 59 insertions(+), 11 deletions(-) diff --git a/back/api/subscription.ts b/back/api/subscription.ts index 1982cdc5..a03ee895 100644 --- a/back/api/subscription.ts +++ b/back/api/subscription.ts @@ -210,12 +210,16 @@ export default (app: Router) => { '/', celebrate({ body: Joi.array().items(Joi.number().required()), + query: Joi.object({ + force: Joi.boolean().optional(), + t: Joi.number() + }) }), async (req: Request, res: Response, next: NextFunction) => { const logger: Logger = Container.get('logger'); try { const subscriptionService = Container.get(SubscriptionService); - const data = await subscriptionService.remove(req.body); + const data = await subscriptionService.remove(req.body, req.query); return res.send({ code: 200, data }); } catch (e) { return next(e); diff --git a/back/services/subscription.ts b/back/services/subscription.ts index b98937fc..842977a2 100644 --- a/back/services/subscription.ts +++ b/back/services/subscription.ts @@ -16,10 +16,11 @@ import { killTask, handleLogPath, promiseExec, + emptyDir, } from '../config/util'; import { promises, existsSync } from 'fs'; import { FindOptions, Op } from 'sequelize'; -import path from 'path'; +import path, { join } from 'path'; import ScheduleService, { TaskCallbacks } from './schedule'; import { SimpleIntervalSchedule } from 'toad-scheduler'; import SockService from './sock'; @@ -27,6 +28,8 @@ import SshKeyService from './sshKey'; import dayjs from 'dayjs'; import { LOG_END_SYMBOL } from '../config/const'; import { formatCommand, formatUrl } from '../config/subscription'; +import { CrontabModel } from '../data/cron'; +import CrontabService from './cron'; @Service() export default class SubscriptionService { @@ -35,7 +38,8 @@ export default class SubscriptionService { private scheduleService: ScheduleService, private sockService: SockService, private sshKeyService: SshKeyService, - ) {} + private crontabService: CrontabService, + ) { } public async list(searchText?: string): Promise { let query = {}; @@ -253,13 +257,24 @@ export default class SubscriptionService { ); } - public async remove(ids: number[]) { + public async remove(ids: number[], query: any) { const docs = await SubscriptionModel.findAll({ where: { id: ids } }); for (const doc of docs) { await this.handleTask(doc, false); } await SubscriptionModel.destroy({ where: { id: ids } }); await this.setSshConfig(); + + if (query?.force === true) { + const crons = await CrontabModel.findAll({ where: { sub_id: ids } }); + if (crons?.length) { + await this.crontabService.remove(crons.map(x => x.id!)) + } + for (const doc of docs) { + const filePath = join(config.scriptPath, doc.alias); + emptyDir(filePath); + } + } } public async getDb( diff --git a/src/layouts/index.less b/src/layouts/index.less index c4f7caec..50c0ff44 100644 --- a/src/layouts/index.less +++ b/src/layouts/index.less @@ -332,7 +332,7 @@ select:-webkit-autofill:focus { } .ant-pro-sider-logo { - padding-inline: 8px !important; + padding-inline: 5px !important; .title { display: flex; diff --git a/src/locales/en-US.json b/src/locales/en-US.json index 24ef6e37..f6934212 100644 --- a/src/locales/en-US.json +++ b/src/locales/en-US.json @@ -394,5 +394,18 @@ "强制删除": "Force Delete", "全部任务": "All Tasks", "关联订阅": "Associate Subscription", - "订阅": "Subscription" + "订阅": "Subscription", + "创建": "Create", + "创建订阅成功": "Subscription created successfully", + "gotify的url地址,例如 https://push.example.de:8080": "Gotify URL address, e.g., https://push.example.de:8080", + "BARK推送图标,自定义推送图标 (需iOS15或以上才能显示)": "BARK push icon, custom push icon (requires iOS 15 or above to display)", + "BARK推送铃声,铃声列表去APP查看复制填写": "BARK push ringtone, check the ringtone list in the APP and copy it", + "BARK推送消息的分组, 默认为qinglong": "BARK push message grouping, default is qinglong", + "telegram代理配置认证参数, 用户名与密码用英文冒号连接 user:password": "Telegram proxy configuration authentication parameters, connect username and password with a colon, e.g., user:password", + "企业微信机器人的 webhook(详见文档 https://work.weixin.qq.com/api/doc/90000/90136/91770),例如:693a91f6-7xxx-4bc4-97a0-0ec2sifa5aaa": "WeChat Work Bot webhook (see documentation at https://work.weixin.qq.com/api/doc/90000/90136/91770), e.g., 693a91f6-7xxx-4bc4-97a0-0ec2sifa5aaa", + "corpid,corpsecret,touser(注:多个成员ID使用|隔开),agentid,消息类型(选填,不填默认文本消息类型) 注意用,号隔开(英文输入法的逗号),例如:wwcfrs,B-76WERQ,qinglong,1000001,2COat": "corpid, corpsecret, touser (note: separate multiple member IDs with |), agentid, message type (optional, defaults to text message type) – separated by commas (`,`), e.g., wwcfrs, B-76WERQ, qinglong, 1000001, 2COat", + "密钥key,智能微秘书个人中心获取apikey,申请地址:https://wechat.aibotk.com/signup?from=ql": "Key, obtain the API key from the Smart WeChat Assistant's personal center, apply at: https://wechat.aibotk.com/signup?from=ql", + "一对多推送的“群组编码”(一对多推送下面->您的群组(如无则新建)->群组编码,如果您是创建群组人。也需点击“查看二维码”扫描绑定,否则不能接受群组消息推送)": "The 'Group Code' for one-to-many push (under one-to-many push->Your Group (create one if none exists)->Group Code. If you are the creator of the group, you also need to click 'View QR Code' for scanning and binding, otherwise you cannot receive group message push)", + "同时删除关联任务和脚本": "Delete associated tasks and scripts as well", + "夹及其子文件": "Folder and its sub-files" } diff --git a/src/locales/zh-CN.json b/src/locales/zh-CN.json index 08559f23..ee7a3855 100644 --- a/src/locales/zh-CN.json +++ b/src/locales/zh-CN.json @@ -394,5 +394,7 @@ "强制删除": "强制删除", "全部任务": "全部任务", "关联订阅": "关联订阅", - "订阅": "订阅" + "订阅": "订阅", + "创建": "创建", + "同时删除关联任务和脚本": "同时删除关联任务和脚本" } diff --git a/src/pages/dependence/index.tsx b/src/pages/dependence/index.tsx index 8c529e23..520ea441 100644 --- a/src/pages/dependence/index.tsx +++ b/src/pages/dependence/index.tsx @@ -106,7 +106,7 @@ const Dependence = () => { { title: intl.get('状态'), key: 'status', - width: 100, + width: 120, dataIndex: 'status', render: (text: string, record: any, index: number) => { return ( diff --git a/src/pages/script/editModal.tsx b/src/pages/script/editModal.tsx index 3e36dda7..58bcc64e 100644 --- a/src/pages/script/editModal.tsx +++ b/src/pages/script/editModal.tsx @@ -195,7 +195,7 @@ const EditModal = ({ > {intl.get('清空日志')} - + */}