11use chrono:: { DateTime , Utc } ;
22use log:: { debug, warn} ;
33use playmatch_client:: Client ;
4+ use playmatch_client:: types:: MetadataProvider ;
45
5- pub struct IgdbGameInfo {
6- pub name : String ,
7- pub page_url : String ,
8- pub summary : Option < String > ,
9- pub first_release_date : Option < DateTime < Utc > > ,
10- pub cover_url : Option < String > ,
11- pub screenshot_urls : Vec < String > ,
12- }
13-
14- pub struct IgdbCompanyInfo {
15- pub name : String ,
16- pub page_url : Option < String > ,
17- pub logo_url : Option < String > ,
18- pub description : Option < String > ,
19- }
20-
21- pub struct IgdbPlatformInfo {
22- pub name : String ,
23- pub page_url : String ,
24- pub logo_url : Option < String > ,
25- pub summary : Option < String > ,
26- }
27-
28- const SUMMARY_MAX : usize = 280 ;
6+ use super :: { ProviderCompanyInfo , ProviderGameInfo , ProviderPlatformInfo , truncate_summary} ;
297
308fn normalize_image_url ( raw : & str , size : & str ) -> String {
319 let https = if let Some ( rest) = raw. strip_prefix ( "//" ) {
@@ -38,20 +16,11 @@ fn normalize_image_url(raw: &str, size: &str) -> String {
3816 https. replacen ( "t_thumb" , size, 1 )
3917}
4018
41- fn truncate_summary ( s : & str ) -> String {
42- if s. chars ( ) . count ( ) <= SUMMARY_MAX {
43- s. to_string ( )
44- } else {
45- let truncated: String = s. chars ( ) . take ( SUMMARY_MAX - 1 ) . collect ( ) ;
46- format ! ( "{truncated}…" )
47- }
48- }
49-
5019fn timestamp_to_datetime ( ts : i64 ) -> Option < DateTime < Utc > > {
5120 DateTime :: < Utc > :: from_timestamp ( ts, 0 )
5221}
5322
54- pub async fn fetch_game ( client : & Client , provider_id : & str ) -> Option < IgdbGameInfo > {
23+ pub async fn fetch_game ( client : & Client , provider_id : & str ) -> Option < ProviderGameInfo > {
5524 let id: i32 = match provider_id. parse ( ) {
5625 Ok ( id) => id,
5726 Err ( e) => {
@@ -110,17 +79,18 @@ pub async fn fetch_game(client: &Client, provider_id: &str) -> Option<IgdbGameIn
11079 }
11180 }
11281
113- Some ( IgdbGameInfo {
82+ Some ( ProviderGameInfo {
83+ provider : MetadataProvider :: Igdb ,
11484 name : game. name ,
115- page_url : game. url ,
85+ page_url : Some ( game. url ) ,
11686 summary : game. summary . map ( |s| truncate_summary ( & s) ) ,
11787 first_release_date : game. first_release_date . and_then ( timestamp_to_datetime) ,
11888 cover_url,
11989 screenshot_urls,
12090 } )
12191}
12292
123- pub async fn fetch_company ( client : & Client , provider_id : & str ) -> Option < IgdbCompanyInfo > {
93+ pub async fn fetch_company ( client : & Client , provider_id : & str ) -> Option < ProviderCompanyInfo > {
12494 let id: i32 = match provider_id. parse ( ) {
12595 Ok ( id) => id,
12696 Err ( e) => {
@@ -157,15 +127,16 @@ pub async fn fetch_company(client: &Client, provider_id: &str) -> Option<IgdbCom
157127 None => None ,
158128 } ;
159129
160- Some ( IgdbCompanyInfo {
130+ Some ( ProviderCompanyInfo {
131+ provider : MetadataProvider :: Igdb ,
161132 name : company. name ,
162133 page_url : company. url ,
163134 logo_url,
164135 description : company. description . map ( |s| truncate_summary ( & s) ) ,
165136 } )
166137}
167138
168- pub async fn fetch_platform ( client : & Client , provider_id : & str ) -> Option < IgdbPlatformInfo > {
139+ pub async fn fetch_platform ( client : & Client , provider_id : & str ) -> Option < ProviderPlatformInfo > {
169140 let id: i32 = match provider_id. parse ( ) {
170141 Ok ( id) => id,
171142 Err ( e) => {
@@ -202,9 +173,10 @@ pub async fn fetch_platform(client: &Client, provider_id: &str) -> Option<IgdbPl
202173 None => None ,
203174 } ;
204175
205- Some ( IgdbPlatformInfo {
176+ Some ( ProviderPlatformInfo {
177+ provider : MetadataProvider :: Igdb ,
206178 name : platform. name ,
207- page_url : platform. url ,
179+ page_url : Some ( platform. url ) ,
208180 logo_url,
209181 summary : platform. summary . map ( |s| truncate_summary ( & s) ) ,
210182 } )
0 commit comments