Skip to content
This repository was archived by the owner on Mar 30, 2024. It is now read-only.

Commit 28b4cea

Browse files
committed
Fix #1
1 parent e0069bb commit 28b4cea

File tree

2 files changed

+47
-18
lines changed

2 files changed

+47
-18
lines changed

imexport/test.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
if( php_sapi_name() !== 'cli' ){
3+
die('Commandline only!');
4+
}
5+
require_once(__DIR__ . '/api.php');
6+
7+
$client = new APIClient(
8+
"http://localhost:8080/",
9+
"admin",
10+
"bbbbb",
11+
"blmWWwrHIJKRbir5cb6VabtX5arRrlomyfekBPc70FU68KUYk7"
12+
);
13+
14+
15+
print_r( $client->listFiles(0, time()) );
16+
?>

php/core/api/APIList.php

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)