/** * @NoAdminRequired * @NoCSRFRequired * @SSOCORS */ public function getFileList($dir = null, $sortby = 'name', $sort = false) { \OCP\JSON::checkLoggedIn(); \OC::$server->getSession()->close(); // Load the files $dir = $dir ? (string) $dir : ''; $dir = \OC\Files\Filesystem::normalizePath($dir); try { $dirInfo = \OC\Files\Filesystem::getFileInfo($dir); if (!$dirInfo || !$dirInfo->getType() === 'dir') { header('HTTP/1.0 404 Not Found'); exit; } $data = array(); $baseUrl = \OCP\Util::linkTo('files', 'index.php') . '?dir='; $permissions = $dirInfo->getPermissions(); $sortDirection = $sort === 'desc'; $mimetypeFilters = ''; $files = []; if (is_array($mimetypeFilters) && count($mimetypeFilters)) { $mimetypeFilters = array_unique($mimetypeFilters); if (!in_array('httpd/unix-directory', $mimetypeFilters)) { $mimetypeFilters[] = 'httpd/unix-directory'; } foreach ($mimetypeFilters as $mimetypeFilter) { $files = array_merge($files, \OCA\Files\Helper::getFiles($dir, $sortby, $sortDirection, $mimetypeFilter)); } $files = \OCA\Files\Helper::sortFiles($files, $sortby, $sortDirection); } else { $files = \OCA\Files\Helper::getFiles($dir, $sortby, $sortDirection); } $files = \OCA\Files\Helper::populateTags($files); $data['directory'] = $dir; $data['files'] = \OCA\Files\Helper::formatFileInfos($files); $data['permissions'] = $permissions; return new DataResponse(array('data' => $data, 'status' => 'success')); } catch (\OCP\Files\StorageNotAvailableException $e) { \OCP\Util::logException('files', $e); return new DataResponse(array('data' => array('exception' => '\\OCP\\Files\\StorageNotAvailableException', 'message' => 'Storage not available'), 'status' => 'error')); } catch (\OCP\Files\StorageInvalidException $e) { \OCP\Util::logException('files', $e); return new DataResponse(array('data' => array('exception' => '\\OCP\\Files\\StorageInvalidException', 'message' => 'Storage invalid'), 'status' => 'error')); } catch (\Exception $e) { \OCP\Util::logException('files', $e); return new DataResponse(array('data' => array('exception' => '\\Exception', 'message' => 'Unknown error'), 'status' => 'error')); } }
OCP\JSON::checkLoggedIn(); \OC::$session->close(); $l = OC_L10N::get('files'); // Load the files $dir = isset($_GET['dir']) ? $_GET['dir'] : ''; $dir = \OC\Files\Filesystem::normalizePath($dir); try { $dirInfo = \OC\Files\Filesystem::getFileInfo($dir); if (!$dirInfo || !$dirInfo->getType() === 'dir') { header("HTTP/1.0 404 Not Found"); exit; } $data = array(); $baseUrl = OCP\Util::linkTo('files', 'index.php') . '?dir='; $permissions = $dirInfo->getPermissions(); $sortAttribute = isset($_GET['sort']) ? $_GET['sort'] : 'name'; $sortDirection = isset($_GET['sortdirection']) ? $_GET['sortdirection'] === 'desc' : false; // make filelist $files = \OCA\Files\Helper::getFiles($dir, $sortAttribute, $sortDirection); $data['directory'] = $dir; $data['files'] = \OCA\Files\Helper::formatFileInfos($files); $data['permissions'] = $permissions; OCP\JSON::success(array('data' => $data)); } catch (\OCP\Files\StorageNotAvailableException $e) { OCP\JSON::error(array('data' => array('exception' => '\\OCP\\Files\\StorageNotAvailableException', 'message' => $l->t('Storage not available')))); } catch (\OCP\Files\StorageInvalidException $e) { OCP\JSON::error(array('data' => array('exception' => '\\OCP\\Files\\StorageInvalidException', 'message' => $l->t('Storage invalid')))); } catch (\Exception $e) { OCP\JSON::error(array('data' => array('exception' => '\\Exception', 'message' => $l->t('Unknown error')))); }
/** * @NoAdminRequired * @NoCSRFRequired */ public function ListTorrentFiles() { \OCP\JSON::setContentTypeHeader('application/json'); try { if (!$this->AllowProtocolBT && !\OC_User::isAdminUser($this->CurrentUID)) { throw new \Exception((string) $this->L10N->t('You are not allowed to use the BitTorrent protocol')); } if (!\OC\Files\Filesystem::is_dir($this->TorrentsFolder)) { \OC\Files\Filesystem::mkdir($this->TorrentsFolder); } $this->TorrentsFolder = \OC\Files\Filesystem::normalizePath($this->TorrentsFolder); $Files = \OCA\Files\Helper::getFiles($this->TorrentsFolder, 'name', 'desc', 'application/octet-stream'); $Files = \OCA\Files\Helper::formatFileInfos($Files); return new JSONResponse(array('ERROR' => false, 'FILES' => $Files)); } catch (Exception $E) { return new JSONResponse(array('ERROR' => true, 'MESSAGE' => $E->getMessage())); } }
/** * @NoAdminRequired * @NoCSRFRequired */ public function ListTorrentFiles() { \OCP\JSON::setContentTypeHeader('application/json'); try { if (!\OC\Files\Filesystem::is_dir($this->TorrentsFolder)) { \OC\Files\Filesystem::mkdir($this->TorrentsFolder); } $this->TorrentsFolder = \OC\Files\Filesystem::normalizePath($this->TorrentsFolder); $Files = \OCA\Files\Helper::getFiles($this->TorrentsFolder, 'name', 'desc'); $Files = \OCA\Files\Helper::formatFileInfos($Files); return new JSONResponse(array('ERROR' => false, 'FILES' => $Files)); } catch (Exception $E) { return new JSONResponse(array('ERROR' => true, 'MESSAGE' => $E->getMessage())); } }