Get files for a particular page

This commit is contained in:
Diego Najar 2020-03-20 19:49:59 +01:00
parent 46fa8a1fab
commit fd80820e0b
1 changed files with 41 additions and 0 deletions

View File

@ -191,6 +191,11 @@ class pluginAPI extends Plugin {
$username = $parameters[1]; $username = $parameters[1];
$data = $this->getUser($username); $data = $this->getUser($username);
} }
// (GET) /api/files/<page-key>
elseif ( ($method==='GET') && ($parameters[0]==='files') && !empty($parameters[1]) ) {
$pageKey = $parameters[1];
$data = $this->getFiles($pageKey);
}
else { else {
$this->response(401, 'Unauthorized', array('message'=>'Access denied or invalid endpoint.')); $this->response(401, 'Unauthorized', array('message'=>'Access denied or invalid endpoint.'));
} }
@ -667,4 +672,40 @@ class pluginAPI extends Plugin {
'data'=>$data 'data'=>$data
); );
} }
/*
| Returns all files uploaded for a specific page, includes any type of file.
|
| @return array
*/
private function getFiles($pageKey)
{
$chunk = false;
$sortByDate = true;
$path = PATH_UPLOADS_PAGES.$pageKey.DS;
$listFiles = Filesystem::listFiles($path, '*', '*', $sortByDate, $chunk);
$files = array();
foreach ($listFiles as $file) {
$info = array('thumbnail'=>'');
$info['file'] = $file;
$info['filename'] = basename($file);
$info['mime'] = Filesystem::mimeType($file);
$info['size'] = Filesystem::getSize($file);
// Check if thumbnail exists for the file
$thumbnail = $path.'thumbnails'.DS.$info['filename'];
if (Filesystem::fileExists($thumbnail)) {
$info['thumbnail'] = $thumbnail;
}
array_push($files, $info);
}
return array(
'status'=>'0',
'message'=>'Files for the page key: '.$pageKey,
'data'=>$files
);
}
} }