summaryrefslogtreecommitdiff
path: root/internal/platforms
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-12-10 22:01:27 +0200
committerPaul Buetow <paul@buetow.org>2024-12-10 22:01:27 +0200
commita5529938536f7a530f0c55e5a82b16a4c80af5b4 (patch)
tree8c76b7190872174bc9dea434f8c3af758d0ffa28 /internal/platforms
parentc0e0e1ff4905af70a4f113eb9c2e0d94f18b2436 (diff)
fix
Diffstat (limited to 'internal/platforms')
-rw-r--r--internal/platforms/linkedin/linkedin.go15
-rw-r--r--internal/platforms/linkedin/oauth2/oauth2.go10
-rw-r--r--internal/platforms/linkedin/preview.go6
-rw-r--r--internal/platforms/mastodon/mastodon.go2
-rw-r--r--internal/platforms/platform.go2
5 files changed, 21 insertions, 14 deletions
diff --git a/internal/platforms/linkedin/linkedin.go b/internal/platforms/linkedin/linkedin.go
index 20bb1c2..b960c01 100644
--- a/internal/platforms/linkedin/linkedin.go
+++ b/internal/platforms/linkedin/linkedin.go
@@ -25,7 +25,9 @@ const linkedInTimeout = 10 * time.Second
func Post(ctx context.Context, args config.Args, sizeLimit int, en entry.Entry) error {
err := post(ctx, args, sizeLimit, en)
if errors.Is(err, errUnauthorized) {
- colour.Infoln(err, "=> trying to refresh LinkedIn access token")
+ if _, err = colour.Infoln(err, "=> trying to refresh LinkedIn access token"); err != nil {
+ return err
+ }
args.Secrets.LinkedInAccessToken = "" // Reset the token
return post(ctx, args, sizeLimit, en)
}
@@ -34,11 +36,16 @@ func Post(ctx context.Context, args config.Args, sizeLimit int, en entry.Entry)
func post(ctx context.Context, args config.Args, sizeLimit int, en entry.Entry) error {
if args.DryRun {
- colour.Infoln("Not posting", en, "to LinkedIn as dry-run enabled")
- return nil
+ _, err := colour.Infoln("Not posting", en, "to LinkedIn as dry-run enabled")
+ return err
}
- newCtx, cancel := context.WithTimeout(ctx, linkedInTimeout)
+ timeout := linkedInTimeout
+ if args.Secrets.LinkedInAccessToken == "" {
+ // Refreshing access token requires more time due to human interaction
+ timeout = 1 * time.Minute
+ }
+ newCtx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
personID, accessToken, err := oauth2.LinkedInCreds(newCtx, args)
if err != nil {
diff --git a/internal/platforms/linkedin/oauth2/oauth2.go b/internal/platforms/linkedin/oauth2/oauth2.go
index 51beec9..f37e913 100644
--- a/internal/platforms/linkedin/oauth2/oauth2.go
+++ b/internal/platforms/linkedin/oauth2/oauth2.go
@@ -72,7 +72,7 @@ func oauthCallbackHandler(w http.ResponseWriter, r *http.Request) {
defer close(errCh)
code := r.URL.Query().Get("code")
- colour.Infoln("Exchanging OAuth2 token")
+ _, _ = colour.Infoln("Exchanging OAuth2 token")
token, err := oauthConfig.Exchange(globalCtx, code)
if err != nil {
_, _ = w.Write([]byte(err.Error()))
@@ -110,7 +110,7 @@ func LinkedInCreds(ctx context.Context, args config.Args) (string, string, error
http.HandleFunc("/callback", oauthCallbackHandler)
http.HandleFunc("/up", upHandler)
- colour.Infoln("Listening on http://localhost:8080 for LinkedIn OAuth2")
+ _, _ = colour.Infoln("Listening on http://localhost:8080 for LinkedIn OAuth2")
go func() {
if err := http.ListenAndServe(":8080", nil); err != nil {
errCh <- err
@@ -139,7 +139,7 @@ func LinkedInCreds(ctx context.Context, args config.Args) (string, string, error
}
func openURLInFirefox(browser, url string) error {
- colour.Infoln("Opening", url, "in", browser)
+ _, _ = colour.Infoln("Opening", url, "in", browser)
switch runtime.GOOS {
case "windows":
cmd := exec.Command("cmd", "/C", "start", browser, url)
@@ -162,10 +162,10 @@ func WaitUntilURLIsReachable(url string) error {
resp, err := http.Get(url)
if err != nil {
- colour.Infof("URL is not reachable: %v", err)
+ _, _ = colour.Infof("URL is not reachable: %v", err)
fmt.Print("\n")
} else {
- colour.Infof("URL is reachable: %s - Status Code: %d", url, resp.StatusCode)
+ _, _ = colour.Infof("URL is reachable: %s - Status Code: %d", url, resp.StatusCode)
fmt.Print("\n")
resp.Body.Close()
return nil
diff --git a/internal/platforms/linkedin/preview.go b/internal/platforms/linkedin/preview.go
index 41b99a5..b30ddf1 100644
--- a/internal/platforms/linkedin/preview.go
+++ b/internal/platforms/linkedin/preview.go
@@ -37,11 +37,11 @@ func NewPreview(ctx context.Context, args config.Args, urls []string) (preview,
if p.title, p.thumbnailURL, err = extractFromURL(ctx, urls[0]); err != nil {
if errors.Is(err, errNoTitleElementFound) || p.title == "" {
- colour.Infoln("Setting title to", urls[0])
+ _, _ = colour.Infoln("Setting title to", urls[0])
p.title = urls[0]
}
if errors.Is(err, errNoImageElementFound) {
- colour.Infoln("URL", urls[0], "without any image, that's fine, though.")
+ _, _ = colour.Infoln("URL", urls[0], "without any image, that's fine, though.")
}
if !errors.Is(err, errNoTitleElementFound) && !errors.Is(err, errNoImageElementFound) {
return p, err
@@ -52,7 +52,7 @@ func NewPreview(ctx context.Context, args config.Args, urls []string) (preview,
if p.thumbnailDownloadPath, err = p.DownloadImage(args.CacheDir); err != nil {
return p, err
}
- colour.Infoln("Downloaded preview image to ", p.thumbnailDownloadPath)
+ _, _ = colour.Infoln("Downloaded preview image to ", p.thumbnailDownloadPath)
}
return p, nil
}
diff --git a/internal/platforms/mastodon/mastodon.go b/internal/platforms/mastodon/mastodon.go
index 938cf6f..abcbea9 100644
--- a/internal/platforms/mastodon/mastodon.go
+++ b/internal/platforms/mastodon/mastodon.go
@@ -23,7 +23,7 @@ func Post(ctx context.Context, args config.Args, sizeLimit int, en entry.Entry)
return err
}
if args.DryRun {
- colour.Infoln("Not posting", en, "to Mastodon as dry-run enabled")
+ _, _ = colour.Infoln("Not posting", en, "to Mastodon as dry-run enabled")
return nil
}
if content, err = prompt.FileAction("Do you want to post this message to Mastodon?", content, en.Path); err != nil {
diff --git a/internal/platforms/platform.go b/internal/platforms/platform.go
index e5bbd22..3cf02c9 100644
--- a/internal/platforms/platform.go
+++ b/internal/platforms/platform.go
@@ -39,7 +39,7 @@ func (p Platform) String() string {
}
func (p Platform) Post(ctx context.Context, args config.Args, sizeLimit int, en entry.Entry) (err error) {
- colour.Infoln("Posting", en)
+ _, _ = colour.Infoln("Posting", en)
switch p.String() {
case "mastodon":
err = mastodon.Post(ctx, args, sizeLimit, en)