mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 07:57:21 +08:00
feat: 添加翻译
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/go-rat/utils/str"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/tnb-labs/panel/internal/app"
|
||||
@@ -20,11 +21,13 @@ import (
|
||||
)
|
||||
|
||||
type cronRepo struct {
|
||||
t *gotext.Locale
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func NewCronRepo(db *gorm.DB) biz.CronRepo {
|
||||
func NewCronRepo(t *gotext.Locale, db *gorm.DB) biz.CronRepo {
|
||||
return &cronRepo{
|
||||
t: t,
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
@@ -39,7 +42,7 @@ func (r *cronRepo) Count() (int64, error) {
|
||||
}
|
||||
|
||||
func (r *cronRepo) List(page, limit uint) ([]*biz.Cron, int64, error) {
|
||||
var cron []*biz.Cron
|
||||
cron := make([]*biz.Cron, 0)
|
||||
var total int64
|
||||
err := r.db.Model(&biz.Cron{}).Order("id desc").Count(&total).Offset(int((page - 1) * limit)).Limit(int(limit)).Find(&cron).Error
|
||||
return cron, total, err
|
||||
@@ -61,8 +64,6 @@ func (r *cronRepo) Create(req *request.CronCreate) error {
|
||||
script = fmt.Sprintf(`#!/bin/bash
|
||||
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH
|
||||
|
||||
# 耗子面板 - 网站备份脚本
|
||||
|
||||
panel-cli backup website -n '%s' -p '%s'
|
||||
panel-cli backup clear -t website -f '%s' -s '%d' -p '%s'
|
||||
systemctl reload nginx
|
||||
@@ -72,8 +73,6 @@ systemctl reload nginx
|
||||
script = fmt.Sprintf(`#!/bin/bash
|
||||
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH
|
||||
|
||||
# 耗子面板 - 数据库备份脚本
|
||||
|
||||
panel-cli backup database -t '%s' -n '%s' -p '%s'
|
||||
panel-cli backup clear -t '%s' -f '%s' -s '%d' -p '%s'
|
||||
`, req.BackupType, req.Target, req.BackupPath, req.BackupType, req.Target, req.Save, req.BackupPath)
|
||||
@@ -83,9 +82,6 @@ panel-cli backup clear -t '%s' -f '%s' -s '%d' -p '%s'
|
||||
script = fmt.Sprintf(`#!/bin/bash
|
||||
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH
|
||||
|
||||
# 耗子面板 - 日志切割脚本
|
||||
|
||||
# 执行切割
|
||||
panel-cli cutoff website -n '%s' -p '%s'
|
||||
panel-cli cutoff clear -t website -f '%s' -s '%d' -p '%s'
|
||||
`, req.Target, req.BackupPath, req.Target, req.Save, req.BackupPath)
|
||||
@@ -97,18 +93,17 @@ panel-cli cutoff clear -t website -f '%s' -s '%d' -p '%s'
|
||||
shellDir := fmt.Sprintf("%s/server/cron/", app.Root)
|
||||
shellLogDir := fmt.Sprintf("%s/server/cron/logs/", app.Root)
|
||||
if !io.Exists(shellDir) {
|
||||
return errors.New("计划任务目录不存在")
|
||||
return errors.New(r.t.Get("cron directory %s not exists", shellDir))
|
||||
}
|
||||
if !io.Exists(shellLogDir) {
|
||||
return errors.New("计划任务日志目录不存在")
|
||||
return errors.New(r.t.Get("cron log directory %s not exists", shellLogDir))
|
||||
}
|
||||
shellFile := strconv.Itoa(int(time.Now().Unix())) + str.Random(16)
|
||||
if err := io.Write(filepath.Join(shellDir, shellFile+".sh"), script, 0700); err != nil {
|
||||
return errors.New(err.Error())
|
||||
}
|
||||
if out, err := shell.Execf("dos2unix %s%s.sh", shellDir, shellFile); err != nil {
|
||||
return errors.New(out)
|
||||
}
|
||||
// 编码转换
|
||||
_, _ = shell.Execf("dos2unix %s%s.sh", shellDir, shellFile)
|
||||
|
||||
cron := new(biz.Cron)
|
||||
cron.Name = req.Name
|
||||
@@ -134,10 +129,6 @@ func (r *cronRepo) Update(req *request.CronUpdate) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if !cron.Status {
|
||||
return errors.New("计划任务已禁用")
|
||||
}
|
||||
|
||||
cron.Time = req.Time
|
||||
cron.Name = req.Name
|
||||
if err = r.db.Save(cron).Error; err != nil {
|
||||
@@ -227,5 +218,5 @@ func (r *cronRepo) restartCron() error {
|
||||
return systemctl.Restart("cron")
|
||||
}
|
||||
|
||||
return errors.New("不支持的系统")
|
||||
return errors.New(r.t.Get("unsupported system"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user