Skip to content

Commit

Permalink
chore: remove cookie jar.
Browse files Browse the repository at this point in the history
  • Loading branch information
syhily committed Nov 20, 2022
1 parent 7b68831 commit df08035
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 137 deletions.
26 changes: 6 additions & 20 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package client
import (
"errors"
"fmt"
"net/http"
"net/url"
"os"
"path/filepath"
Expand All @@ -19,7 +18,6 @@ var (
)

const (
CookieFile = "cookies.json"
DefaultUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko)" +
" Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.42"
)
Expand Down Expand Up @@ -55,15 +53,6 @@ func (c *Config) ConfigPath() (string, error) {
return mkdir(filepath.Join(c.ConfigRoot, c.Host))
}

func (c *Config) newCookieJar() (http.CookieJar, error) {
configPath, err := c.ConfigPath()
if err != nil {
return nil, err
}

return newCookieJar(filepath.Join(configPath, CookieFile))
}

func (c *Config) redirectPolicy() []any {
policies := []any{
resty.FlexibleRedirectPolicy(5),
Expand Down Expand Up @@ -154,10 +143,14 @@ func New(c *Config) (*Client, error) {
SetAllowGetMethodPayload(true).
SetTimeout(5*time.Minute).
SetContentLength(true).
SetDebug(log.EnableDebug).
SetDisableWarn(true).
SetHeader("User-Agent", c.userAgent())

if !log.EnableDebug {
client.DisableTrace().SetDebug(false).SetDisableWarn(true)
} else {
client.SetDebug(true).SetDisableWarn(false)
}

if c.Host != "" {
client.SetBaseURL(c.baseURL())
}
Expand All @@ -166,13 +159,6 @@ func New(c *Config) (*Client, error) {
client.SetRedirectPolicy(c.redirectPolicy()...)
}

// Setting the cookiejar
cookieJar, err := c.newCookieJar()
if err != nil {
return nil, err
}
client.SetCookieJar(cookieJar)

// Setting the proxy for the resty client.
// The proxy environment is also supported.
if c.Proxy != "" {
Expand Down
101 changes: 0 additions & 101 deletions internal/client/cookie.go

This file was deleted.

16 changes: 0 additions & 16 deletions internal/fetcher/tianlang.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package fetcher

import (
"fmt"
"os"
"path/filepath"
"strconv"
"strings"

Expand All @@ -20,23 +18,9 @@ func newTianlangService(config *Config) (service, error) {
return tianlangLinkResolver(config, c, id)
}

if err := cleanStaleCookies(config); err != nil {
return nil, err
}

return newWordpressService(config, resolver)
}

func cleanStaleCookies(config *Config) error {
path, err := config.Config.ConfigPath()
if err != nil {
return err
}

_ = os.Remove(filepath.Join(path, client.CookieFile))
return nil
}

func tianlangLinkResolver(config *Config, c *client.Client, id int64) (map[driver.Source]wordpress.ShareLink, error) {
resp, err := c.R().
SetPathParam("id", strconv.FormatInt(id, 10)).
Expand Down

0 comments on commit df08035

Please sign in to comment.