mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-09-10 04:06:18 +00:00
Add gormStatement.RaiseErrorOnNotFound in few places
This commit is contained in:
parent
c5b30d6c6c
commit
572b530863
4 changed files with 12 additions and 9 deletions
|
@ -102,6 +102,7 @@ func (s *SubService) GetSubs(subId string, host string) ([]string, string, error
|
|||
|
||||
func (s *SubService) getInboundsBySubId(subId string) ([]*model.Inbound, error) {
|
||||
db := database.GetDB()
|
||||
db.Statement.RaiseErrorOnNotFound = true
|
||||
var inbounds []*model.Inbound
|
||||
err := db.Model(model.Inbound{}).Preload("ClientStats").Where(`id in (
|
||||
SELECT DISTINCT inbounds.id
|
||||
|
@ -128,6 +129,7 @@ func (s *SubService) getClientTraffics(traffics []xray.ClientTraffic, email stri
|
|||
|
||||
func (s *SubService) getFallbackMaster(dest string, streamSettings string) (string, int, string, error) {
|
||||
db := database.GetDB()
|
||||
db.Statement.RaiseErrorOnNotFound = true
|
||||
var inbound *model.Inbound
|
||||
err := db.Model(model.Inbound{}).
|
||||
Where("JSON_TYPE(settings, '$.fallbacks') = 'array'").
|
||||
|
|
|
@ -82,6 +82,7 @@ func (j *CheckClientIpJob) clearAccessLog() {
|
|||
|
||||
func (j *CheckClientIpJob) hasLimitIp() bool {
|
||||
db := database.GetDB()
|
||||
db.Statement.RaiseErrorOnNotFound = true
|
||||
var inbounds []*model.Inbound
|
||||
|
||||
err := db.Model(model.Inbound{}).Find(&inbounds).Error
|
||||
|
@ -259,10 +260,9 @@ func (j *CheckClientIpJob) updateInboundClientIps(inboundClientIps *model.Inboun
|
|||
|
||||
// check inbound limitation
|
||||
inbound, err := j.getInboundByEmail(clientEmail)
|
||||
j.checkError(err)
|
||||
|
||||
if inbound.Settings == "" {
|
||||
logger.Debug("wrong data ", inbound)
|
||||
if err != nil {
|
||||
logger.Debug(inbound, ":", err)
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -313,6 +313,7 @@ func (j *CheckClientIpJob) updateInboundClientIps(inboundClientIps *model.Inboun
|
|||
|
||||
func (j *CheckClientIpJob) getInboundByEmail(clientEmail string) (*model.Inbound, error) {
|
||||
db := database.GetDB()
|
||||
db.Statement.RaiseErrorOnNotFound = true
|
||||
var inbounds *model.Inbound
|
||||
|
||||
err := db.Model(model.Inbound{}).Where("settings LIKE ?", "%"+clientEmail+"%").Find(&inbounds).Error
|
||||
|
|
|
@ -824,6 +824,7 @@ func (s *InboundService) adjustTraffics(tx *gorm.DB, dbClientTraffics []*xray.Cl
|
|||
|
||||
if len(inboundIds) > 0 {
|
||||
var inbounds []*model.Inbound
|
||||
tx.Statement.RaiseErrorOnNotFound = true
|
||||
err := tx.Model(model.Inbound{}).Where("id IN (?)", inboundIds).Find(&inbounds).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -893,6 +894,7 @@ func (s *InboundService) autoRenewClients(tx *gorm.DB) (bool, int64, error) {
|
|||
for _, traffic := range traffics {
|
||||
inbound_ids = append(inbound_ids, traffic.InboundId)
|
||||
}
|
||||
tx.Statement.RaiseErrorOnNotFound = true
|
||||
err = tx.Model(model.Inbound{}).Where("id IN ?", inbound_ids).Find(&inbounds).Error
|
||||
if err != nil {
|
||||
return false, 0, err
|
||||
|
@ -1675,12 +1677,10 @@ func (s *InboundService) GetClientTrafficTgBot(tgId string) ([]*xray.ClientTraff
|
|||
var traffics []*xray.ClientTraffic
|
||||
err = db.Model(xray.ClientTraffic{}).Where("email IN ?", emails).Find(&traffics).Error
|
||||
if err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
logger.Warning(err)
|
||||
return nil, err
|
||||
}
|
||||
logger.Warning(err)
|
||||
return nil, err
|
||||
}
|
||||
return traffics, err
|
||||
return traffics, nil
|
||||
}
|
||||
|
||||
func (s *InboundService) GetClientTrafficByEmail(email string) (traffic *xray.ClientTraffic, err error) {
|
||||
|
|
|
@ -1469,7 +1469,7 @@ func (t *Tgbot) notifyExhausted() {
|
|||
var disabledClients []xray.ClientTraffic
|
||||
var exhaustedClients []xray.ClientTraffic
|
||||
traffics, err := t.inboundService.GetClientTrafficTgBot(client.TgID)
|
||||
if err == nil {
|
||||
if err == nil && len (traffics) > 0 {
|
||||
output := t.I18nBot("tgbot.messages.exhaustedCount", "Type=="+t.I18nBot("tgbot.clients"))
|
||||
for _, traffic := range traffics {
|
||||
if traffic.Enable {
|
||||
|
|
Loading…
Reference in a new issue