@@ -2,14 +2,14 @@ package bizsteam
22
33import (
44 "context"
5- "errors"
65 "fmt"
76 "strconv"
87 "strings"
98
109 "github.com/tuihub/librarian/app/porter/internal/client/steam"
1110 "github.com/tuihub/librarian/app/porter/internal/client/steam/model"
12- "github.com/tuihub/librarian/app/porter/internal/data"
11+
12+ "github.com/go-kratos/kratos/v2/errors"
1313)
1414
1515type User struct {
@@ -58,16 +58,26 @@ type SteamUseCase struct {
5858 c * steam.Steam
5959}
6060
61- func NewSteamUseCase (client * steam.Steam , _ * data.Data ) * SteamUseCase {
61+ func NewSteamUseCase (client * steam.Steam ) * SteamUseCase {
62+ if ! client .FeatureEnabled () {
63+ return new (SteamUseCase )
64+ }
6265 return & SteamUseCase {c : client }
6366}
6467
68+ func (s * SteamUseCase ) FeatureEnabled () bool {
69+ return s .c != nil
70+ }
71+
6572func (s * SteamUseCase ) GetUser (ctx context.Context , steamID string ) (* User , error ) {
73+ if ! s .FeatureEnabled () {
74+ return nil , errors .BadRequest ("request disabled feature" , "" )
75+ }
6676 id , err := strconv .ParseUint (steamID , 10 , 64 )
6777 if err != nil {
6878 return nil , err
6979 }
70- resp , err := s .c .WebAPI . GetPlayerSummary (ctx , model.GetPlayerSummariesRequest {
80+ resp , err := s .c .GetPlayerSummary (ctx , model.GetPlayerSummariesRequest {
7181 SteamID : id ,
7282 })
7383 if err != nil {
@@ -82,11 +92,14 @@ func (s *SteamUseCase) GetUser(ctx context.Context, steamID string) (*User, erro
8292}
8393
8494func (s * SteamUseCase ) GetOwnedGames (ctx context.Context , steamID string ) ([]* App , error ) {
95+ if ! s .FeatureEnabled () {
96+ return nil , errors .BadRequest ("request disabled feature" , "" )
97+ }
8598 id , err := strconv .ParseUint (steamID , 10 , 64 )
8699 if err != nil {
87100 return nil , err
88101 }
89- resp , err := s .c .WebAPI . GetOwnedGames (ctx , model.GetOwnedGamesRequest {
102+ resp , err := s .c .GetOwnedGames (ctx , model.GetOwnedGamesRequest {
90103 SteamID : id ,
91104 IncludeAppInfo : true ,
92105 IncludePlayedFreeGames : true ,
@@ -117,7 +130,10 @@ func (s *SteamUseCase) GetOwnedGames(ctx context.Context, steamID string) ([]*Ap
117130}
118131
119132func (s * SteamUseCase ) GetAppDetails (ctx context.Context , appID int ) (* App , error ) {
120- resp , err := s .c .StoreAPI .GetAppDetails (ctx , model.GetAppDetailsRequest {
133+ if ! s .FeatureEnabled () {
134+ return nil , errors .BadRequest ("request disabled feature" , "" )
135+ }
136+ resp , err := s .c .GetAppDetails (ctx , model.GetAppDetailsRequest {
121137 AppIDs : []int {appID },
122138 CountryCode : "" ,
123139 Language : "" ,
@@ -126,7 +142,7 @@ func (s *SteamUseCase) GetAppDetails(ctx context.Context, appID int) (*App, erro
126142 return nil , err
127143 }
128144 if len (resp ) != 1 {
129- return nil , errors .New ("unexpected result" )
145+ return nil , errors .InternalServer ("unexpected result" , " " )
130146 }
131147 var res * App
132148 for _ , app := range resp {
0 commit comments