Skip to content

Commit

Permalink
Fix nilaway warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Wikidepia committed Jul 19, 2024
1 parent d115919 commit 9a4cf92
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
10 changes: 7 additions & 3 deletions handlers/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ func Embed(w http.ResponseWriter, r *http.Request) {
var err error
postID := chi.URLParam(r, "postID")
mediaNumParams := chi.URLParam(r, "mediaNum")
urlQuery := r.URL.Query()
if urlQuery == nil {
return
}
if mediaNumParams == "" {
imgIndex := r.URL.Query().Get("img_index")
imgIndex := urlQuery.Get("img_index")
if imgIndex != "" {
mediaNumParams = imgIndex
} else {
Expand All @@ -48,8 +52,8 @@ func Embed(w http.ResponseWriter, r *http.Request) {
return
}

isDirect, _ := strconv.ParseBool(r.URL.Query().Get("direct"))
isGallery, _ := strconv.ParseBool(r.URL.Query().Get("gallery"))
isDirect, _ := strconv.ParseBool(urlQuery.Get("direct"))
isGallery, _ := strconv.ParseBool(urlQuery.Get("gallery"))

// Stories use mediaID (int) instead of postID
if strings.Contains(r.URL.Path, "/stories/") {
Expand Down
8 changes: 6 additions & 2 deletions handlers/oembed.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ import (
)

func OEmbed(w http.ResponseWriter, r *http.Request) {
headingText := r.URL.Query().Get("text")
headingURL := r.URL.Query().Get("url")
urlQuery := r.URL.Query()
if urlQuery == nil {
return
}
headingText := urlQuery.Get("text")
headingURL := urlQuery.Get("url")
if headingText == "" || headingURL == "" {
return
}
Expand Down
22 changes: 11 additions & 11 deletions handlers/scraper/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ func (i *InstaData) ScrapeData() error {
if err != nil {
return err
}
if res, err := client.Do(req); err == nil {
res, err := client.Do(req)
if res != nil && res.StatusCode == 200 {
defer res.Body.Close()
iDataGunzip, err := io.ReadAll(res.Body)
if err == nil {
Expand All @@ -158,18 +159,16 @@ func (i *InstaData) ScrapeData() error {

var body []byte
for retries := 0; retries < 3; retries++ {
var res *http.Response
if res, err = client.Do(req); err == nil {
res, err := client.Do(req)
if res != nil && res.StatusCode == 200 {
defer res.Body.Close()
body, err = io.ReadAll(res.Body)
if err == nil && len(body) > 0 {
break
}
}
}
if err != nil {
return err
}

// Pattern matching using LDE
l := &Line{}

Expand All @@ -185,7 +184,7 @@ func (i *InstaData) ScrapeData() error {
lexer := js.NewLexer(parse.NewInputBytes(l.GetTimeSliceImplValue()))
for {
tt, text := lexer.Next()
if tt == js.ErrorToken {
if tt == js.ErrorToken || text == nil {
break
}
if tt == js.StringToken && bytes.Contains(text, []byte("shortcode_media")) {
Expand Down Expand Up @@ -410,9 +409,10 @@ func scrapeFromGQL(postID string) ([]byte, error) {
}

client := http.Client{Timeout: timeout}
if res, err := client.Do(req); err == nil {
defer res.Body.Close()
return io.ReadAll(res.Body)
res, err := client.Do(req)
if err != nil || res == nil {
return nil, err
}
return nil, err
defer res.Body.Close()
return io.ReadAll(res.Body)
}

0 comments on commit 9a4cf92

Please sign in to comment.