Merge pull request 'fix: resolve timeout issues and implement format retrieval retries' (#50) from fix-timeout-and-implement-retries into dev
Reviewed-on: #50
This commit was merged in pull request #50.
This commit is contained in:
25
app/main.go
25
app/main.go
@@ -6,6 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
@@ -365,8 +366,20 @@ func main() {
|
|||||||
h(s, i)
|
h(s, i)
|
||||||
}
|
}
|
||||||
case discordgo.InteractionMessageComponent:
|
case discordgo.InteractionMessageComponent:
|
||||||
if h, ok := componentHandlers[i.MessageComponentData().CustomID]; ok {
|
customID := i.MessageComponentData().CustomID
|
||||||
|
if h, ok := componentHandlers[customID]; ok {
|
||||||
h(s, i)
|
h(s, i)
|
||||||
|
} else if strings.HasPrefix(customID, "retry:") {
|
||||||
|
url := strings.TrimPrefix(customID, "retry:")
|
||||||
|
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||||
|
Type: discordgo.InteractionResponseUpdateMessage,
|
||||||
|
Data: &discordgo.InteractionResponseData{
|
||||||
|
Content: fmt.Sprintf("%s Fetching available formats...", loading_emoji),
|
||||||
|
Components: []discordgo.MessageComponent{},
|
||||||
|
Flags: discordgo.MessageFlagsEphemeral,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
go fetchAndShowFormats(s, i, url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -444,6 +457,16 @@ func fetchAndShowFormats(s *discordgo.Session, i *discordgo.InteractionCreate, u
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
_, err = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
|
_, err = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
|
||||||
Content: ptr("❌ Error fetching formats: " + err.Error()),
|
Content: ptr("❌ Error fetching formats: " + err.Error()),
|
||||||
|
Components: &[]discordgo.MessageComponent{
|
||||||
|
&discordgo.ActionsRow{
|
||||||
|
Components: []discordgo.MessageComponent{
|
||||||
|
discordgo.Button{
|
||||||
|
Label: "Retry",
|
||||||
|
CustomID: fmt.Sprintf("retry:%s", url),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error updating interaction: %v", err)
|
log.Printf("Error updating interaction: %v", err)
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ func GetFormats(url string) (*FormatOptions, error) {
|
|||||||
SkipDownload().
|
SkipDownload().
|
||||||
DumpJSON()
|
DumpJSON()
|
||||||
|
|
||||||
result, err := dl.Run(context.TODO(), url)
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
|
||||||
|
defer cancel()
|
||||||
|
result, err := dl.Run(ctx, url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user