@@ -16,27 +16,40 @@ class APIList extends API {
1616 protected function handleAPITask () : void {
1717 $ groupDir = parent ::getStorageDir ($ this ->login ->getGroup ());
1818
19+ // send range?
20+ if ( isset ($ this ->requestData ['timeMin ' ]) && isset ($ this ->requestData ['timeMax ' ]) &&
21+ is_int ($ this ->requestData ['timeMin ' ]) && is_int ($ this ->requestData ['timeMax ' ])
22+ ){
23+ $ timeMin = $ this ->requestData ['timeMin ' ];
24+ $ timeMax = $ this ->requestData ['timeMax ' ];
25+ }
26+ if (empty ($ timeMin ) || $ timeMin < 0 ){
27+ $ timeMin = 0 ;
28+ }
29+ if (empty ($ timeMax ) || $ timeMax < 0 ){
30+ $ timeMax = time ();
31+ }
32+
1933 $ files = array ();
20- if ( is_dir ($ groupDir )){
34+ if ( is_dir ($ groupDir ) ){
2135 foreach (array_diff (scandir ($ groupDir ), ['. ' ,'.. ' ]) as $ dir ){
2236 if ( $ dir !== $ this ->login ->getDeviceName () && is_dir ($ groupDir . '/ ' . $ dir ) ){
23- $ files = array_merge (
24- $ files ,
25- array_map ( function ($ f ) use (&$ dir ) {
26- return array (
27- 'timestamp ' => strtotime (substr ($ f , 0 , -5 )),
28- 'file ' => $ f ,
29- 'device ' => $ dir
30- );
31- },
32- array_filter (
33- scandir ( $ groupDir . '/ ' . $ dir ),
34- function ($ f ) {
35- return preg_match (parent ::FILENAME_PREG , $ f ) === 1 ;
36- }
37- )
38- )
39- );
37+ $ fi = array_filter (
38+ scandir ( $ groupDir . '/ ' . $ dir ),
39+ function ($ f ) {
40+ return preg_match (parent ::FILENAME_PREG , $ f ) === 1 ;
41+ }
42+ );
43+ foreach ($ fi as $ f ){
44+ $ time = strtotime (substr ($ f , 0 , -5 ));
45+ if ( $ time >= $ timeMin && $ time <= $ timeMax ){
46+ $ files [] = array (
47+ 'timestamp ' => $ time ,
48+ 'file ' => $ f ,
49+ 'device ' => $ dir
50+ );
51+ }
52+ }
4053 }
4154 }
4255 }
0 commit comments