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

Fix Twitch clip domains #189

Merged
merged 3 commits into from
Jul 4, 2021
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 @@ -2,6 +2,7 @@

## Unreleased

- Twitch clips under `www.twitch.tv` domain work again. (#189)
- Imgur thumbnails are now proxied as well. (#187)
- Added link preview support for 7tv emote links. (#155)
- Skip lilliput if image is below maxThumbnailSize. (#184)
Expand Down
17 changes: 9 additions & 8 deletions internal/resolvers/twitch/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net/url"
"regexp"

"github.com/Chatterino/api/pkg/utils"
"github.com/Chatterino/api/pkg/resolver"
)

var (
Expand All @@ -19,17 +19,18 @@ func check(url *url.URL) bool {
return false
}

match, domain := resolver.MatchesHosts(url, domains)
if !match {
return false
}

// Find clips that look like https://clips.twitch.tv/SlugHere
if utils.IsDomain(url, "clips.twitch.tv") {
if domain == "clips.twitch.tv" {
zneix marked this conversation as resolved.
Show resolved Hide resolved
// matches[1] contains "StreamerName/clip/" - we don't want it in this check though
return matches[1] == ""
}

// Find clips that look like https://twitch.tv/StreamerName/clip/SlugHere
if utils.IsDomain(url, "twitch.tv") {
// matches[1] contains "StreamerName/clip/" - we need it in this check
return matches[1] != ""
}

return false
// matches[1] contains "StreamerName/clip/" - we need it in this check
return matches[1] != ""
}
6 changes: 6 additions & 0 deletions internal/resolvers/twitch/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ var (

twitchClipsTooltip = template.Must(template.New("twitchclipsTooltip").Parse(twitchClipsTooltipString))

domains = map[string]struct{}{
"twitch.tv": {},
"www.twitch.tv": {},
"clips.twitch.tv": {},
}

clipCache = cache.New("twitchclip", load, 1*time.Hour)

helixAPI TwitchAPIClient
Expand Down