summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-11-10 12:06:48 +0200
committerPaul Buetow <paul@buetow.org>2024-11-10 12:06:48 +0200
commit42e2b2c29e1e54995f5b20095943844ac92aa55e (patch)
tree845360a1d6a1b4c246a086c33cf5e46759000b70 /internal
parent103b800fa849f0565b4eaa38dee054379b96cd57 (diff)
fix, thumbnail cant be empty
Diffstat (limited to 'internal')
-rw-r--r--internal/platforms/linkedin/linkedin.go24
1 files changed, 10 insertions, 14 deletions
diff --git a/internal/platforms/linkedin/linkedin.go b/internal/platforms/linkedin/linkedin.go
index b8790dd..39ca8cc 100644
--- a/internal/platforms/linkedin/linkedin.go
+++ b/internal/platforms/linkedin/linkedin.go
@@ -85,22 +85,19 @@ func postMessageToLinkedInAPI(ctx context.Context, personID, accessToken, conten
"isReshareDisabledByAuthor": false,
}
- var thumbnailURN string
+ article := map[string]interface{}{}
+
if thumbnailPath, ok := prev.Thumbnail(); ok {
- imageURN, err := postImageToLinkedInAPI(ctx, personURN, accessToken, thumbnailPath)
+ thumbnailURN, err := postImageToLinkedInAPI(ctx, personURN, accessToken, thumbnailPath)
if err != nil {
return err
}
- thumbnailURN = imageURN
+ article["thumbnail"] = thumbnailURN
}
if title, url, ok := prev.TitleAndURL(); ok {
- post["content"] = map[string]interface{}{
- "article": map[string]interface{}{
- "title": title,
- "source": url,
- "thumbnail": thumbnailURN,
- },
- }
+ article["title"] = title
+ article["source"] = url
+ post["content"] = map[string]interface{}{"article": article}
}
payload, err := json.Marshal(post)
@@ -145,7 +142,7 @@ func postImageToLinkedInAPI(ctx context.Context, personURN, accessToken, imagePa
if err != nil {
return imageURN, err
}
- return imageURN, uploadImage(ctx, imagePath, uploadURL, accessToken)
+ return imageURN, performImageUpload(ctx, imagePath, uploadURL, accessToken)
}
func initializeImageUpload(ctx context.Context, personURN, accessToken string) (string, string, error) {
@@ -193,7 +190,7 @@ func initializeImageUpload(ctx context.Context, personURN, accessToken string) (
return response.Value.UploadURL, response.Value.Image, nil
}
-func uploadImage(ctx context.Context, imagePath, uploadURL, accessToken string) error {
+func performImageUpload(ctx context.Context, imagePath, uploadURL, accessToken string) error {
file, err := os.Open(imagePath)
if err != nil {
return err
@@ -222,11 +219,10 @@ func uploadImage(ctx context.Context, imagePath, uploadURL, accessToken string)
if err != nil {
return err
}
- colour.Infoln(string(body))
+ fmt.Println(string(body))
if resp.StatusCode != http.StatusCreated {
return fmt.Errorf("upload failed with status %s: %s", resp.Status, string(body))
}
-
return nil
}