diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2015-06-08 21:07:11 +0300 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2015-06-09 19:21:30 +0300 |
commit | 8440ecf4699ee6da2454cfd54f4eb70ffc88ff24 (patch) | |
tree | 06e21ce3a110c98746ea173e2139a7c5755840ad /appinfo | |
parent | 8748910bf5f44a2687835bf4dd2be9782a8e4ce8 (diff) |
move load/save file to a controller and fix error response on failed load operation
Diffstat (limited to 'appinfo')
-rw-r--r-- | appinfo/application.php | 58 | ||||
-rw-r--r-- | appinfo/routes.php | 43 |
2 files changed, 92 insertions, 9 deletions
diff --git a/appinfo/application.php b/appinfo/application.php new file mode 100644 index 0000000..463d3db --- /dev/null +++ b/appinfo/application.php @@ -0,0 +1,58 @@ +<?php +/** + * @author Björn Schießle <schiessle@owncloud.com> + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + + +namespace OCA\Files_Texteditor\AppInfo; + +use OC\Files\View; +use OCA\Files_Texteditor\Controller\FileHandlingController; +use OCP\AppFramework\App; +use OCP\AppFramework\IAppContainer; +use Punic\Exception; + +class Application extends App { + + /** + * @param array $urlParams + */ + public function __construct(array $urlParams = array()) { + parent::__construct('files_texteditor', $urlParams); + + $container = $this->getContainer(); + $server = $container->getServer(); + + $container->registerService('FileHandlingController', function (IAppContainer $c) use ($server) { + $user = $server->getUserSession()->getUser(); + if ($user) { + $uid = $user->getUID(); + } else { + throw new \BadMethodCallException('no user logged in'); + } + return new FileHandlingController( + $c->getAppName(), + $server->getRequest(), + $server->getL10N($c->getAppName()), + new View('/' . $uid . '/files'), + $server->getLogger() + ); + }); + } +} diff --git a/appinfo/routes.php b/appinfo/routes.php index 09b13dc..4ab756e 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -1,14 +1,39 @@ <?php /** - * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. + * @author Björn Schießle <schiessle@owncloud.com> + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * */ -/** @var $this OC\Route\Router */ -$this->create('files_texteditor_load', '/ajax/loadfile.php') - ->actionInclude('files_texteditor/ajax/loadfile.php'); -$this->create('files_texteditor_save', 'ajax/savefile.php') - ->actionInclude('files_texteditor/ajax/savefile.php'); +namespace OCA\Files_Texteditor\AppInfo; + +$app = new Application(); + +$app->registerRoutes($this, array('routes' => array( + + [ + 'name' => 'FileHandling#load', + 'url' => '/ajax/loadfile', + 'verb' => 'GET' + ], + [ + 'name' => 'FileHandling#save', + 'url' => '/ajax/savefile', + 'verb' => 'PUT' + ] +))); |