Skip to content

Commit

Permalink
fix: Adjusted Pixiv for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
XangelMusic committed Jun 7, 2024
1 parent 5ec4c05 commit 69f8a6d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions artworks/artstation/artstation_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ func TestArtstation(t *testing.T) {
var _ = DescribeTable(
"Match Artstation URL",
func(url string, expectedID string, expectedResult bool) {
as := artstation.New()
provider := artstation.New()

id, ok := as.Match(url)
id, ok := provider.Match(url)
Expect(id).To(BeEquivalentTo(expectedID))
Expect(ok).To(BeEquivalentTo(expectedResult))
},
Expand Down
9 changes: 6 additions & 3 deletions artworks/pixiv/pixiv.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ type Image struct {
Original string
}

func New(proxyHost, authToken, refreshToken string) (artworks.Provider, error) {
func LoadAuth(authToken, refreshToken string) error {
_, err := pixiv.LoadAuth(authToken, refreshToken, time.Now())
if err != nil {
return nil, err
return err
}
return nil
}

func New(proxyHost string) artworks.Provider {
if proxyHost == "" {
proxyHost = "https://boetea.dev"
}
Expand All @@ -58,7 +61,7 @@ func New(proxyHost, authToken, refreshToken string) (artworks.Provider, error) {
app: pixiv.NewApp(),
proxyHost: proxyHost,
regex: regexp.MustCompile(`(?i)https?://(?:www\.)?pixiv\.net/(?:en/)?(?:artworks/|member_illust\.php\?)(?:mode=medium&)?(?:illust_id=)?([0-9]+)`),
}, nil
}
}

func (p *Pixiv) Match(s string) (string, bool) {
Expand Down
2 changes: 1 addition & 1 deletion artworks/pixiv/pixiv_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestPixiv(t *testing.T) {
var _ = DescribeTable(
"Match Pixiv URL",
func(url string, expectedID string, expectedResult bool) {
provider := pixiv.Pixiv{}
provider := pixiv.New("")

id, ok := provider.Match(url)
Expect(id).To(BeEquivalentTo(expectedID))
Expand Down
4 changes: 2 additions & 2 deletions cmd/boetea/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ func main() {
b.AddProvider(twitter.New())
b.AddProvider(deviant.New())

if pixiv, err := pixiv.New(cfg.Pixiv.ProxyHost, cfg.Pixiv.AuthToken, cfg.Pixiv.RefreshToken); err == nil {
if err := pixiv.LoadAuth(cfg.Pixiv.AuthToken, cfg.Pixiv.RefreshToken); err == nil {
log.Info("Successfully logged into Pixiv.")
b.AddProvider(pixiv)
b.AddProvider(pixiv.New(cfg.Pixiv.ProxyHost))
}

b.AddRouter(&gumi.Router{
Expand Down

0 comments on commit 69f8a6d

Please sign in to comment.