@@ -25,10 +25,10 @@ var (
25
25
type redditWidget struct {
26
26
logger * slog.Logger
27
27
widgetBase `yaml:",inline"`
28
- redditAccessToken string
29
- redditAppName string `yaml:"reddit-app-name"`
30
- redditClientID string `yaml:"reddit-client-id"`
31
- redditClientSecret string `yaml:"reddit-client-secret"`
28
+ RedditAccessToken string
29
+ RedditAppName string `yaml:"reddit-app-name"`
30
+ RedditClientID string `yaml:"reddit-client-id"`
31
+ RedditClientSecret string `yaml:"reddit-client-secret"`
32
32
Posts forumPostList `yaml:"-"`
33
33
Subreddit string `yaml:"subreddit"`
34
34
Proxy proxyOptionsField `yaml:"proxy"`
@@ -54,13 +54,13 @@ type redditTokenResponse struct {
54
54
55
55
func (widget * redditWidget ) fetchRedditAccessToken () error {
56
56
// Only execute if a matching configuration is provider
57
- if widget .redditAppName == "" || widget .redditClientID == "" || widget .redditClientSecret == "" {
57
+ if widget .RedditAppName == "" || widget .RedditClientID == "" || widget .RedditClientSecret == "" {
58
58
return nil
59
59
}
60
60
61
- widget .logger .Info ("Found reddit API credentials" , "app-name" , widget .redditAppName , "client-id" , widget .redditClientID , "client-secret" , widget .redditClientSecret )
61
+ widget .logger .Info ("Found reddit API credentials" , "app-name" , widget .RedditAppName , "client-id" , widget .RedditClientID , "client-secret" , widget .RedditClientSecret )
62
62
63
- auth := base64 .StdEncoding .EncodeToString ([]byte (widget .redditClientID + ":" + widget .redditClientSecret ))
63
+ auth := base64 .StdEncoding .EncodeToString ([]byte (widget .RedditClientID + ":" + widget .RedditClientSecret ))
64
64
65
65
// Prepare form data
66
66
data := url.Values {}
@@ -74,7 +74,7 @@ func (widget *redditWidget) fetchRedditAccessToken() error {
74
74
75
75
// Set headers
76
76
req .Header .Add ("Authorization" , "Basic " + auth )
77
- req .Header .Add ("User-Agent" , fmt .Sprintf ("%s/1.0" , widget .redditAppName ))
77
+ req .Header .Add ("User-Agent" , fmt .Sprintf ("%s/1.0" , widget .RedditAppName ))
78
78
req .Header .Add ("Content-Type" , "application/x-www-form-urlencoded" )
79
79
80
80
// Make the request
@@ -103,7 +103,7 @@ func (widget *redditWidget) fetchRedditAccessToken() error {
103
103
return fmt .Errorf ("unmarshalling Reddit API response: %w" , err )
104
104
}
105
105
106
- widget .redditAccessToken = tokenResp .AccessToken
106
+ widget .RedditAccessToken = tokenResp .AccessToken
107
107
108
108
widget .logger .Info ("Successfully fetched Reddit access token" , "access-token" , tokenResp .AccessToken )
109
109
@@ -178,8 +178,8 @@ func (widget *redditWidget) update(ctx context.Context) {
178
178
widget .RequestUrlTemplate ,
179
179
widget .Proxy .client ,
180
180
widget .ShowFlairs ,
181
- widget .redditAppName ,
182
- widget .redditAccessToken ,
181
+ widget .RedditAppName ,
182
+ widget .RedditAccessToken ,
183
183
)
184
184
185
185
if ! widget .canContinueUpdateAfterHandlingErr (err ) {
@@ -261,6 +261,9 @@ func fetchSubredditPosts(
261
261
query := url.Values {}
262
262
var requestUrl string
263
263
264
+ logger := slog .New (slog .NewTextHandler (os .Stdout , nil ))
265
+ logger .Info ("Fetching subreddit posts" , "app-name" , redditAppName )
266
+
264
267
if search != "" {
265
268
query .Set ("q" , search + " subreddit:" + subreddit )
266
269
query .Set ("sort" , sort )
@@ -274,6 +277,7 @@ func fetchSubredditPosts(
274
277
275
278
if redditAccessToken != "" {
276
279
baseURL = "https://oauth.reddit.com"
280
+ logger .Info ("using oauth url" )
277
281
} else {
278
282
baseURL = "https://www.reddit.com"
279
283
}
@@ -302,6 +306,7 @@ func fetchSubredditPosts(
302
306
setBrowserUserAgentHeader (request )
303
307
} else {
304
308
request .Header .Set ("User-Agent" , fmt .Sprintf ("%s/1.0" , redditAppName ))
309
+ logger .Info ("setting app user agent" , "app-name" , redditAppName )
305
310
}
306
311
307
312
if redditAccessToken != "" {
0 commit comments