Skip to content

Commit

Permalink
Return error when failed to get new /share/ postID
Browse files Browse the repository at this point in the history
  • Loading branch information
Wikidepia committed Jan 12, 2025
1 parent cd00984 commit 077c05c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions handlers/embed.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package handlers

import (
"errors"
scraper "instafix/handlers/scraper"
"instafix/utils"
"instafix/views"
Expand Down Expand Up @@ -31,18 +32,21 @@ func mediaidToCode(mediaID int) string {
func getSharePostID(postID string) (string, error) {
req, err := http.NewRequest("HEAD", "https://www.instagram.com/share/reel/"+postID+"/", nil)
if err != nil {
return "", err
return postID, err
}
resp, err := http.DefaultTransport.RoundTrip(req)
if err != nil {
return "", err
return postID, err
}
defer resp.Body.Close()
redirURL, err := url.Parse(resp.Header.Get("Location"))
if err != nil {
return "", err
return postID, err
}
postID = path.Base(redirURL.Path)
if postID == "login" {
return postID, errors.New("not logged in")
}
return postID, nil
}

Expand Down

0 comments on commit 077c05c

Please sign in to comment.