@@ -25,9 +25,9 @@ |
||
| 25 | 25 | namespace OCA\DAV\Direct; |
| 26 | 26 | |
| 27 | 27 | class Server extends \Sabre\DAV\Server { |
| 28 | - public function __construct($treeOrNode = null) { |
|
| 29 | - parent::__construct($treeOrNode); |
|
| 30 | - self::$exposeVersion = false; |
|
| 31 | - $this->enablePropfindDepthInfinityf = false; |
|
| 32 | - } |
|
| 28 | + public function __construct($treeOrNode = null) { |
|
| 29 | + parent::__construct($treeOrNode); |
|
| 30 | + self::$exposeVersion = false; |
|
| 31 | + $this->enablePropfindDepthInfinityf = false; |
|
| 32 | + } |
|
| 33 | 33 | } |
@@ -37,22 +37,22 @@ |
||
| 37 | 37 | * @method void setExpiration(int $expiration) |
| 38 | 38 | */ |
| 39 | 39 | class Direct extends Entity { |
| 40 | - /** @var string */ |
|
| 41 | - protected $userId; |
|
| 40 | + /** @var string */ |
|
| 41 | + protected $userId; |
|
| 42 | 42 | |
| 43 | - /** @var int */ |
|
| 44 | - protected $fileId; |
|
| 43 | + /** @var int */ |
|
| 44 | + protected $fileId; |
|
| 45 | 45 | |
| 46 | - /** @var string */ |
|
| 47 | - protected $token; |
|
| 46 | + /** @var string */ |
|
| 47 | + protected $token; |
|
| 48 | 48 | |
| 49 | - /** @var int */ |
|
| 50 | - protected $expiration; |
|
| 49 | + /** @var int */ |
|
| 50 | + protected $expiration; |
|
| 51 | 51 | |
| 52 | - public function __construct() { |
|
| 53 | - $this->addType('userId', 'string'); |
|
| 54 | - $this->addType('fileId', 'int'); |
|
| 55 | - $this->addType('token', 'string'); |
|
| 56 | - $this->addType('expiration', 'int'); |
|
| 57 | - } |
|
| 52 | + public function __construct() { |
|
| 53 | + $this->addType('userId', 'string'); |
|
| 54 | + $this->addType('fileId', 'int'); |
|
| 55 | + $this->addType('token', 'string'); |
|
| 56 | + $this->addType('expiration', 'int'); |
|
| 57 | + } |
|
| 58 | 58 | } |
@@ -31,50 +31,50 @@ |
||
| 31 | 31 | |
| 32 | 32 | class Version1005Date20180413093149 extends SimpleMigrationStep { |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @param IOutput $output |
|
| 36 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
| 37 | - * @param array $options |
|
| 38 | - * @return null|ISchemaWrapper |
|
| 39 | - */ |
|
| 40 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
| 34 | + /** |
|
| 35 | + * @param IOutput $output |
|
| 36 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
| 37 | + * @param array $options |
|
| 38 | + * @return null|ISchemaWrapper |
|
| 39 | + */ |
|
| 40 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
| 41 | 41 | |
| 42 | - /** @var ISchemaWrapper $schema */ |
|
| 43 | - $schema = $schemaClosure(); |
|
| 42 | + /** @var ISchemaWrapper $schema */ |
|
| 43 | + $schema = $schemaClosure(); |
|
| 44 | 44 | |
| 45 | - if (!$schema->hasTable('directlink')) { |
|
| 46 | - $table = $schema->createTable('directlink'); |
|
| 45 | + if (!$schema->hasTable('directlink')) { |
|
| 46 | + $table = $schema->createTable('directlink'); |
|
| 47 | 47 | |
| 48 | - $table->addColumn('id',Type::BIGINT, [ |
|
| 49 | - 'autoincrement' => true, |
|
| 50 | - 'notnull' => true, |
|
| 51 | - 'length' => 11, |
|
| 52 | - 'unsigned' => true, |
|
| 53 | - ]); |
|
| 54 | - $table->addColumn('user_id', Type::STRING, [ |
|
| 55 | - 'notnull' => false, |
|
| 56 | - 'length' => 64, |
|
| 57 | - ]); |
|
| 58 | - $table->addColumn('file_id', Type::BIGINT, [ |
|
| 59 | - 'notnull' => true, |
|
| 60 | - 'length' => 11, |
|
| 61 | - 'unsigned' => true, |
|
| 62 | - ]); |
|
| 63 | - $table->addColumn('token', Type::STRING, [ |
|
| 64 | - 'notnull' => false, |
|
| 65 | - 'length' => 60, |
|
| 66 | - ]); |
|
| 67 | - $table->addColumn('expiration', Type::BIGINT, [ |
|
| 68 | - 'notnull' => true, |
|
| 69 | - 'length' => 11, |
|
| 70 | - 'unsigned' => true, |
|
| 71 | - ]); |
|
| 48 | + $table->addColumn('id',Type::BIGINT, [ |
|
| 49 | + 'autoincrement' => true, |
|
| 50 | + 'notnull' => true, |
|
| 51 | + 'length' => 11, |
|
| 52 | + 'unsigned' => true, |
|
| 53 | + ]); |
|
| 54 | + $table->addColumn('user_id', Type::STRING, [ |
|
| 55 | + 'notnull' => false, |
|
| 56 | + 'length' => 64, |
|
| 57 | + ]); |
|
| 58 | + $table->addColumn('file_id', Type::BIGINT, [ |
|
| 59 | + 'notnull' => true, |
|
| 60 | + 'length' => 11, |
|
| 61 | + 'unsigned' => true, |
|
| 62 | + ]); |
|
| 63 | + $table->addColumn('token', Type::STRING, [ |
|
| 64 | + 'notnull' => false, |
|
| 65 | + 'length' => 60, |
|
| 66 | + ]); |
|
| 67 | + $table->addColumn('expiration', Type::BIGINT, [ |
|
| 68 | + 'notnull' => true, |
|
| 69 | + 'length' => 11, |
|
| 70 | + 'unsigned' => true, |
|
| 71 | + ]); |
|
| 72 | 72 | |
| 73 | - $table->setPrimaryKey(['id'], 'directlink_id_idx'); |
|
| 74 | - $table->addIndex(['token'], 'directlink_token_idx'); |
|
| 75 | - $table->addIndex(['expiration'], 'directlink_expiration_idx'); |
|
| 73 | + $table->setPrimaryKey(['id'], 'directlink_id_idx'); |
|
| 74 | + $table->addIndex(['token'], 'directlink_token_idx'); |
|
| 75 | + $table->addIndex(['expiration'], 'directlink_expiration_idx'); |
|
| 76 | 76 | |
| 77 | - return $schema; |
|
| 78 | - } |
|
| 79 | - } |
|
| 77 | + return $schema; |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | 80 | } |
@@ -45,7 +45,7 @@ |
||
| 45 | 45 | if (!$schema->hasTable('directlink')) { |
| 46 | 46 | $table = $schema->createTable('directlink'); |
| 47 | 47 | |
| 48 | - $table->addColumn('id',Type::BIGINT, [ |
|
| 48 | + $table->addColumn('id', Type::BIGINT, [ |
|
| 49 | 49 | 'autoincrement' => true, |
| 50 | 50 | 'notnull' => true, |
| 51 | 51 | 'length' => 11, |
@@ -22,11 +22,11 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | |
| 24 | 24 | return [ |
| 25 | - 'routes' => [ |
|
| 26 | - ['name' => 'birthday_calendar#enable', 'url' => '/enableBirthdayCalendar', 'verb' => 'POST'], |
|
| 27 | - ['name' => 'birthday_calendar#disable', 'url' => '/disableBirthdayCalendar', 'verb' => 'POST'], |
|
| 28 | - ], |
|
| 29 | - 'ocs' => [ |
|
| 30 | - ['name' => 'direct#getUrl', 'url' => '/api/v1/direct', 'verb' => 'POST'], |
|
| 31 | - ], |
|
| 25 | + 'routes' => [ |
|
| 26 | + ['name' => 'birthday_calendar#enable', 'url' => '/enableBirthdayCalendar', 'verb' => 'POST'], |
|
| 27 | + ['name' => 'birthday_calendar#disable', 'url' => '/disableBirthdayCalendar', 'verb' => 'POST'], |
|
| 28 | + ], |
|
| 29 | + 'ocs' => [ |
|
| 30 | + ['name' => 'direct#getUrl', 'url' => '/api/v1/direct', 'verb' => 'POST'], |
|
| 31 | + ], |
|
| 32 | 32 | ]; |
@@ -46,45 +46,45 @@ discard block |
||
| 46 | 46 | * @param Exception|Error $e |
| 47 | 47 | */ |
| 48 | 48 | function handleException($e) { |
| 49 | - $request = \OC::$server->getRequest(); |
|
| 50 | - // in case the request content type is text/xml - we assume it's a WebDAV request |
|
| 51 | - $isXmlContentType = strpos($request->getHeader('Content-Type'), 'text/xml'); |
|
| 52 | - if ($isXmlContentType === 0) { |
|
| 53 | - // fire up a simple server to properly process the exception |
|
| 54 | - $server = new Server(); |
|
| 55 | - if (!($e instanceof RemoteException)) { |
|
| 56 | - // we shall not log on RemoteException |
|
| 57 | - $server->addPlugin(new ExceptionLoggerPlugin('webdav', \OC::$server->getLogger())); |
|
| 58 | - } |
|
| 59 | - $server->on('beforeMethod', function () use ($e) { |
|
| 60 | - if ($e instanceof RemoteException) { |
|
| 61 | - switch ($e->getCode()) { |
|
| 62 | - case OC_Response::STATUS_SERVICE_UNAVAILABLE: |
|
| 63 | - throw new ServiceUnavailable($e->getMessage()); |
|
| 64 | - case OC_Response::STATUS_NOT_FOUND: |
|
| 65 | - throw new \Sabre\DAV\Exception\NotFound($e->getMessage()); |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - $class = get_class($e); |
|
| 69 | - $msg = $e->getMessage(); |
|
| 70 | - throw new ServiceUnavailable("$class: $msg"); |
|
| 71 | - }); |
|
| 72 | - $server->exec(); |
|
| 73 | - } else { |
|
| 74 | - $statusCode = OC_Response::STATUS_INTERNAL_SERVER_ERROR; |
|
| 75 | - if ($e instanceof \OC\ServiceUnavailableException ) { |
|
| 76 | - $statusCode = OC_Response::STATUS_SERVICE_UNAVAILABLE; |
|
| 77 | - } |
|
| 78 | - if ($e instanceof RemoteException) { |
|
| 79 | - // we shall not log on RemoteException |
|
| 80 | - OC_Response::setStatus($e->getCode()); |
|
| 81 | - OC_Template::printErrorPage($e->getMessage()); |
|
| 82 | - } else { |
|
| 83 | - \OC::$server->getLogger()->logException($e, ['app' => 'remote']); |
|
| 84 | - OC_Response::setStatus($statusCode); |
|
| 85 | - OC_Template::printExceptionErrorPage($e); |
|
| 86 | - } |
|
| 87 | - } |
|
| 49 | + $request = \OC::$server->getRequest(); |
|
| 50 | + // in case the request content type is text/xml - we assume it's a WebDAV request |
|
| 51 | + $isXmlContentType = strpos($request->getHeader('Content-Type'), 'text/xml'); |
|
| 52 | + if ($isXmlContentType === 0) { |
|
| 53 | + // fire up a simple server to properly process the exception |
|
| 54 | + $server = new Server(); |
|
| 55 | + if (!($e instanceof RemoteException)) { |
|
| 56 | + // we shall not log on RemoteException |
|
| 57 | + $server->addPlugin(new ExceptionLoggerPlugin('webdav', \OC::$server->getLogger())); |
|
| 58 | + } |
|
| 59 | + $server->on('beforeMethod', function () use ($e) { |
|
| 60 | + if ($e instanceof RemoteException) { |
|
| 61 | + switch ($e->getCode()) { |
|
| 62 | + case OC_Response::STATUS_SERVICE_UNAVAILABLE: |
|
| 63 | + throw new ServiceUnavailable($e->getMessage()); |
|
| 64 | + case OC_Response::STATUS_NOT_FOUND: |
|
| 65 | + throw new \Sabre\DAV\Exception\NotFound($e->getMessage()); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + $class = get_class($e); |
|
| 69 | + $msg = $e->getMessage(); |
|
| 70 | + throw new ServiceUnavailable("$class: $msg"); |
|
| 71 | + }); |
|
| 72 | + $server->exec(); |
|
| 73 | + } else { |
|
| 74 | + $statusCode = OC_Response::STATUS_INTERNAL_SERVER_ERROR; |
|
| 75 | + if ($e instanceof \OC\ServiceUnavailableException ) { |
|
| 76 | + $statusCode = OC_Response::STATUS_SERVICE_UNAVAILABLE; |
|
| 77 | + } |
|
| 78 | + if ($e instanceof RemoteException) { |
|
| 79 | + // we shall not log on RemoteException |
|
| 80 | + OC_Response::setStatus($e->getCode()); |
|
| 81 | + OC_Template::printErrorPage($e->getMessage()); |
|
| 82 | + } else { |
|
| 83 | + \OC::$server->getLogger()->logException($e, ['app' => 'remote']); |
|
| 84 | + OC_Response::setStatus($statusCode); |
|
| 85 | + OC_Template::printExceptionErrorPage($e); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -92,80 +92,80 @@ discard block |
||
| 92 | 92 | * @return string |
| 93 | 93 | */ |
| 94 | 94 | function resolveService($service) { |
| 95 | - $services = [ |
|
| 96 | - 'webdav' => 'dav/appinfo/v1/webdav.php', |
|
| 97 | - 'dav' => 'dav/appinfo/v2/remote.php', |
|
| 98 | - 'caldav' => 'dav/appinfo/v1/caldav.php', |
|
| 99 | - 'calendar' => 'dav/appinfo/v1/caldav.php', |
|
| 100 | - 'carddav' => 'dav/appinfo/v1/carddav.php', |
|
| 101 | - 'contacts' => 'dav/appinfo/v1/carddav.php', |
|
| 102 | - 'files' => 'dav/appinfo/v1/webdav.php', |
|
| 103 | - 'direct' => 'dav/appinfo/v2/direct.php', |
|
| 104 | - ]; |
|
| 105 | - if (isset($services[$service])) { |
|
| 106 | - return $services[$service]; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - return \OC::$server->getConfig()->getAppValue('core', 'remote_' . $service); |
|
| 95 | + $services = [ |
|
| 96 | + 'webdav' => 'dav/appinfo/v1/webdav.php', |
|
| 97 | + 'dav' => 'dav/appinfo/v2/remote.php', |
|
| 98 | + 'caldav' => 'dav/appinfo/v1/caldav.php', |
|
| 99 | + 'calendar' => 'dav/appinfo/v1/caldav.php', |
|
| 100 | + 'carddav' => 'dav/appinfo/v1/carddav.php', |
|
| 101 | + 'contacts' => 'dav/appinfo/v1/carddav.php', |
|
| 102 | + 'files' => 'dav/appinfo/v1/webdav.php', |
|
| 103 | + 'direct' => 'dav/appinfo/v2/direct.php', |
|
| 104 | + ]; |
|
| 105 | + if (isset($services[$service])) { |
|
| 106 | + return $services[$service]; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + return \OC::$server->getConfig()->getAppValue('core', 'remote_' . $service); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | try { |
| 113 | - require_once __DIR__ . '/lib/base.php'; |
|
| 114 | - |
|
| 115 | - // All resources served via the DAV endpoint should have the strictest possible |
|
| 116 | - // policy. Exempted from this is the SabreDAV browser plugin which overwrites |
|
| 117 | - // this policy with a softer one if debug mode is enabled. |
|
| 118 | - header("Content-Security-Policy: default-src 'none';"); |
|
| 119 | - |
|
| 120 | - if (\OCP\Util::needUpgrade()) { |
|
| 121 | - // since the behavior of apps or remotes are unpredictable during |
|
| 122 | - // an upgrade, return a 503 directly |
|
| 123 | - throw new RemoteException('Service unavailable', OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - $request = \OC::$server->getRequest(); |
|
| 127 | - $pathInfo = $request->getPathInfo(); |
|
| 128 | - if ($pathInfo === false || $pathInfo === '') { |
|
| 129 | - throw new RemoteException('Path not found', OC_Response::STATUS_NOT_FOUND); |
|
| 130 | - } |
|
| 131 | - if (!$pos = strpos($pathInfo, '/', 1)) { |
|
| 132 | - $pos = strlen($pathInfo); |
|
| 133 | - } |
|
| 134 | - $service=substr($pathInfo, 1, $pos-1); |
|
| 135 | - |
|
| 136 | - $file = resolveService($service); |
|
| 137 | - |
|
| 138 | - if(is_null($file)) { |
|
| 139 | - throw new RemoteException('Path not found', OC_Response::STATUS_NOT_FOUND); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - $file=ltrim($file, '/'); |
|
| 143 | - |
|
| 144 | - $parts=explode('/', $file, 2); |
|
| 145 | - $app=$parts[0]; |
|
| 146 | - |
|
| 147 | - // Load all required applications |
|
| 148 | - \OC::$REQUESTEDAPP = $app; |
|
| 149 | - OC_App::loadApps(array('authentication')); |
|
| 150 | - OC_App::loadApps(array('filesystem', 'logging')); |
|
| 151 | - |
|
| 152 | - switch ($app) { |
|
| 153 | - case 'core': |
|
| 154 | - $file = OC::$SERVERROOT .'/'. $file; |
|
| 155 | - break; |
|
| 156 | - default: |
|
| 157 | - if (!\OC::$server->getAppManager()->isInstalled($app)) { |
|
| 158 | - throw new RemoteException('App not installed: ' . $app); |
|
| 159 | - } |
|
| 160 | - OC_App::loadApp($app); |
|
| 161 | - $file = OC_App::getAppPath($app) .'/'. $parts[1]; |
|
| 162 | - break; |
|
| 163 | - } |
|
| 164 | - $baseuri = OC::$WEBROOT . '/remote.php/'.$service.'/'; |
|
| 165 | - require_once $file; |
|
| 113 | + require_once __DIR__ . '/lib/base.php'; |
|
| 114 | + |
|
| 115 | + // All resources served via the DAV endpoint should have the strictest possible |
|
| 116 | + // policy. Exempted from this is the SabreDAV browser plugin which overwrites |
|
| 117 | + // this policy with a softer one if debug mode is enabled. |
|
| 118 | + header("Content-Security-Policy: default-src 'none';"); |
|
| 119 | + |
|
| 120 | + if (\OCP\Util::needUpgrade()) { |
|
| 121 | + // since the behavior of apps or remotes are unpredictable during |
|
| 122 | + // an upgrade, return a 503 directly |
|
| 123 | + throw new RemoteException('Service unavailable', OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + $request = \OC::$server->getRequest(); |
|
| 127 | + $pathInfo = $request->getPathInfo(); |
|
| 128 | + if ($pathInfo === false || $pathInfo === '') { |
|
| 129 | + throw new RemoteException('Path not found', OC_Response::STATUS_NOT_FOUND); |
|
| 130 | + } |
|
| 131 | + if (!$pos = strpos($pathInfo, '/', 1)) { |
|
| 132 | + $pos = strlen($pathInfo); |
|
| 133 | + } |
|
| 134 | + $service=substr($pathInfo, 1, $pos-1); |
|
| 135 | + |
|
| 136 | + $file = resolveService($service); |
|
| 137 | + |
|
| 138 | + if(is_null($file)) { |
|
| 139 | + throw new RemoteException('Path not found', OC_Response::STATUS_NOT_FOUND); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + $file=ltrim($file, '/'); |
|
| 143 | + |
|
| 144 | + $parts=explode('/', $file, 2); |
|
| 145 | + $app=$parts[0]; |
|
| 146 | + |
|
| 147 | + // Load all required applications |
|
| 148 | + \OC::$REQUESTEDAPP = $app; |
|
| 149 | + OC_App::loadApps(array('authentication')); |
|
| 150 | + OC_App::loadApps(array('filesystem', 'logging')); |
|
| 151 | + |
|
| 152 | + switch ($app) { |
|
| 153 | + case 'core': |
|
| 154 | + $file = OC::$SERVERROOT .'/'. $file; |
|
| 155 | + break; |
|
| 156 | + default: |
|
| 157 | + if (!\OC::$server->getAppManager()->isInstalled($app)) { |
|
| 158 | + throw new RemoteException('App not installed: ' . $app); |
|
| 159 | + } |
|
| 160 | + OC_App::loadApp($app); |
|
| 161 | + $file = OC_App::getAppPath($app) .'/'. $parts[1]; |
|
| 162 | + break; |
|
| 163 | + } |
|
| 164 | + $baseuri = OC::$WEBROOT . '/remote.php/'.$service.'/'; |
|
| 165 | + require_once $file; |
|
| 166 | 166 | |
| 167 | 167 | } catch (Exception $ex) { |
| 168 | - handleException($ex); |
|
| 168 | + handleException($ex); |
|
| 169 | 169 | } catch (Error $e) { |
| 170 | - handleException($e); |
|
| 170 | + handleException($e); |
|
| 171 | 171 | } |
@@ -30,43 +30,43 @@ |
||
| 30 | 30 | |
| 31 | 31 | class DirectMapper extends Mapper { |
| 32 | 32 | |
| 33 | - public function __construct(IDBConnection $db) { |
|
| 34 | - parent::__construct($db, 'directlink', Direct::class); |
|
| 35 | - } |
|
| 33 | + public function __construct(IDBConnection $db) { |
|
| 34 | + parent::__construct($db, 'directlink', Direct::class); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @param string $token |
|
| 39 | - * @return Direct |
|
| 40 | - * @throws DoesNotExistException |
|
| 41 | - */ |
|
| 42 | - public function getByToken(string $token): Direct { |
|
| 43 | - $qb = $this->db->getQueryBuilder(); |
|
| 37 | + /** |
|
| 38 | + * @param string $token |
|
| 39 | + * @return Direct |
|
| 40 | + * @throws DoesNotExistException |
|
| 41 | + */ |
|
| 42 | + public function getByToken(string $token): Direct { |
|
| 43 | + $qb = $this->db->getQueryBuilder(); |
|
| 44 | 44 | |
| 45 | - $qb->select('*') |
|
| 46 | - ->from('directlink') |
|
| 47 | - ->where( |
|
| 48 | - $qb->expr()->eq('token', $qb->createNamedParameter($token)) |
|
| 49 | - ); |
|
| 45 | + $qb->select('*') |
|
| 46 | + ->from('directlink') |
|
| 47 | + ->where( |
|
| 48 | + $qb->expr()->eq('token', $qb->createNamedParameter($token)) |
|
| 49 | + ); |
|
| 50 | 50 | |
| 51 | - $cursor = $qb->execute(); |
|
| 52 | - $data = $cursor->fetch(); |
|
| 53 | - $cursor->closeCursor(); |
|
| 51 | + $cursor = $qb->execute(); |
|
| 52 | + $data = $cursor->fetch(); |
|
| 53 | + $cursor->closeCursor(); |
|
| 54 | 54 | |
| 55 | - if ($data === false) { |
|
| 56 | - throw new DoesNotExistException('Direct link with token does not exist'); |
|
| 57 | - } |
|
| 55 | + if ($data === false) { |
|
| 56 | + throw new DoesNotExistException('Direct link with token does not exist'); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - return Direct::fromRow($data); |
|
| 60 | - } |
|
| 59 | + return Direct::fromRow($data); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - public function deleteExpired(int $expiration) { |
|
| 63 | - $qb = $this->db->getQueryBuilder(); |
|
| 62 | + public function deleteExpired(int $expiration) { |
|
| 63 | + $qb = $this->db->getQueryBuilder(); |
|
| 64 | 64 | |
| 65 | - $qb->delete('directlink') |
|
| 66 | - ->where( |
|
| 67 | - $qb->expr()->lt('expiration', $qb->createNamedParameter($expiration)) |
|
| 68 | - ); |
|
| 65 | + $qb->delete('directlink') |
|
| 66 | + ->where( |
|
| 67 | + $qb->expr()->lt('expiration', $qb->createNamedParameter($expiration)) |
|
| 68 | + ); |
|
| 69 | 69 | |
| 70 | - $qb->execute(); |
|
| 71 | - } |
|
| 70 | + $qb->execute(); |
|
| 71 | + } |
|
| 72 | 72 | } |
@@ -32,30 +32,30 @@ |
||
| 32 | 32 | use OCP\IRequest; |
| 33 | 33 | |
| 34 | 34 | class ServerFactory { |
| 35 | - /** @var IConfig */ |
|
| 36 | - private $config; |
|
| 35 | + /** @var IConfig */ |
|
| 36 | + private $config; |
|
| 37 | 37 | |
| 38 | - public function __construct(IConfig $config) { |
|
| 39 | - $this->config = $config; |
|
| 40 | - } |
|
| 38 | + public function __construct(IConfig $config) { |
|
| 39 | + $this->config = $config; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - public function createServer(string $baseURI, |
|
| 43 | - string $requestURI, |
|
| 44 | - IRootFolder $rootFolder, |
|
| 45 | - DirectMapper $mapper, |
|
| 46 | - ITimeFactory $timeFactory, |
|
| 47 | - Throttler $throttler, |
|
| 48 | - IRequest $request): Server { |
|
| 49 | - $home = new DirectHome($rootFolder, $mapper, $timeFactory, $throttler, $request); |
|
| 50 | - $server = new Server($home); |
|
| 42 | + public function createServer(string $baseURI, |
|
| 43 | + string $requestURI, |
|
| 44 | + IRootFolder $rootFolder, |
|
| 45 | + DirectMapper $mapper, |
|
| 46 | + ITimeFactory $timeFactory, |
|
| 47 | + Throttler $throttler, |
|
| 48 | + IRequest $request): Server { |
|
| 49 | + $home = new DirectHome($rootFolder, $mapper, $timeFactory, $throttler, $request); |
|
| 50 | + $server = new Server($home); |
|
| 51 | 51 | |
| 52 | - $server->httpRequest->setUrl($requestURI); |
|
| 53 | - $server->setBaseUri($baseURI); |
|
| 52 | + $server->httpRequest->setUrl($requestURI); |
|
| 53 | + $server->setBaseUri($baseURI); |
|
| 54 | 54 | |
| 55 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin($this->config)); |
|
| 55 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin($this->config)); |
|
| 56 | 56 | |
| 57 | - return $server; |
|
| 57 | + return $server; |
|
| 58 | 58 | |
| 59 | 59 | |
| 60 | - } |
|
| 60 | + } |
|
| 61 | 61 | } |
@@ -32,79 +32,79 @@ |
||
| 32 | 32 | use Sabre\DAV\IFile; |
| 33 | 33 | |
| 34 | 34 | class DirectFile implements IFile { |
| 35 | - /** @var Direct */ |
|
| 36 | - private $direct; |
|
| 35 | + /** @var Direct */ |
|
| 36 | + private $direct; |
|
| 37 | 37 | |
| 38 | - /** @var IRootFolder */ |
|
| 39 | - private $rootFolder; |
|
| 38 | + /** @var IRootFolder */ |
|
| 39 | + private $rootFolder; |
|
| 40 | 40 | |
| 41 | - /** @var File */ |
|
| 42 | - private $file; |
|
| 41 | + /** @var File */ |
|
| 42 | + private $file; |
|
| 43 | 43 | |
| 44 | - public function __construct(Direct $direct, IRootFolder $rootFolder) { |
|
| 45 | - $this->direct = $direct; |
|
| 46 | - $this->rootFolder = $rootFolder; |
|
| 47 | - } |
|
| 44 | + public function __construct(Direct $direct, IRootFolder $rootFolder) { |
|
| 45 | + $this->direct = $direct; |
|
| 46 | + $this->rootFolder = $rootFolder; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - public function put($data) { |
|
| 50 | - throw new Forbidden(); |
|
| 51 | - } |
|
| 49 | + public function put($data) { |
|
| 50 | + throw new Forbidden(); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - public function get() { |
|
| 54 | - $this->getFile(); |
|
| 53 | + public function get() { |
|
| 54 | + $this->getFile(); |
|
| 55 | 55 | |
| 56 | - return $this->file->fopen('rb'); |
|
| 57 | - } |
|
| 56 | + return $this->file->fopen('rb'); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - public function getContentType() { |
|
| 60 | - $this->getFile(); |
|
| 59 | + public function getContentType() { |
|
| 60 | + $this->getFile(); |
|
| 61 | 61 | |
| 62 | - return $this->file->getMimeType(); |
|
| 63 | - } |
|
| 62 | + return $this->file->getMimeType(); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - public function getETag() { |
|
| 66 | - $this->getFile(); |
|
| 65 | + public function getETag() { |
|
| 66 | + $this->getFile(); |
|
| 67 | 67 | |
| 68 | - return $this->file->getEtag(); |
|
| 69 | - } |
|
| 68 | + return $this->file->getEtag(); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - public function getSize() { |
|
| 72 | - $this->getFile(); |
|
| 71 | + public function getSize() { |
|
| 72 | + $this->getFile(); |
|
| 73 | 73 | |
| 74 | - return $this->file->getSize(); |
|
| 75 | - } |
|
| 74 | + return $this->file->getSize(); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - public function delete() { |
|
| 78 | - throw new Forbidden(); |
|
| 79 | - } |
|
| 77 | + public function delete() { |
|
| 78 | + throw new Forbidden(); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - public function getName() { |
|
| 82 | - return $this->direct->getToken(); |
|
| 83 | - } |
|
| 81 | + public function getName() { |
|
| 82 | + return $this->direct->getToken(); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - public function setName($name) { |
|
| 86 | - throw new Forbidden(); |
|
| 87 | - } |
|
| 85 | + public function setName($name) { |
|
| 86 | + throw new Forbidden(); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - public function getLastModified() { |
|
| 90 | - $this->getFile(); |
|
| 89 | + public function getLastModified() { |
|
| 90 | + $this->getFile(); |
|
| 91 | 91 | |
| 92 | - return $this->file->getMTime(); |
|
| 93 | - } |
|
| 92 | + return $this->file->getMTime(); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - private function getFile() { |
|
| 96 | - if ($this->file === null) { |
|
| 97 | - $userFolder = $this->rootFolder->getUserFolder($this->direct->getUserId()); |
|
| 98 | - $files = $userFolder->getById($this->direct->getFileId()); |
|
| 95 | + private function getFile() { |
|
| 96 | + if ($this->file === null) { |
|
| 97 | + $userFolder = $this->rootFolder->getUserFolder($this->direct->getUserId()); |
|
| 98 | + $files = $userFolder->getById($this->direct->getFileId()); |
|
| 99 | 99 | |
| 100 | - if ($files === []) { |
|
| 101 | - throw new NotFound(); |
|
| 102 | - } |
|
| 100 | + if ($files === []) { |
|
| 101 | + throw new NotFound(); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - $this->file = array_shift($files); |
|
| 105 | - } |
|
| 104 | + $this->file = array_shift($files); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - return $this->file; |
|
| 108 | - } |
|
| 107 | + return $this->file; |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | 110 | } |
@@ -29,22 +29,22 @@ |
||
| 29 | 29 | use OCP\AppFramework\Utility\ITimeFactory; |
| 30 | 30 | |
| 31 | 31 | class CleanupDirectLinksJob extends TimedJob { |
| 32 | - /** @var ITimeFactory */ |
|
| 33 | - private $timeFactory; |
|
| 32 | + /** @var ITimeFactory */ |
|
| 33 | + private $timeFactory; |
|
| 34 | 34 | |
| 35 | - /** @var DirectMapper */ |
|
| 36 | - private $mapper; |
|
| 35 | + /** @var DirectMapper */ |
|
| 36 | + private $mapper; |
|
| 37 | 37 | |
| 38 | - public function __construct(ITimeFactory $timeFactory, DirectMapper $mapper) { |
|
| 39 | - $this->setInterval(60*60*24); |
|
| 38 | + public function __construct(ITimeFactory $timeFactory, DirectMapper $mapper) { |
|
| 39 | + $this->setInterval(60*60*24); |
|
| 40 | 40 | |
| 41 | - $this->timeFactory = $timeFactory; |
|
| 42 | - $this->mapper = $mapper; |
|
| 43 | - } |
|
| 41 | + $this->timeFactory = $timeFactory; |
|
| 42 | + $this->mapper = $mapper; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - protected function run($argument) { |
|
| 46 | - // Delete all shares expired 24 hours ago |
|
| 47 | - $this->mapper->deleteExpired($this->timeFactory->getTime() - 60*60*24); |
|
| 48 | - } |
|
| 45 | + protected function run($argument) { |
|
| 46 | + // Delete all shares expired 24 hours ago |
|
| 47 | + $this->mapper->deleteExpired($this->timeFactory->getTime() - 60*60*24); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | 50 | } |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | private $mapper; |
| 37 | 37 | |
| 38 | 38 | public function __construct(ITimeFactory $timeFactory, DirectMapper $mapper) { |
| 39 | - $this->setInterval(60*60*24); |
|
| 39 | + $this->setInterval(60 * 60 * 24); |
|
| 40 | 40 | |
| 41 | 41 | $this->timeFactory = $timeFactory; |
| 42 | 42 | $this->mapper = $mapper; |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | protected function run($argument) { |
| 46 | 46 | // Delete all shares expired 24 hours ago |
| 47 | - $this->mapper->deleteExpired($this->timeFactory->getTime() - 60*60*24); |
|
| 47 | + $this->mapper->deleteExpired($this->timeFactory->getTime() - 60 * 60 * 24); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | } |