mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-04-20 05:52:24 +00:00
Fix tgbot - document upload issue for empty ban logs
This commit is contained in:
parent
9d724d34e1
commit
2a2bf531ee
1 changed files with 30 additions and 16 deletions
|
@ -1568,30 +1568,44 @@ func (t *Tgbot) sendBanLogs(chatId int64, dt bool) {
|
||||||
|
|
||||||
file, err := os.Open(xray.GetIPLimitBannedPrevLogPath())
|
file, err := os.Open(xray.GetIPLimitBannedPrevLogPath())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
// Check if the file is non-empty before attempting to upload
|
||||||
|
fileInfo, _ := file.Stat()
|
||||||
|
if fileInfo.Size() > 0 {
|
||||||
document := tu.Document(
|
document := tu.Document(
|
||||||
tu.ID(chatId),
|
tu.ID(chatId),
|
||||||
tu.File(file),
|
tu.File(file),
|
||||||
)
|
)
|
||||||
_, err = bot.SendDocument(document)
|
_, err = bot.SendDocument(document)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("Error in uploading backup: ", err)
|
logger.Error("Error in uploading IPLimitBannedPrevLog: ", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.Error("Error in opening db file for backup: ", err)
|
logger.Warning("IPLimitBannedPrevLog file is empty, not uploading.")
|
||||||
|
}
|
||||||
|
file.Close()
|
||||||
|
} else {
|
||||||
|
logger.Error("Error in opening IPLimitBannedPrevLog file for backup: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
file, err = os.Open(xray.GetIPLimitBannedLogPath())
|
file, err = os.Open(xray.GetIPLimitBannedLogPath())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
// Check if the file is non-empty before attempting to upload
|
||||||
|
fileInfo, _ := file.Stat()
|
||||||
|
if fileInfo.Size() > 0 {
|
||||||
document := tu.Document(
|
document := tu.Document(
|
||||||
tu.ID(chatId),
|
tu.ID(chatId),
|
||||||
tu.File(file),
|
tu.File(file),
|
||||||
)
|
)
|
||||||
_, err = bot.SendDocument(document)
|
_, err = bot.SendDocument(document)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("Error in uploading config.json: ", err)
|
logger.Error("Error in uploading IPLimitBannedLog: ", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.Error("Error in opening config.json file for backup: ", err)
|
logger.Warning("IPLimitBannedLog file is empty, not uploading.")
|
||||||
|
}
|
||||||
|
file.Close()
|
||||||
|
} else {
|
||||||
|
logger.Error("Error in opening IPLimitBannedLog file for backup: ", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue