11use crate :: model:: { macros, EpgConfig , PanelApiConfig } ;
2+ use crate :: repository:: get_csv_file_path;
23use chrono:: Utc ;
34use log:: warn;
5+ use shared:: check_input_credentials;
46use shared:: error:: TuliproxError ;
57use shared:: model:: { ConfigInputAliasDto , ConfigInputDto , ConfigInputOptionsDto , InputFetchMethod , InputType , StagedInputDto } ;
68use shared:: utils:: { get_credentials_from_url, Internable } ;
79use shared:: { check_input_connections, info_err_res, write_if_some} ;
8- use shared:: check_input_credentials;
910use std:: collections:: HashMap ;
1011use std:: fmt;
1112use std:: path:: PathBuf ;
1213use std:: sync:: Arc ;
1314use url:: Url ;
14- use crate :: repository:: get_csv_file_path;
1515
1616#[ allow( clippy:: struct_excessive_bools) ]
1717#[ derive( Debug , Clone ) ]
@@ -105,6 +105,7 @@ pub struct ConfigInputAlias {
105105 pub priority : i16 ,
106106 pub max_connections : u16 ,
107107 pub exp_date : Option < i64 > ,
108+ pub enabled : bool ,
108109}
109110
110111macros:: from_impl!( ConfigInputAlias ) ;
@@ -119,6 +120,7 @@ impl From<&ConfigInputAliasDto> for ConfigInputAlias {
119120 priority : dto. priority ,
120121 max_connections : dto. max_connections ,
121122 exp_date : dto. exp_date ,
123+ enabled : dto. enabled ,
122124 }
123125 }
124126}
@@ -165,6 +167,15 @@ impl ConfigInput {
165167 self . enabled = false ;
166168 }
167169
170+ if let Some ( aliases) = & mut self . aliases {
171+ for alias in aliases {
172+ if is_input_expired ( alias. exp_date ) {
173+ warn ! ( "Account {} expired for provider: {}" , alias. username. as_ref( ) . map_or( "?" , |s| s. as_str( ) ) , alias. name) ;
174+ alias. enabled = false ;
175+ }
176+ }
177+ }
178+
168179 if let Some ( panel_api) = & mut self . panel_api {
169180 panel_api. prepare ( ) ?;
170181 }
@@ -210,15 +221,20 @@ impl ConfigInput {
210221 }
211222
212223 if !aliases. is_empty ( ) {
213- let mut first = aliases. remove ( 0 ) ;
214- self . id = first. id ;
215- self . username = first. username . take ( ) ;
216- self . password = first. password . take ( ) ;
217- self . url = first. url . trim ( ) . to_string ( ) ;
218- self . max_connections = first. max_connections ;
219- self . priority = first. priority ;
220- if self . name . is_empty ( ) {
221- self . name . clone_from ( & first. name ) ;
224+ if let Some ( index) = aliases. iter ( ) . position ( |alias| alias. enabled ) {
225+ let mut first = aliases. remove ( index) ;
226+ self . id = first. id ;
227+ self . username = first. username . take ( ) ;
228+ self . password = first. password . take ( ) ;
229+ self . url = first. url . trim ( ) . to_string ( ) ;
230+ self . max_connections = first. max_connections ;
231+ self . priority = first. priority ;
232+ self . enabled = first. enabled ;
233+ if self . name . is_empty ( ) {
234+ self . name . clone_from ( & first. name ) ;
235+ }
236+ } else {
237+ self . enabled = false ;
222238 }
223239 }
224240 }
@@ -254,6 +270,23 @@ impl ConfigInput {
254270 cache_duration_seconds : self . cache_duration_seconds ,
255271 }
256272 }
273+
274+ pub fn has_enabled_aliases ( & self ) -> bool {
275+ self . aliases
276+ . as_ref ( )
277+ . is_some_and ( |aliases| aliases. iter ( ) . any ( |a| a. enabled ) )
278+ }
279+
280+ pub fn get_enabled_aliases ( & self ) -> Option < Vec < & ConfigInputAlias > > {
281+ self . aliases . as_ref ( ) . map_or ( None , |aliases| {
282+ let result: Vec < _ > = aliases. iter ( ) . filter ( |alias| alias. enabled ) . collect ( ) ;
283+ if result. is_empty ( ) {
284+ None
285+ } else {
286+ Some ( result)
287+ }
288+ } )
289+ }
257290}
258291
259292macros:: from_impl!( ConfigInput ) ;
0 commit comments