diff --git a/commands/download/download.go b/commands/download/download.go index ccaa9ea..01786a8 100644 --- a/commands/download/download.go +++ b/commands/download/download.go @@ -2,10 +2,8 @@ package download import ( "errors" - "io" log2 "log" "math/rand" - "net/http" "net/url" "os" "os/exec" @@ -163,25 +161,6 @@ func matchURL(URL string) (matchedURL string) { } -func shortURL(URL string) (shorturl string) { - resp, err := http.Get(config.BotConfig.Download.Yourls.APIPath + "?signature=" + config.BotConfig.Download.Yourls.Signature + "&action=shorturl&format=simple&url=" + URL) - if err != nil { - log.Err(err).Msg("Failed to get shortURL") - return "" - } - - defer resp.Body.Close() - - body, err := io.ReadAll(resp.Body) - - if err != nil { - log.Err(err).Msg("Failed to get shortURL") - return "" - } - - return string(body) -} - func serveMedia(update tgbotapi.Update, bot *tgbotapi.BotAPI, randomNoise string, file string) { fsPath := "data/videos/" + randomNoise + "/" + file fsThumbPath := "data/videos/" + randomNoise + "thumb" + "/" + strings.TrimSuffix(file, "mp4") + "jpg" @@ -189,8 +168,6 @@ func serveMedia(update tgbotapi.Update, bot *tgbotapi.BotAPI, randomNoise string imageTypes := []string{".jpg", ".jpeg", ".png"} - shortURL := shortURL(url.PathEscape(config.BotConfig.Download.Prefix + "/" + randomNoise + "/" + url.PathEscape(file))) - fsPathStat, _ := os.Stat(fsPath) if fsPathStat.Size() >= 52428800 { @@ -201,7 +178,7 @@ func serveMedia(update tgbotapi.Update, bot *tgbotapi.BotAPI, randomNoise string vid := tgbotapi.VideoConfig{ BaseFile: tgbotapi.BaseFile{BaseChat: tgbotapi.BaseChat{ChatID: update.Message.Chat.ID, ReplyToMessageID: update.Message.MessageID}, File: tgbotapi.FilePath(fsPath)}, Thumb: tgbotapi.FilePath(fsThumbPath), - Caption: shortURL, + Caption: config.BotConfig.Download.Prefix + "/" + randomNoise + "/" + url.PathEscape(file), SupportsStreaming: true, } if _, err := os.Stat(fsThumbPath); err != nil { @@ -212,7 +189,7 @@ func serveMedia(update tgbotapi.Update, bot *tgbotapi.BotAPI, randomNoise string } else if commonlogic.ContainsString(imageTypes, fExt) { pic := tgbotapi.PhotoConfig{ BaseFile: tgbotapi.BaseFile{BaseChat: tgbotapi.BaseChat{ChatID: update.Message.Chat.ID, ReplyToMessageID: update.Message.MessageID}, File: tgbotapi.FilePath(fsPath)}, - Caption: shortURL, + Caption: config.BotConfig.Download.Prefix + "/" + randomNoise + "/" + url.PathEscape(file), } botIO.SendPhoto(pic, bot) } else { @@ -220,7 +197,7 @@ func serveMedia(update tgbotapi.Update, bot *tgbotapi.BotAPI, randomNoise string BaseChat: tgbotapi.BaseChat{ChatID: update.Message.Chat.ID, ReplyToMessageID: update.Message.MessageID}, DisableWebPagePreview: false, ParseMode: "html", - Text: shortURL, + Text: config.BotConfig.Download.Prefix + "/" + randomNoise + "/" + url.PathEscape(file), } botIO.SendMessage(message, bot) } diff --git a/config/config.go b/config/config.go index 818bb87..e08dcf1 100644 --- a/config/config.go +++ b/config/config.go @@ -60,19 +60,8 @@ func EncodeToml() { }, Download: struct { Prefix string - Yourls struct { - APIPath string - Signature string - } }{ Prefix: "https://bloater.example.com", - Yourls: struct { - APIPath string - Signature string - }{ - APIPath: "https://short.com/yourls-api.php", - Signature: "kfn83h28r", - }, }, } diff --git a/config/types.go b/config/types.go index e55ca9c..729b5ee 100644 --- a/config/types.go +++ b/config/types.go @@ -21,9 +21,5 @@ type config struct { } Download struct { Prefix string - Yourls struct { - APIPath string - Signature string - } } } diff --git a/data/config.toml.example b/data/config.toml.example index b3568b5..7e1f0d9 100644 --- a/data/config.toml.example +++ b/data/config.toml.example @@ -15,7 +15,4 @@ PrivilegedUsers = [1234567, 9764382423] ModifyUsers = [3827468324, 1736576] [Download] - Prefix = "https://bloater.example.com" - [Download.Yourls] - APIPath = "https://short.com/yourls-api.php" - Signature = "kfn83h28r" + Prefix = "https://bloater.example.com" \ No newline at end of file