Remove yourls

This commit is contained in:
Noah 2024-06-03 21:14:31 +02:00
parent 02c9f2af6b
commit 3f3e75a5be
4 changed files with 4 additions and 45 deletions

View file

@ -2,10 +2,8 @@ package download
import ( import (
"errors" "errors"
"io"
log2 "log" log2 "log"
"math/rand" "math/rand"
"net/http"
"net/url" "net/url"
"os" "os"
"os/exec" "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) { func serveMedia(update tgbotapi.Update, bot *tgbotapi.BotAPI, randomNoise string, file string) {
fsPath := "data/videos/" + randomNoise + "/" + file fsPath := "data/videos/" + randomNoise + "/" + file
fsThumbPath := "data/videos/" + randomNoise + "thumb" + "/" + strings.TrimSuffix(file, "mp4") + "jpg" 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"} imageTypes := []string{".jpg", ".jpeg", ".png"}
shortURL := shortURL(url.PathEscape(config.BotConfig.Download.Prefix + "/" + randomNoise + "/" + url.PathEscape(file)))
fsPathStat, _ := os.Stat(fsPath) fsPathStat, _ := os.Stat(fsPath)
if fsPathStat.Size() >= 52428800 { if fsPathStat.Size() >= 52428800 {
@ -201,7 +178,7 @@ func serveMedia(update tgbotapi.Update, bot *tgbotapi.BotAPI, randomNoise string
vid := tgbotapi.VideoConfig{ vid := tgbotapi.VideoConfig{
BaseFile: tgbotapi.BaseFile{BaseChat: tgbotapi.BaseChat{ChatID: update.Message.Chat.ID, ReplyToMessageID: update.Message.MessageID}, File: tgbotapi.FilePath(fsPath)}, BaseFile: tgbotapi.BaseFile{BaseChat: tgbotapi.BaseChat{ChatID: update.Message.Chat.ID, ReplyToMessageID: update.Message.MessageID}, File: tgbotapi.FilePath(fsPath)},
Thumb: tgbotapi.FilePath(fsThumbPath), Thumb: tgbotapi.FilePath(fsThumbPath),
Caption: shortURL, Caption: config.BotConfig.Download.Prefix + "/" + randomNoise + "/" + url.PathEscape(file),
SupportsStreaming: true, SupportsStreaming: true,
} }
if _, err := os.Stat(fsThumbPath); err != nil { 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) { } else if commonlogic.ContainsString(imageTypes, fExt) {
pic := tgbotapi.PhotoConfig{ pic := tgbotapi.PhotoConfig{
BaseFile: tgbotapi.BaseFile{BaseChat: tgbotapi.BaseChat{ChatID: update.Message.Chat.ID, ReplyToMessageID: update.Message.MessageID}, File: tgbotapi.FilePath(fsPath)}, 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) botIO.SendPhoto(pic, bot)
} else { } 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}, BaseChat: tgbotapi.BaseChat{ChatID: update.Message.Chat.ID, ReplyToMessageID: update.Message.MessageID},
DisableWebPagePreview: false, DisableWebPagePreview: false,
ParseMode: "html", ParseMode: "html",
Text: shortURL, Text: config.BotConfig.Download.Prefix + "/" + randomNoise + "/" + url.PathEscape(file),
} }
botIO.SendMessage(message, bot) botIO.SendMessage(message, bot)
} }

View file

@ -60,19 +60,8 @@ func EncodeToml() {
}, },
Download: struct { Download: struct {
Prefix string Prefix string
Yourls struct {
APIPath string
Signature string
}
}{ }{
Prefix: "https://bloater.example.com", Prefix: "https://bloater.example.com",
Yourls: struct {
APIPath string
Signature string
}{
APIPath: "https://short.com/yourls-api.php",
Signature: "kfn83h28r",
},
}, },
} }

View file

@ -21,9 +21,5 @@ type config struct {
} }
Download struct { Download struct {
Prefix string Prefix string
Yourls struct {
APIPath string
Signature string
}
} }
} }

View file

@ -15,7 +15,4 @@ PrivilegedUsers = [1234567, 9764382423]
ModifyUsers = [3827468324, 1736576] ModifyUsers = [3827468324, 1736576]
[Download] [Download]
Prefix = "https://bloater.example.com" Prefix = "https://bloater.example.com"
[Download.Yourls]
APIPath = "https://short.com/yourls-api.php"
Signature = "kfn83h28r"