mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-19 00:09:16 +08:00
fix: 计划任务执行周期增加校验
This commit is contained in:
parent
7ea55997c5
commit
ab8a440c12
5
.gitignore
vendored
5
.gitignore
vendored
@ -16,11 +16,12 @@ build/1panel
|
||||
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
# vendor/
|
||||
/build
|
||||
/pkg/
|
||||
backend/__debug_bin
|
||||
cmd/server/__debug_bin
|
||||
cmd/server/web/assets/
|
||||
cmd/server/web/assets
|
||||
cmd/server/web/monacoeditorwork
|
||||
cmd/server/web/favicon.png
|
||||
cmd/server/web/index.html
|
||||
cmd/server/web/favicon.png
|
||||
frontend/auto-imports.d.ts
|
||||
|
@ -7,9 +7,9 @@ type CronjobCreate struct {
|
||||
Type string `json:"type" validate:"required"`
|
||||
SpecType string `json:"specType" validate:"required"`
|
||||
Week int `json:"week" validate:"number,max=7,min=1"`
|
||||
Day int `json:"day" validate:"number,max=31,min=1"`
|
||||
Hour int `json:"hour" validate:"number,max=23,min=0"`
|
||||
Minute int `json:"minute" validate:"number,max=59,min=0"`
|
||||
Day int `json:"day" validate:"number"`
|
||||
Hour int `json:"hour" validate:"number"`
|
||||
Minute int `json:"minute" validate:"number"`
|
||||
|
||||
Script string `json:"script"`
|
||||
Website string `json:"website"`
|
||||
@ -27,9 +27,9 @@ type CronjobUpdate struct {
|
||||
Name string `json:"name" validate:"required"`
|
||||
SpecType string `json:"specType" validate:"required"`
|
||||
Week int `json:"week" validate:"number,max=7,min=1"`
|
||||
Day int `json:"day" validate:"number,max=31,min=1"`
|
||||
Hour int `json:"hour" validate:"number,max=23,min=0"`
|
||||
Minute int `json:"minute" validate:"number,max=59,min=0"`
|
||||
Day int `json:"day" validate:"number"`
|
||||
Hour int `json:"hour" validate:"number"`
|
||||
Minute int `json:"minute" validate:"number"`
|
||||
|
||||
Script string `json:"script"`
|
||||
Website string `json:"website"`
|
||||
|
@ -177,13 +177,13 @@ func (u *CronjobService) Create(cronjobDto dto.CronjobCreate) error {
|
||||
cronjob.Status = constant.StatusEnable
|
||||
cronjob.Spec = loadSpec(cronjob)
|
||||
|
||||
if err := cronjobRepo.Create(&cronjob); err != nil {
|
||||
return err
|
||||
}
|
||||
global.LOG.Infof("create cronjob %s successful, spec: %s", cronjob.Name, cronjob.Spec)
|
||||
if err := u.StartJob(&cronjob); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := cronjobRepo.Create(&cronjob); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/1Panel-dev/1Panel/backend/global"
|
||||
"html/template"
|
||||
"net/http"
|
||||
|
||||
v1 "github.com/1Panel-dev/1Panel/backend/app/api/v1"
|
||||
"github.com/1Panel-dev/1Panel/backend/global"
|
||||
"github.com/1Panel-dev/1Panel/backend/i18n"
|
||||
"github.com/1Panel-dev/1Panel/backend/middleware"
|
||||
rou "github.com/1Panel-dev/1Panel/backend/router"
|
||||
|
@ -556,6 +556,7 @@ export default {
|
||||
curl: 'Access URL',
|
||||
taskName: 'Task name',
|
||||
cronSpec: 'Lifecycle',
|
||||
cronSpecHelper: 'Enter the correct execution period',
|
||||
directory: 'Backup directory',
|
||||
sourceDir: 'Backup directory',
|
||||
exclusionRules: 'Exclusive rule',
|
||||
|
@ -564,6 +564,7 @@ export default {
|
||||
curl: '访问 URL',
|
||||
taskName: '任务名称',
|
||||
cronSpec: '执行周期',
|
||||
cronSpecHelper: '请输入正确的执行周期',
|
||||
directory: '备份目录',
|
||||
sourceDir: '备份目录',
|
||||
exclusionRules: '排除规则',
|
||||
|
@ -159,7 +159,7 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { reactive, ref } from 'vue';
|
||||
import { Rules } from '@/global/form-rules';
|
||||
import { checkNumberRange, Rules } from '@/global/form-rules';
|
||||
import FileList from '@/components/file-list/index.vue';
|
||||
import { getBackupList } from '@/api/modules/setting';
|
||||
import i18n from '@/lang';
|
||||
@ -170,7 +170,7 @@ import { loadDBNames } from '@/api/modules/database';
|
||||
import { CheckAppInstalled } from '@/api/modules/app';
|
||||
import { GetWebsiteOptions } from '@/api/modules/website';
|
||||
import DrawerHeader from '@/components/drawer-header/index.vue';
|
||||
import { MsgSuccess } from '@/utils/message';
|
||||
import { MsgError, MsgSuccess } from '@/utils/message';
|
||||
|
||||
interface DialogProps {
|
||||
title: string;
|
||||
@ -291,9 +291,9 @@ const rules = reactive({
|
||||
{ validator: varifySpec, trigger: 'change', required: true },
|
||||
],
|
||||
week: [Rules.requiredSelect, Rules.number],
|
||||
day: [Rules.number, { max: 31, min: 1 }],
|
||||
hour: [Rules.number, { max: 23, min: 0 }],
|
||||
minute: [Rules.number, { max: 60, min: 1 }],
|
||||
day: [Rules.number, checkNumberRange(1, 31)],
|
||||
hour: [Rules.number, checkNumberRange(1, 23)],
|
||||
minute: [Rules.number, checkNumberRange(1, 59)],
|
||||
|
||||
script: [Rules.requiredInput],
|
||||
website: [Rules.requiredSelect],
|
||||
@ -389,11 +389,36 @@ function hasScript() {
|
||||
return dialogData.value.rowData!.type === 'shell';
|
||||
}
|
||||
|
||||
function checkScript() {
|
||||
let row = dialogData.value.rowData;
|
||||
console.log(row.specType, row.week, row.day, row.hour, row.minute);
|
||||
switch (row.specType) {
|
||||
case 'perMonth':
|
||||
return row.day > 0 && row.day < 32 && row.hour >= 0 && row.hour < 24 && row.minute >= 0 && row.minute < 60;
|
||||
case 'perWeek':
|
||||
return row.week > 0 && row.week < 8 && row.hour >= 0 && row.hour < 24 && row.minute >= 0 && row.minute < 60;
|
||||
case 'perDay':
|
||||
return row.hour >= 0 && row.hour < 24 && row.minute >= 0 && row.minute < 60;
|
||||
case 'perHour':
|
||||
return row.minute > 0 && row.minute < 60;
|
||||
case 'perNDay':
|
||||
return row.day > 0 && row.day < 366 && row.hour >= 0 && row.hour < 24 && row.minute >= 0 && row.minute < 60;
|
||||
case 'perNHour':
|
||||
return row.hour > 0 && row.hour < 8784 && row.minute >= 0 && row.minute < 60;
|
||||
case 'perNMinute':
|
||||
return row.minute > 0 && row.minute < 527040;
|
||||
}
|
||||
}
|
||||
|
||||
const onSubmit = async (formEl: FormInstance | undefined) => {
|
||||
dialogData.value.rowData.week = Number(dialogData.value.rowData.week);
|
||||
dialogData.value.rowData.day = Number(dialogData.value.rowData.day);
|
||||
dialogData.value.rowData.hour = Number(dialogData.value.rowData.hour);
|
||||
dialogData.value.rowData.minute = Number(dialogData.value.rowData.minute);
|
||||
if (!checkScript()) {
|
||||
MsgError(i18n.global.t('cronjob.cronSpecHelper'));
|
||||
return;
|
||||
}
|
||||
if (!formEl) return;
|
||||
formEl.validate(async (valid) => {
|
||||
if (!valid) return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user