fixes some lint errors

This commit is contained in:
stefanodvx 2025-04-16 17:03:16 +02:00
parent 5ccf4e6168
commit 12c12e53f7
16 changed files with 108 additions and 93 deletions

View file

@ -185,7 +185,7 @@ func GetVideoAPI(contentURL string) (*IGramResponse, error) {
if err != nil {
return nil, fmt.Errorf("failed to build signed payload: %w", err)
}
req, err := http.NewRequest("POST", apiURL, payload)
req, err := http.NewRequest(http.MethodPost, apiURL, payload)
if err != nil {
return nil, fmt.Errorf("failed to create request: %w", err)
}

View file

@ -2,6 +2,7 @@ package instagram
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
"govd/util"
@ -10,6 +11,7 @@ import (
"net/http"
"net/url"
"regexp"
"strconv"
"strings"
"time"
)
@ -19,7 +21,7 @@ var captionPattern = regexp.MustCompile(
)
func BuildSignedPayload(contentURL string) (io.Reader, error) {
timestamp := fmt.Sprintf("%d", time.Now().UnixMilli())
timestamp := strconv.FormatInt(time.Now().UnixMilli(), 10)
hash := sha256.New()
_, err := io.WriteString(
hash,
@ -29,7 +31,7 @@ func BuildSignedPayload(contentURL string) (io.Reader, error) {
return nil, fmt.Errorf("error writing to SHA256 hash: %w", err)
}
secretBytes := hash.Sum(nil)
secretString := fmt.Sprintf("%x", secretBytes)
secretString := hex.EncodeToString(secretBytes)
secretString = strings.ToLower(secretString)
payload := map[string]string{
"url": contentURL,
@ -76,13 +78,13 @@ func ParseIGramResponse(body []byte) (*IGramResponse, error) {
}
func GetCDNURL(contentURL string) (string, error) {
parsedUrl, err := url.Parse(contentURL)
parsedURL, err := url.Parse(contentURL)
if err != nil {
return "", fmt.Errorf("can't parse igram URL: %v", err)
return "", fmt.Errorf("can't parse igram URL: %w", err)
}
queryParams, err := url.ParseQuery(parsedUrl.RawQuery)
queryParams, err := url.ParseQuery(parsedURL.RawQuery)
if err != nil {
return "", fmt.Errorf("can't unescape igram URL: %v", err)
return "", fmt.Errorf("can't unescape igram URL: %w", err)
}
cdnURL := queryParams.Get("uri")
return cdnURL, nil
@ -133,7 +135,6 @@ func GetPostCaption(
if len(matches) < 2 {
// post has no caption most likely
return "", nil
} else {
return html.UnescapeString(matches[1]), nil
}
return html.UnescapeString(matches[1]), nil
}

View file

@ -27,8 +27,8 @@ var (
"co\\.in", "co\\.nz", "id", "com\\.ec", "com\\.py", "tw", "be", "uk", "com\\.bo", "com\\.pe",
}
validHostRegex = strings.Join(validHost, "|")
validUrlPattern = `https?://(?:[^/]+\.)?pinterest\.(` + validHostRegex + `)/pin/(?:[\w-]+--)?(?P<id>\d+)`
pinValidUrlPattern = `https?://(www\.)?pin\.(` + validHostRegex + `)/(?P<id>\w+)`
validURLPattern = `https?://(?:[^/]+\.)?pinterest\.(` + validHostRegex + `)/pin/(?:[\w-]+--)?(?P<id>\d+)`
pinValidURLPattern = `https?://(www\.)?pin\.(` + validHostRegex + `)/(?P<id>\w+)`
)
var ShortExtractor = &models.Extractor{
@ -36,7 +36,7 @@ var ShortExtractor = &models.Extractor{
CodeName: "pinterest:short",
Type: enums.ExtractorTypeSingle,
Category: enums.ExtractorCategorySocial,
URLPattern: regexp.MustCompile(pinValidUrlPattern),
URLPattern: regexp.MustCompile(pinValidURLPattern),
Host: func() []string {
var domains []string
for _, domain := range validHost {
@ -63,7 +63,7 @@ var Extractor = &models.Extractor{
CodeName: "pinterest",
Type: enums.ExtractorTypeSingle,
Category: enums.ExtractorCategorySocial,
URLPattern: regexp.MustCompile(validUrlPattern),
URLPattern: regexp.MustCompile(validURLPattern),
Host: func() []string {
var domains []string
for _, domain := range validHost {
@ -161,7 +161,7 @@ func ExtractPinMedia(ctx *models.DownloadContext) ([]*models.Media, error) {
func GetPinData(pinID string) (*PinData, error) {
params := BuildPinRequestParams(pinID)
req, err := http.NewRequest("GET", pinResourceEndpoint, nil)
req, err := http.NewRequest(http.MethodGet, pinResourceEndpoint, nil)
if err != nil {
return nil, fmt.Errorf("failed to create request: %w", err)
}

View file

@ -32,7 +32,7 @@ var ShortExtractor = &models.Extractor{
IsRedirect: true,
Run: func(ctx *models.DownloadContext) (*models.ExtractorResponse, error) {
req, err := http.NewRequest("GET", ctx.MatchedContentURL, nil)
req, err := http.NewRequest(http.MethodGet, ctx.MatchedContentURL, nil)
if err != nil {
return nil, fmt.Errorf("failed to create request: %w", err)
}
@ -225,7 +225,7 @@ func MediaListFromAPI(ctx *models.DownloadContext) ([]*models.Media, error) {
func GetRedditData(host string, slug string) (RedditResponse, error) {
url := fmt.Sprintf("https://%s/%s/.json", host, slug)
req, err := http.NewRequest("GET", url, nil)
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return nil, fmt.Errorf("failed to create request: %w", err)
}

View file

@ -29,7 +29,7 @@ var ShortExtractor = &models.Extractor{
IsRedirect: true,
Run: func(ctx *models.DownloadContext) (*models.ExtractorResponse, error) {
req, err := http.NewRequest("GET", ctx.MatchedContentURL, nil)
req, err := http.NewRequest(http.MethodGet, ctx.MatchedContentURL, nil)
if err != nil {
return nil, fmt.Errorf("failed to create req: %w", err)
}
@ -139,7 +139,7 @@ func GetTweetAPI(tweetID string) (*Tweet, error) {
}
query := BuildAPIQuery(tweetID)
req, err := http.NewRequest("GET", apiEndpoint, nil)
req, err := http.NewRequest(http.MethodGet, apiEndpoint, nil)
if err != nil {
return nil, fmt.Errorf("failed to create req: %w", err)
}

View file

@ -28,7 +28,7 @@ func BuildAPIHeaders(cookies []*http.Cookie) map[string]string {
return nil
}
headers := map[string]string{
"authorization": fmt.Sprintf("Bearer %s", authToken),
"authorization": "Bearer " + authToken,
"user-agent": util.ChromeUA,
"x-twitter-auth-type": "OAuth2Session",
"x-twitter-client-language": "en",
@ -140,7 +140,7 @@ func FindTweetData(resp *APIResponse, tweetID string) (*Tweet, error) {
}
entries := instructions[0].Entries
entryID := fmt.Sprintf("tweet-%s", tweetID)
entryID := "tweet-" + tweetID
for _, entry := range entries {
if entry.EntryID == entryID {