Skip to content

Commit 1a396d0

Browse files
author
jessevz
committed
Added helper to retrieve files in the import directory
1 parent 42afc2e commit 1a396d0

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/inc/apiv2/helper/importFile.routes.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,31 @@ function processDelete(Request $request, Response $response, array $args): Respo
386386
->WithHeader("Access-Control-Expose-Headers", "Tus-Resumable");
387387
}
388388

389+
/**
390+
* Scans the import-directory for files. Directories are ignored.
391+
* @return array of all files in the top-level directory /../import
392+
*/
393+
function scanImportDirectory() {
394+
$directory = Factory::getStoredValueFactory()->get(DDirectories::IMPORT)->getVal() . "/";
395+
if (file_exists($directory) && is_dir($directory)) {
396+
$importDirectory = opendir($directory);
397+
$importFiles = array();
398+
while ($file = readdir($importDirectory)) {
399+
if ($file[0] != '.' && $file != "." && $file != ".." && !is_dir($file)) {
400+
$importFiles[] = array("file" => $file, "size" => Util::filesize($directory . "/" . $file));
401+
}
402+
}
403+
sort($importFiles);
404+
return $importFiles;
405+
}
406+
return array();
407+
}
408+
409+
function processGet(Request $request, Response $response, array $args): Response {
410+
$importFiles = $this->scanImportDirectory();
411+
return self::getMetaResponse($importFiles, $request, $response);
412+
}
413+
389414

390415
static public function register($app): void {
391416
$me = get_called_class();
@@ -404,6 +429,7 @@ static public function register($app): void {
404429
});
405430

406431
$group->post('', $me . ":processPost")->setName($me . ":processPost");
432+
$group->get('', $me . ":processGet")->setName($me . ":processGet");
407433
});
408434

409435
$app->group($baseUri . "/{id:[0-9]{14}-[0-9a-f]{32}}", function (RouteCollectorProxy $group) use ($me) {

0 commit comments

Comments
 (0)