Skip to content

Commit

Permalink
Fix API for extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
e-alfred committed Apr 28, 2019
1 parent 8a4606a commit 49dd4af
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 44 deletions.
29 changes: 19 additions & 10 deletions appinfo/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use OCA\ocDownloader\Controller\FtpDownloader;
use OCA\ocDownloader\Controller\YTDownloader;
use OCA\ocDownloader\Controller\BTDownloader;
use OCA\ocDownloader\Controller\Lib\Api;
use OCA\ocDownloader\Controller\Queue;
use OCA\ocDownloader\Controller\Updater;
use OCA\ocDownloader\Controller\PersonalSettings;
Expand All @@ -30,12 +31,12 @@ public function __construct(array $URLParams = array())
{
parent::__construct('ocdownloader', $URLParams);
$container = $this->getContainer();

$container->registerService('CurrentUID', function (IContainer $Container) {
$User = $Container->query('ServerContainer')->getUserSession()->getUser();
return($User) ? $User->getUID() : '';
});

$container->registerService('IndexController', function (IContainer $Container) {
return new Index(
$Container->query('AppName'),
Expand All @@ -44,7 +45,7 @@ public function __construct(array $URLParams = array())
$Container->getServer()->getL10N('ocdownloader')
);
});

$container->registerService('HttpDownloaderController', function (IContainer $Container) {
return new HttpDownloader(
$Container->query('AppName'),
Expand All @@ -53,7 +54,7 @@ public function __construct(array $URLParams = array())
$Container->getServer()->getL10N('ocdownloader')
);
});

$container->registerService('FtpDownloaderController', function (IContainer $Container) {
return new FtpDownloader(
$Container->query('AppName'),
Expand All @@ -62,7 +63,7 @@ public function __construct(array $URLParams = array())
$Container->getServer()->getL10N('ocdownloader')
);
});

$container->registerService('YTDownloaderController', function (IContainer $Container) {
return new YTDownloader(
$Container->query('AppName'),
Expand All @@ -71,7 +72,7 @@ public function __construct(array $URLParams = array())
$Container->getServer()->getL10N('ocdownloader')
);
});

$container->registerService('BTDownloaderController', function (IContainer $Container) {
return new BTDownloader(
$Container->query('AppName'),
Expand All @@ -80,7 +81,7 @@ public function __construct(array $URLParams = array())
$Container->getServer()->getL10N('ocdownloader')
);
});

$container->registerService('QueueController', function (IContainer $Container) {
return new Queue(
$Container->query('AppName'),
Expand All @@ -89,23 +90,23 @@ public function __construct(array $URLParams = array())
$Container->getServer()->getL10N('ocdownloader')
);
});

$container->registerService('UpdaterController', function (IContainer $Container) {
return new Updater(
$Container->query('AppName'),
$Container->query('Request'),
$Container->getServer()->getL10N('ocdownloader')
);
});

$container->registerService('AdminSettingsController', function (IContainer $Container) {
return new AdminSettings(
$Container->query('AppName'),
$Container->query('Request'),
$Container->getServer()->getL10N('ocdownloader')
);
});

$container->registerService('PersonalSettingsController', function (IContainer $Container) {
return new PersonalSettings(
$Container->query('AppName'),
Expand All @@ -114,5 +115,13 @@ public function __construct(array $URLParams = array())
$Container->getServer()->getL10N('ocdownloader')
);
});

$container->registerService('ApiController', function (IContainer $Container) {
return new Api(
$Container->query('AppName'),
$Container->query('Request'),
$Container->getServer()->getL10N('ocdownloader')
);
});
}
}
39 changes: 7 additions & 32 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,37 +58,12 @@
['name' => 'PersonalSettings#Get', 'url' => '/personalsettings/get', 'verb' => 'GET'],

// Updater
['name' => 'Updater#Check', 'url' => '/updater/check', 'verb' => 'GET']
]
));

$APIBasePath = '/apps/ocdownloader/api/';
\OCP\API::register(
'POST',
$APIBasePath.'version',
function ($URLParams) {
return new \OC\OCS\Result(\OCA\ocDownloader\Controller\Lib\API::checkAddonVersion($_POST['AddonVersion']));
},
'ocdownloader',
\OCP\API::USER_AUTH
);
['name' => 'Updater#Check', 'url' => '/updater/check', 'verb' => 'GET'],

\OCP\API::register(
'GET',
$APIBasePath.'queue/get',
function ($URLParams) {
return new \OC\OCS\Result(\OCA\ocDownloader\Controller\Lib\API::getQueue());
},
'ocdownloader',
\OCP\API::USER_AUTH
);
//Extension API
['name' => 'Api#checkAddonVersion', 'url' => '/api/version', 'verb' => 'POST'],
['name' => 'Api#getQueue', 'url' => '/api/queue/get', 'verb' => 'GET'],
['name' => 'Api#add', 'url' => '/api/add', 'verb' => 'POST']

\OCP\API::register(
'POST',
$APIBasePath.'add',
function ($URLParams) {
return new \OC\OCS\Result(\OCA\ocDownloader\Controller\Lib\API::add($_POST['URL']));
},
'ocdownloader',
\OCP\API::USER_AUTH
);
]
));
20 changes: 18 additions & 2 deletions controller/lib/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@

namespace OCA\ocDownloader\Controller\Lib;


use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;

use \OCA\ocDownloader\Controller\Lib\YouTube;
use \OCA\ocDownloader\Controller\Lib\Aria2;
use \OCA\ocDownloader\Controller\Lib\Tools;
use \OCA\ocDownloader\Controller\Lib\Settings;

class API
class API extends Controller
{
private static $AbsoluteDownloadsFolder = null;
private static $DownloadsFolder = null;
Expand All @@ -37,6 +38,11 @@ class API
private static $AllowProtocolBT = null;
private static $MaxDownloadSpeed = null;

/**
* @NoAdminRequired
* @NoCSRFRequired
*/

public static function add($URL)
{
try {
Expand Down Expand Up @@ -132,12 +138,22 @@ public static function add($URL)
}
}

/**
* @NoAdminRequired
* @NoCSRFRequired
*/

public static function checkAddonVersion($Version)
{
$AppVersion = \OC::$server->getConfig()->getAppValue('ocdownloader', 'installed_version');
return array('RESULT' => version_compare($Version, $AppVersion, '<='));
}

/**
* @NoAdminRequired
* @NoCSRFRequired
*/

public static function getQueue()
{
self::load();
Expand Down

0 comments on commit 49dd4af

Please sign in to comment.