-
-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
data: rewrite twitch-search-channel model
- Loading branch information
1 parent
12534fd
commit d1d935e
Showing
13 changed files
with
383 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,84 @@ | ||
import { computed } from "@ember/object"; | ||
import { inject as service } from "@ember/service"; | ||
import attr from "ember-data/attr"; | ||
import Model from "ember-data/model"; | ||
import { belongsTo } from "ember-data/relationships"; | ||
import { DEFAULT_VODCAST_REGEXP } from "data/models/settings/streams/fragment"; | ||
|
||
|
||
export default Model.extend({ | ||
channel: belongsTo( "twitchChannel", { async: false } ) | ||
// noinspection JSValidateTypes | ||
export default Model.extend( /** @class TwitchSearchChannel */ { | ||
/** @type {IntlService} */ | ||
intl: service(), | ||
/** @type {SettingsService} */ | ||
settings: service(), | ||
|
||
/** @type {TwitchUser} */ | ||
user: belongsTo( "twitch-user", { async: true } ), | ||
/** @type {string} */ | ||
broadcaster_language: attr( "string" ), | ||
/** @type {string} */ | ||
broadcaster_login: attr( "string" ), | ||
/** @type {string} */ | ||
display_name: attr( "string" ), | ||
/** @type {string} */ | ||
game: belongsTo( "twitch-game", { async: true } ), | ||
/** @type {string} */ | ||
game_name: attr( "string" ), | ||
/** @type {boolean} */ | ||
is_live: attr( "boolean" ), | ||
//** @type {TwitchStreamTag[]} */ | ||
//tag_ids: hasMany( "twitch-stream-tag", { async: true } ), | ||
/** @type {string} */ | ||
thumbnail_url: attr( "string" ), | ||
/** @type {string} */ | ||
title: attr( "string" ), | ||
/** @type {Date} */ | ||
started_at: attr( "date" ), | ||
|
||
|
||
/** @type {(null|RegExp)} */ | ||
reVodcast: computed( "settings.content.streams.vodcast_regexp", function() { | ||
/** @this {TwitchStream} */ | ||
const vodcast_regexp = this.settings.content.streams.vodcast_regexp; | ||
|
||
if ( vodcast_regexp.length && !vodcast_regexp.trim().length ) { | ||
return null; | ||
} | ||
try { | ||
return new RegExp( vodcast_regexp || DEFAULT_VODCAST_REGEXP, "i" ); | ||
} catch ( e ) { | ||
return null; | ||
} | ||
}), | ||
|
||
/** @type {boolean} */ | ||
isVodcast: computed( "reVodcast", "title", function() { | ||
/** @this {TwitchStream} */ | ||
const { reVodcast, title } = this; | ||
|
||
return reVodcast && title && reVodcast.test( title ); | ||
}), | ||
|
||
/** @type {string} */ | ||
titleStartedAt: computed( "intl.locale", "started_at", function() { | ||
/** @this {TwitchStream} */ | ||
const { started_at } = this; | ||
return !started_at | ||
? this.intl.t( | ||
"models.twitch.search-channel.started-at.offline" | ||
) | ||
: new Date() - started_at < 24 * 3600 * 1000 | ||
? this.intl.t( | ||
"models.twitch.search-channel.started-at.less-than-24h", | ||
{ started_at } | ||
) | ||
: this.intl.t( | ||
"models.twitch.search-channel.started-at.more-than-24h", | ||
{ started_at } | ||
); | ||
}) | ||
|
||
}).reopenClass({ | ||
toString() { return "kraken/search/channels"; } | ||
toString() { return "helix/search/channels"; } | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
search-channel: | ||
request: | ||
method: "GET" | ||
url: "https://api.twitch.tv/helix/search/channels" | ||
query: | ||
query: "foo" | ||
live_only: true | ||
response: | ||
data: | ||
- id: "1" | ||
broadcaster_language: "en" | ||
broadcaster_login: "foo" | ||
display_name: "FOO" | ||
game_id: "1" | ||
game_name: "some game" | ||
is_live: true | ||
tag_ids: [] | ||
thumbnail_url: "https://localhost/data/twitch-search-stream/1/thumbnail-{width}x{height}.jpg" | ||
title: "some title" | ||
started_at: "2000-01-01T00:00:00Z" | ||
- id: "2" | ||
broadcaster_language: "de" | ||
broadcaster_login: "bar" | ||
display_name: "BAR" | ||
game_id: "2" | ||
game_name: "another game" | ||
is_live: true | ||
tag_ids: [] | ||
thumbnail_url: "https://localhost/data/twitch-search-stream/2/thumbnail-{width}x{height}.jpg" | ||
title: "another title" | ||
started_at: "1999-12-31T23:59:59Z" | ||
pagination: {} | ||
user: | ||
request: | ||
method: "GET" | ||
url: "https://api.twitch.tv/helix/users" | ||
query: | ||
id: "1,2" | ||
response: | ||
data: | ||
- id: "1" | ||
- id: "2" | ||
game: | ||
request: | ||
method: "GET" | ||
url: "https://api.twitch.tv/helix/games" | ||
query: | ||
id: "1,2" | ||
response: | ||
data: | ||
- id: "1" | ||
- id: "2" |
Oops, something went wrong.