Refresh guest token every 3 hours
This commit is contained in:
parent
0adf36d8c2
commit
56f5a2edc2
2 changed files with 4 additions and 1 deletions
4
api.go
4
api.go
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const bearerToken string = "AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA"
|
const bearerToken string = "AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA"
|
||||||
|
|
@ -23,7 +24,7 @@ var cacheIDs sync.Map
|
||||||
|
|
||||||
// RequestAPI get JSON from frontend API and decodes it
|
// RequestAPI get JSON from frontend API and decodes it
|
||||||
func (s *Scraper) RequestAPI(req *http.Request, target interface{}) error {
|
func (s *Scraper) RequestAPI(req *http.Request, target interface{}) error {
|
||||||
if s.guestToken == "" {
|
if s.guestToken == "" || s.guestCreatedAt.Before(time.Now().Add(-time.Hour*3)) {
|
||||||
err := s.GetGuestToken()
|
err := s.GetGuestToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -76,6 +77,7 @@ func (s *Scraper) GetGuestToken() error {
|
||||||
if s.guestToken, ok = jsn["guest_token"].(string); !ok {
|
if s.guestToken, ok = jsn["guest_token"].(string); !ok {
|
||||||
return fmt.Errorf("guest_token not found")
|
return fmt.Errorf("guest_token not found")
|
||||||
}
|
}
|
||||||
|
s.guestCreatedAt = time.Now()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import (
|
||||||
type Scraper struct {
|
type Scraper struct {
|
||||||
client *http.Client
|
client *http.Client
|
||||||
guestToken string
|
guestToken string
|
||||||
|
guestCreatedAt time.Time
|
||||||
includeReplies bool
|
includeReplies bool
|
||||||
searchMode SearchMode
|
searchMode SearchMode
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue