Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMHSanaei <ho3ein.sanaei@gmail.com>2024-02-04 01:20:14 +0300
committerMHSanaei <ho3ein.sanaei@gmail.com>2024-02-04 01:20:14 +0300
commit2a2bf531eef9ca0fdc0894e4e740ff0a613ea350 (patch)
tree6b23874a8e6da5b5e429bc0b5dee473053158ee4
parent9d724d34e1cf0c6cf118fb092d737d2f84d67a60 (diff)
Fix tgbot - document upload issue for empty ban logs
-rw-r--r--web/service/tgbot.go46
1 files changed, 30 insertions, 16 deletions
diff --git a/web/service/tgbot.go b/web/service/tgbot.go
index 0b5a8158..7bd6a179 100644
--- a/web/service/tgbot.go
+++ b/web/service/tgbot.go
@@ -1568,30 +1568,44 @@ func (t *Tgbot) sendBanLogs(chatId int64, dt bool) {
file, err := os.Open(xray.GetIPLimitBannedPrevLogPath())
if err == nil {
- document := tu.Document(
- tu.ID(chatId),
- tu.File(file),
- )
- _, err = bot.SendDocument(document)
- if err != nil {
- logger.Error("Error in uploading backup: ", err)
+ // Check if the file is non-empty before attempting to upload
+ fileInfo, _ := file.Stat()
+ if fileInfo.Size() > 0 {
+ document := tu.Document(
+ tu.ID(chatId),
+ tu.File(file),
+ )
+ _, err = bot.SendDocument(document)
+ if err != nil {
+ logger.Error("Error in uploading IPLimitBannedPrevLog: ", err)
+ }
+ } else {
+ logger.Warning("IPLimitBannedPrevLog file is empty, not uploading.")
}
+ file.Close()
} else {
- logger.Error("Error in opening db file for backup: ", err)
+ logger.Error("Error in opening IPLimitBannedPrevLog file for backup: ", err)
}
file, err = os.Open(xray.GetIPLimitBannedLogPath())
if err == nil {
- document := tu.Document(
- tu.ID(chatId),
- tu.File(file),
- )
- _, err = bot.SendDocument(document)
- if err != nil {
- logger.Error("Error in uploading config.json: ", err)
+ // Check if the file is non-empty before attempting to upload
+ fileInfo, _ := file.Stat()
+ if fileInfo.Size() > 0 {
+ document := tu.Document(
+ tu.ID(chatId),
+ tu.File(file),
+ )
+ _, err = bot.SendDocument(document)
+ if err != nil {
+ logger.Error("Error in uploading IPLimitBannedLog: ", err)
+ }
+ } else {
+ logger.Warning("IPLimitBannedLog file is empty, not uploading.")
}
+ file.Close()
} else {
- logger.Error("Error in opening config.json file for backup: ", err)
+ logger.Error("Error in opening IPLimitBannedLog file for backup: ", err)
}
}