Remove yourls
This commit is contained in:
parent
02c9f2af6b
commit
3f3e75a5be
4 changed files with 4 additions and 45 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -21,9 +21,5 @@ type config struct {
|
|||
}
|
||||
Download struct {
|
||||
Prefix string
|
||||
Yourls struct {
|
||||
APIPath string
|
||||
Signature string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
Loading…
Reference in a new issue