HEAVY: migrate accounts and logs to service/repo architecture
This commit is contained in:
parent
5c255fb34b
commit
49e14b5bc5
37 changed files with 1019 additions and 687 deletions
|
|
@ -1,7 +1,8 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"arimelody-web/model"
|
||||
"arimelody-web/model/app"
|
||||
"arimelody-web/model/twitch"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
|
@ -11,13 +12,13 @@ import (
|
|||
|
||||
const TWITCH_API_BASE = "https://api.twitch.tv/helix/"
|
||||
|
||||
func TwitchSetup(app *model.AppState) error {
|
||||
app.Twitch = &model.TwitchState{}
|
||||
func TwitchSetup(app *app.AppState) error {
|
||||
app.Twitch = &twitch.State{}
|
||||
err := RefreshTwitchToken(app)
|
||||
return err
|
||||
}
|
||||
|
||||
func RefreshTwitchToken(app *model.AppState) error {
|
||||
func RefreshTwitchToken(app *app.AppState) error {
|
||||
if app.Twitch != nil && app.Twitch.Token != nil && time.Now().UTC().After(app.Twitch.Token.ExpiresAt) {
|
||||
return nil
|
||||
}
|
||||
|
|
@ -45,7 +46,7 @@ func RefreshTwitchToken(app *model.AppState) error {
|
|||
return err
|
||||
}
|
||||
|
||||
app.Twitch.Token = &model.TwitchOAuthToken{
|
||||
app.Twitch.Token = &twitch.OAuthToken{
|
||||
AccessToken: oauthResponse.AccessToken,
|
||||
ExpiresAt: time.Now().UTC().Add(time.Second * time.Duration(oauthResponse.ExpiresIn)).UTC(),
|
||||
TokenType: oauthResponse.TokenType,
|
||||
|
|
@ -54,10 +55,10 @@ func RefreshTwitchToken(app *model.AppState) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
var lastStreamState *model.TwitchStreamInfo
|
||||
var lastStreamState *twitch.StreamInfo
|
||||
var lastStreamStateAt time.Time
|
||||
|
||||
func GetTwitchStatus(app *model.AppState, broadcaster string) (*model.TwitchStreamInfo, error) {
|
||||
func GetTwitchStatus(app *app.AppState, broadcaster string) (*twitch.StreamInfo, error) {
|
||||
if lastStreamState != nil && time.Now().UTC().Before(lastStreamStateAt.Add(time.Minute)) {
|
||||
return lastStreamState, nil
|
||||
}
|
||||
|
|
@ -76,7 +77,7 @@ func GetTwitchStatus(app *model.AppState, broadcaster string) (*model.TwitchStre
|
|||
}
|
||||
|
||||
type StreamsResponse struct {
|
||||
Data []model.TwitchStreamInfo `json:"data"`
|
||||
Data []twitch.StreamInfo `json:"data"`
|
||||
}
|
||||
streamInfo := StreamsResponse{}
|
||||
err = json.NewDecoder(res.Body).Decode(&streamInfo)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue