1313using JacRed . Models . Details ;
1414using JacRed . Models . Tracks ;
1515using JacRed . Models . Api ;
16+ using Microsoft . AspNetCore . Http ;
1617
1718namespace JacRed . Controllers
1819{
@@ -24,6 +25,30 @@ public ActionResult Index()
2425 return File ( System . IO . File . OpenRead ( "wwwroot/index.html" ) , "text/html" ) ;
2526 }
2627
28+ [ Route ( "health" ) ]
29+ public IActionResult Health ( )
30+ {
31+ return Json ( new Dictionary < string , string >
32+ {
33+ [ "status" ] = "OK"
34+ } ) ;
35+ }
36+
37+ [ Route ( "version" ) ]
38+ public ActionResult Version ( )
39+ {
40+ return Content ( "11" , contentType : "text/plain; charset=utf-8" ) ;
41+ }
42+
43+ [ Route ( "lastupdatedb" ) ]
44+ public ActionResult LastUpdateDB ( )
45+ {
46+ if ( FileDB . masterDb == null || FileDB . masterDb . Count == 0 )
47+ return Content ( "01.01.2000 01:01" , contentType : "text/plain; charset=utf-8" ) ;
48+
49+ return Content ( FileDB . masterDb . OrderByDescending ( i => i . Value . updateTime ) . First ( ) . Value . updateTime . ToString ( "dd.MM.yyyy HH:mm" ) , contentType : "text/plain; charset=utf-8" ) ;
50+ }
51+
2752 [ Route ( "api/v1.0/conf" ) ]
2853 public JsonResult JacRedConf ( string apikey )
2954 {
@@ -107,6 +132,9 @@ void AddTorrents(TorrentDetails t)
107132 if ( AppInit . conf . synctrackers != null && ! AppInit . conf . synctrackers . Contains ( t . trackerName ) )
108133 return ;
109134
135+ if ( AppInit . conf . disable_trackers != null && AppInit . conf . disable_trackers . Contains ( t . trackerName ) )
136+ return ;
137+
110138 if ( torrents . TryGetValue ( t . url , out TorrentDetails val ) )
111139 {
112140 if ( t . updateTime > val . updateTime )
@@ -665,6 +693,9 @@ void AddTorrents(TorrentDetails t)
665693 if ( AppInit . conf . synctrackers != null && ! AppInit . conf . synctrackers . Contains ( t . trackerName ) )
666694 return ;
667695
696+ if ( AppInit . conf . disable_trackers != null && AppInit . conf . disable_trackers . Contains ( t . trackerName ) )
697+ return ;
698+
668699 if ( torrents . TryGetValue ( t . url , out TorrentDetails val ) )
669700 {
670701 if ( t . updateTime > val . updateTime )
@@ -793,6 +824,102 @@ void AddTorrents(TorrentDetails t)
793824 }
794825 #endregion
795826
827+ #region Qualitys
828+ [ Route ( "/api/v1.0/qualitys" ) ]
829+ public JsonResult Qualitys ( string name , string originalname , string type , int page = 1 , int take = 1000 )
830+ {
831+ var torrents = new Dictionary < string , Dictionary < int , Models . TorrentQuality > > ( ) ;
832+
833+ #region AddTorrents
834+ void AddTorrents ( TorrentDetails t )
835+ {
836+ if ( t ? . types == null || t . types . Contains ( "sport" ) || t . relased == 0 )
837+ return ;
838+
839+ if ( ! string . IsNullOrEmpty ( type ) && ! t . types . Contains ( type ) )
840+ return ;
841+
842+ string key = $ "{ StringConvert . SearchName ( t . name ) } :{ StringConvert . SearchName ( t . originalname ) } ";
843+
844+ var langs = t . languages ;
845+
846+ if ( t . ffprobe != null || ! AppInit . conf . tracks )
847+ langs = TracksDB . Languages ( t , t . ffprobe ) ;
848+ else
849+ {
850+ var streams = TracksDB . Get ( t . magnet , t . types ) ;
851+ langs = TracksDB . Languages ( t , streams ?? t . ffprobe ) ;
852+ }
853+
854+ var model = new Models . TorrentQuality ( )
855+ {
856+ types = t . types . ToHashSet ( ) ,
857+ createTime = t . createTime ,
858+ updateTime = t . updateTime ,
859+ languages = langs ?? new HashSet < string > ( ) ,
860+ qualitys = new HashSet < int > ( ) { t . quality }
861+ } ;
862+
863+ if ( torrents . TryGetValue ( key , out Dictionary < int , Models . TorrentQuality > val ) )
864+ {
865+ if ( val . TryGetValue ( t . relased , out Models . TorrentQuality _md ) )
866+ {
867+ if ( langs != null )
868+ {
869+ foreach ( var item in langs )
870+ _md . languages . Add ( item ) ;
871+ }
872+
873+ if ( t . types != null )
874+ {
875+ foreach ( var item in t . types )
876+ _md . types . Add ( item ) ;
877+ }
878+
879+ _md . qualitys . Add ( t . quality ) ;
880+
881+ if ( _md . createTime > t . createTime )
882+ _md . createTime = t . createTime ;
883+
884+ if ( t . updateTime > _md . updateTime )
885+ _md . updateTime = t . updateTime ;
886+
887+ val [ t . relased ] = _md ;
888+ }
889+ else
890+ {
891+ val . TryAdd ( t . relased , model ) ;
892+ }
893+
894+ torrents [ key ] = val ;
895+ }
896+ else
897+ {
898+ torrents . TryAdd ( key , new Dictionary < int , Models . TorrentQuality > ( ) { [ t . relased ] = model } ) ;
899+ }
900+ }
901+ #endregion
902+
903+ string _s = StringConvert . SearchName ( name ) ;
904+ string _so = StringConvert . SearchName ( originalname ) ;
905+
906+ var mdb = FileDB . masterDb . OrderByDescending ( i => i . Value . updateTime ) . Where ( i => ( _s == null && _so == null ) || ( _s != null && i . Key . Contains ( _s ) ) || ( _so != null && i . Key . Contains ( _so ) ) ) ;
907+ if ( ! AppInit . conf . evercache . enable || AppInit . conf . evercache . validHour > 0 )
908+ mdb = mdb . Take ( AppInit . conf . maxreadfile ) ;
909+
910+ foreach ( var val in mdb )
911+ {
912+ foreach ( var t in FileDB . OpenRead ( val . Key , true ) . Values )
913+ AddTorrents ( t ) ;
914+ }
915+
916+ if ( take == - 1 )
917+ return Json ( torrents ) ;
918+
919+ return Json ( torrents . Skip ( ( page * take ) - take ) . Take ( take ) ) ;
920+ }
921+ #endregion
922+
796923
797924 #region getFastdb
798925 static Dictionary < string , List < string > > _fastdb = null ;
0 commit comments