Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement imgur.io resolving #365

Merged
merged 11 commits into from
Oct 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- Dev: Improve FrankerFaceZ tests. (#295)
- Dev: Improve Livestreamfails tests. (#297, #301)
- Dev: Improve default resolver tests. (#300)
- Dev: Resolve imgur.io links. (#365)

## 1.2.3

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/golang/mock v1.6.0
github.com/jackc/pgconn v1.13.0
github.com/jackc/pgx/v4 v4.17.2
github.com/koffeinsource/go-imgur v0.4.0
github.com/koffeinsource/go-imgur v0.4.1
github.com/nicklaw5/helix v1.25.0
github.com/pashagolub/pgxmock v1.8.0
github.com/patrickmn/go-cache v2.1.0+incompatible
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/X
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/koffeinsource/go-imgur v0.4.0 h1:xQSun+7yvQkYIm0Y7wjfIj5fp4A8fJWMhL5VBtFTYxA=
github.com/koffeinsource/go-imgur v0.4.0/go.mod h1:Zwyz9VDJVekCxMfxx6psjijDZOUyzkNCia9YYWkjp60=
github.com/koffeinsource/go-imgur v0.4.1 h1:31mMPGi1QI4/awe1iOWJpcdv9G2TUaYB34RpYfWpz9M=
github.com/koffeinsource/go-imgur v0.4.1/go.mod h1:Zwyz9VDJVekCxMfxx6psjijDZOUyzkNCia9YYWkjp60=
github.com/koffeinsource/go-klogger v0.1.1 h1:FImHHVcDwEV4Ze3uOtRmBTQdJdzuBHtrvR4B8ssKkbw=
github.com/koffeinsource/go-klogger v0.1.1/go.mod h1:oqHKXZOZt4uktar7WIYuEyWJRRlrkRSX+Uj1DWGZ79I=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
Expand Down
6 changes: 4 additions & 2 deletions internal/logger/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ var (
)

func FromContext(ctx context.Context) Logger {
if v := ctx.Value(contextKey); v != nil {
return v.(Logger)
if ctx != nil {
if v := ctx.Value(contextKey); v != nil {
return v.(Logger)
}
}

log.Fatal("No logger found in context")
Expand Down
16 changes: 15 additions & 1 deletion internal/resolvers/imgur/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"github.com/koffeinsource/go-imgur"
)

var VALID_IMGUR_DOMAINS = []string{"imgur.com", "imgur.io"}

type ImgurClient interface {
GetInfoFromURL(urlString string) (*imgur.GenericInfo, int, error)
}
Expand All @@ -27,7 +29,19 @@ type Resolver struct {
}

func (r *Resolver) Check(ctx context.Context, url *url.URL) (context.Context, bool) {
return ctx, utils.IsSubdomainOf(url, "imgur.com")
for _, domain := range VALID_IMGUR_DOMAINS {
result := utils.IsSubdomainOf(url, domain)
if result {
return ctx, result
}

result = utils.IsDomain(url, domain)
if result {
return ctx, result
}
}

return ctx, false
}

func (r *Resolver) Run(ctx context.Context, url *url.URL, req *http.Request) (*cache.Response, error) {
Expand Down