mirror of
https://github.com/veops/oneterm.git
synced 2026-09-03 07:25:15 +08:00
feat(backend): add config item replayDir
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/veops/oneterm/internal/model"
|
||||
"github.com/veops/oneterm/internal/service"
|
||||
"github.com/veops/oneterm/pkg/config"
|
||||
"github.com/veops/oneterm/pkg/errors"
|
||||
)
|
||||
|
||||
@@ -151,5 +152,5 @@ func (c *Controller) GetSessionReplay(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx.FileAttachment(filepath.Join("/tmp/replay", filename), filename)
|
||||
ctx.FileAttachment(filepath.Join(config.Cfg.Session.ReplayDir, filename), filename)
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/veops/oneterm/internal/model"
|
||||
"github.com/veops/oneterm/internal/repository"
|
||||
gsession "github.com/veops/oneterm/internal/session"
|
||||
"github.com/veops/oneterm/pkg/config"
|
||||
"github.com/veops/oneterm/pkg/logger"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -113,7 +114,12 @@ func (s *SessionService) CreateSessionReplay(ctx *gin.Context, sessionId string,
|
||||
return err
|
||||
}
|
||||
|
||||
f, err := os.Create(filepath.Join("/tmp/replay", fmt.Sprintf("%s.cast", sessionId)))
|
||||
replayDir := config.Cfg.Session.ReplayDir
|
||||
if err := os.MkdirAll(replayDir, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
f, err := os.Create(filepath.Join(replayDir, fmt.Sprintf("%s.cast", sessionId)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/veops/oneterm/pkg/config"
|
||||
"github.com/veops/oneterm/pkg/logger"
|
||||
)
|
||||
|
||||
@@ -18,7 +19,13 @@ type Asciinema struct {
|
||||
}
|
||||
|
||||
func NewAsciinema(id string, w, h int) (ret *Asciinema, err error) {
|
||||
f, err := os.Create(filepath.Join("/tmp/replay", fmt.Sprintf("%s.cast", id)))
|
||||
replayDir := config.Cfg.Session.ReplayDir
|
||||
if err = os.MkdirAll(replayDir, 0755); err != nil {
|
||||
logger.L().Error("create replay directory failed", zap.String("dir", replayDir), zap.Error(err))
|
||||
return
|
||||
}
|
||||
|
||||
f, err := os.Create(filepath.Join(replayDir, fmt.Sprintf("%s.cast", id)))
|
||||
if err != nil {
|
||||
logger.L().Error("open cast failed", zap.String("id", id), zap.Error(err))
|
||||
return
|
||||
|
||||
@@ -34,6 +34,9 @@ var (
|
||||
Path: "app.log",
|
||||
ConsoleEnable: true,
|
||||
},
|
||||
Session: SessionConfig{
|
||||
ReplayDir: "/replay",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
@@ -139,6 +142,10 @@ type GuacdConfig struct {
|
||||
Port int `yaml:"port"`
|
||||
}
|
||||
|
||||
type SessionConfig struct {
|
||||
ReplayDir string `yaml:"replayDir"`
|
||||
}
|
||||
|
||||
type ConfigYaml struct {
|
||||
Mode string `yaml:"mode"`
|
||||
I18nDir string `yaml:"i18nDir"`
|
||||
@@ -149,6 +156,7 @@ type ConfigYaml struct {
|
||||
Guacd GuacdConfig `yaml:"guacd"`
|
||||
Http HttpConfig `yaml:"http"`
|
||||
Ssh SshConfig `yaml:"ssh"`
|
||||
Session SessionConfig `yaml:"session"`
|
||||
Auth Auth `yaml:"auth"`
|
||||
SecretKey string `yaml:"secretKey"`
|
||||
}
|
||||
|
||||
@@ -48,3 +48,6 @@ auth:
|
||||
iv: 0123456789abcdef
|
||||
|
||||
secretKey: xW2FAUfgffjmerTEBXADmURDOQ43ojLN
|
||||
|
||||
session:
|
||||
replayDir: /replay/
|
||||
|
||||
Reference in New Issue
Block a user