Cleanup code a little bit
- Use OCP\Response constants instead of the HTTP error code - Use checkAppEnabled() instead of OC_App::isEnabled with an if statement - Remove uneeded variable $baseURL - Rename $isvalid to $isValid
This commit is contained in:
parent
9385b97b5f
commit
0b7d9e2668
|
@ -20,17 +20,10 @@
|
|||
*
|
||||
*/
|
||||
|
||||
// only need filesystem apps
|
||||
$RUNTIME_APPTYPES=array('filesystem');
|
||||
|
||||
// Init owncloud
|
||||
|
||||
if(!\OC_App::isEnabled('files_sharing')){
|
||||
exit;
|
||||
}
|
||||
OCP\JSON::checkAppEnabled('files_sharing');
|
||||
|
||||
if(!isset($_GET['t'])){
|
||||
\OC_Response::setStatus(400); //400 Bad Request
|
||||
\OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST);
|
||||
\OC_Log::write('core-preview', 'No token parameter was passed', \OC_Log::DEBUG);
|
||||
exit;
|
||||
}
|
||||
|
@ -55,13 +48,12 @@ $dir = $data['realPath'];
|
|||
|
||||
$dir = \OC\Files\Filesystem::normalizePath($dir);
|
||||
if (!\OC\Files\Filesystem::is_dir($dir . '/')) {
|
||||
\OC_Response::setStatus(404);
|
||||
\OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND);
|
||||
\OCP\JSON::error(array('success' => false));
|
||||
exit();
|
||||
}
|
||||
|
||||
$data = array();
|
||||
$baseUrl = OCP\Util::linkTo('files_sharing', 'index.php') . '?t=' . urlencode($token) . '&dir=';
|
||||
|
||||
// make filelist
|
||||
$files = \OCA\Files\Helper::getFiles($dir);
|
||||
|
@ -88,4 +80,4 @@ if (OC_Appconfig::getValue('core', 'shareapi_allow_public_upload', 'yes') === 'n
|
|||
|
||||
$data['permissions'] = $permissions;
|
||||
|
||||
OCP\JSON::success(array('data' => $data));
|
||||
OCP\JSON::success(array('data' => $data));
|
|
@ -5,9 +5,8 @@
|
|||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
if(!\OC_App::isEnabled('files_sharing')){
|
||||
exit;
|
||||
}
|
||||
|
||||
OCP\JSON::checkAppEnabled('files_sharing');
|
||||
|
||||
\OC_User::setIncognitoMode(true);
|
||||
|
||||
|
@ -18,20 +17,20 @@ $scalingUp = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] :
|
|||
$token = array_key_exists('t', $_GET) ? (string) $_GET['t'] : '';
|
||||
|
||||
if($token === ''){
|
||||
\OC_Response::setStatus(400); //400 Bad Request
|
||||
\OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST);
|
||||
\OC_Log::write('core-preview', 'No token parameter was passed', \OC_Log::DEBUG);
|
||||
exit;
|
||||
}
|
||||
|
||||
$linkedItem = \OCP\Share::getShareByToken($token);
|
||||
if($linkedItem === false || ($linkedItem['item_type'] !== 'file' && $linkedItem['item_type'] !== 'folder')) {
|
||||
\OC_Response::setStatus(404);
|
||||
\OC_Response::setStatus(\OC_Response::STATUS_NOT_FOUND);
|
||||
\OC_Log::write('core-preview', 'Passed token parameter is not valid', \OC_Log::DEBUG);
|
||||
exit;
|
||||
}
|
||||
|
||||
if(!isset($linkedItem['uid_owner']) || !isset($linkedItem['file_source'])) {
|
||||
\OC_Response::setStatus(500);
|
||||
\OC_Response::setStatus(\OC_Response::STATUS_INTERNAL_SERVER_ERROR);
|
||||
\OC_Log::write('core-preview', 'Passed token seems to be valid, but it does not contain all necessary information . ("' . $token . '")', \OC_Log::WARN);
|
||||
exit;
|
||||
}
|
||||
|
@ -50,9 +49,9 @@ $pathInfo = $view->getFileInfo($path);
|
|||
$sharedFile = null;
|
||||
|
||||
if($linkedItem['item_type'] === 'folder') {
|
||||
$isvalid = \OC\Files\Filesystem::isValidPath($file);
|
||||
if(!$isvalid) {
|
||||
\OC_Response::setStatus(400); //400 Bad Request
|
||||
$isValid = \OC\Files\Filesystem::isValidPath($file);
|
||||
if(!$isValid) {
|
||||
\OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST);
|
||||
\OC_Log::write('core-preview', 'Passed filename is not valid, might be malicious (file:"' . $file . '";ip:"' . $_SERVER['REMOTE_ADDR'] . '")', \OC_Log::WARN);
|
||||
exit;
|
||||
}
|
||||
|
@ -71,7 +70,7 @@ if(substr($path, 0, 1) === '/') {
|
|||
}
|
||||
|
||||
if($maxX === 0 || $maxY === 0) {
|
||||
\OC_Response::setStatus(400); //400 Bad Request
|
||||
\OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST);
|
||||
\OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG);
|
||||
exit;
|
||||
}
|
||||
|
@ -87,6 +86,6 @@ try{
|
|||
|
||||
$preview->show();
|
||||
} catch (\Exception $e) {
|
||||
\OC_Response::setStatus(500);
|
||||
\OC_Response::setStatus(\OC_Response::STATUS_INTERNAL_SERVER_ERROR);
|
||||
\OC_Log::write('core', $e->getmessage(), \OC_Log::DEBUG);
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ class OC_Response {
|
|||
const STATUS_FOUND = 304;
|
||||
const STATUS_NOT_MODIFIED = 304;
|
||||
const STATUS_TEMPORARY_REDIRECT = 307;
|
||||
const STATUS_BAD_REQUEST = 400;
|
||||
const STATUS_NOT_FOUND = 404;
|
||||
const STATUS_INTERNAL_SERVER_ERROR = 500;
|
||||
const STATUS_SERVICE_UNAVAILABLE = 503;
|
||||
|
|
Loading…
Reference in New Issue