Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

translated from Chinese & end delete a.s emty file #150

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion util/json_util/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

type RawMessage []byte

// MarshalJSON 自定义 json.RawMessage 默认行为
// MarshalJSON customizes the default behavior of json.RawMessage
func (m RawMessage) MarshalJSON() ([]byte, error) {
if len(m) == 0 {
return []byte("null"), nil
Expand Down
Empty file removed util/sys/a.s
Empty file.
8 changes: 4 additions & 4 deletions web/service/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (s *InboundService) AddInbound(inbound *model.Inbound) (*model.Inbound,erro
return inbound, err
}
if exist {
return inbound, common.NewError("端口已存在:", inbound.Port)
return inbound, common.NewError("port already exists:", inbound.Port)
}
db := database.GetDB()

Expand All @@ -74,7 +74,7 @@ func (s *InboundService) AddInbounds(inbounds []*model.Inbound) error {
return err
}
if exist {
return common.NewError("端口已存在:", inbound.Port)
return common.NewError("port already exists:", inbound.Port)
}
}

Expand Down Expand Up @@ -125,7 +125,7 @@ func (s *InboundService) UpdateInbound(inbound *model.Inbound) (*model.Inbound,
return inbound, err
}
if exist {
return inbound, common.NewError("端口已存在:", inbound.Port)
return inbound, common.NewError("port already exists:", inbound.Port)
}

oldInbound, err := s.GetInbound(inbound.Id)
Expand Down Expand Up @@ -336,4 +336,4 @@ func (s *InboundService) DisableInboundByPort(port int) error {
func (s *InboundService) EnableInboundByPort(port int) error {
db := database.GetDB()
return db.Model(model.Inbound{}).Where("port = ?", port).Update("enable", true).Error
}
}
32 changes: 32 additions & 0 deletions web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ var htmlFS embed.FS
//go:embed translation/*
var i18nFS embed.FS

//restore work telegram bot start
var startTime = time.Now()
var isTelegramEnable bool
//restore work telegram bot end

var startTime = time.Now()

type wrapAssetsFS struct {
Expand Down Expand Up @@ -89,6 +94,9 @@ type Server struct {
xrayService service.XrayService
settingService service.SettingService
inboundService service.InboundService
//restore work telegram bot start
telegramService service.TelegramService
//restore work telegram bot end

cron *cron.Cron

Expand Down Expand Up @@ -393,6 +401,23 @@ func (s *Server) Start() (err error) {
logger.Info("web server run http on", listener.Addr())
}
s.listener = listener
//restore work telegram bot start
xuiBeginRunTime = time.Now().Format("2006-01-02 15:04:05")

isTgbotenabled, err := s.settingService.GetTgbotenabled()
if (err == nil) && (isTgbotenabled) {
isTelegramEnable = true

go func() {
s.telegramService.StartRun()
time.Sleep(time.Second * 2)
}()

} else {
isTelegramEnable = false
}

//restore work telegram bot end

s.startTask()

Expand Down Expand Up @@ -421,6 +446,12 @@ func (s *Server) Stop() error {
if s.listener != nil {
err2 = s.listener.Close()
}
isTgbotenabled, err := s.settingService.GetTgbotenabled()
if (err == nil) && (isTgbotenabled) {
go func() {
s.telegramService.StopRunAndClose()
}()
}
return common.Combine(err1, err2)
}

Expand All @@ -431,3 +462,4 @@ func (s *Server) GetCtx() context.Context {
func (s *Server) GetCron() *cron.Cron {
return s.cron
}