@@ -3,8 +3,10 @@ package betterdiscord
33import (
44 "fmt"
55 "net/http"
6+ "net/url"
67 "strconv"
78 "strings"
9+ "time"
810
911 "github.com/betterdiscord/cli/internal/models"
1012 "github.com/betterdiscord/cli/internal/output"
@@ -14,7 +16,7 @@ import (
1416// FetchAddonFromStore queries the BetterDiscord Store API by name or ID.
1517// Returns addon metadata including download URL.
1618func FetchAddonFromStore (identifier string ) (* models.StoreAddon , error ) {
17- apiURL := fmt .Sprintf ("https://api.betterdiscord.app/v3/store/%s" , identifier )
19+ apiURL := fmt .Sprintf ("https://api.betterdiscord.app/v3/store/%s" , url . PathEscape ( identifier ) )
1820
1921 addon , err := utils.DownloadJSON [models.StoreAddon ](apiURL )
2022 if err != nil {
@@ -37,6 +39,7 @@ func GetAddonDownloadURL(id int) (s string, err error) {
3739
3840 // Create client that follows redirects and returns the final URL
3941 client := & http.Client {
42+ Timeout : 10 * time .Second ,
4043 CheckRedirect : func (req * http.Request , via []* http.Request ) error {
4144 // Allow up to 10 redirects
4245 if len (via ) >= 10 {
@@ -126,10 +129,19 @@ func ResolveAddonIdentifier(identifier string) (int, string, bool) {
126129// FetchAddonsOfType fetches all addons of a specific type from the store.
127130// Kind can be "plugin", "theme", or "addon" for all types.
128131func FetchAddonsOfType (kind string ) ([]models.StoreAddon , error ) {
129- endpoint := kind
130- if kind == "" {
131- endpoint = "addons"
132- }
132+ k := strings .ToLower (kind )
133+
134+ var endpoint string
135+ switch k {
136+ case "" , "addon" , "addons" :
137+ endpoint = "addons"
138+ case "plugin" , "plugins" :
139+ endpoint = "plugins"
140+ case "theme" , "themes" :
141+ endpoint = "themes"
142+ default :
143+ return nil , fmt .Errorf ("invalid addon kind %q (expected plugin[s], theme[s], or addon[s])" , kind )
144+ }
133145 apiURL := fmt .Sprintf ("https://api.betterdiscord.app/v3/store/%s" , endpoint )
134146
135147 addons , err := utils.DownloadJSON [[]models.StoreAddon ](apiURL )
0 commit comments