Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: API Handler #48

Open
wants to merge 59 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
4e19f2d
add API handler
castorinop Sep 22, 2017
820e46b
add uri form to add template
castorinop Sep 22, 2017
7e3ca37
remove new download buttons from template
castorinop Sep 22, 2017
20389f8
update styles
castorinop Sep 22, 2017
6ce3657
add magnet support
castorinop Sep 22, 2017
1f4b2a4
update minified js and css
castorinop Sep 22, 2017
40dcebc
correct handle value from imput checkbox
castorinop Nov 3, 2017
a03f4da
Add API Controller (Add|Handler)
castorinop Nov 4, 2017
7f9a7c9
Update use namespaces for libs
castorinop Nov 4, 2017
31ca664
Add backends
castorinop Nov 4, 2017
59defa7
Aplication uses backends
castorinop Nov 5, 2017
81a2858
Use namespace
castorinop Nov 5, 2017
e88bb5d
Libs: fix namespaces
castorinop Nov 5, 2017
34ae53c
update from e-alfred master
castorinop Feb 5, 2019
191ea09
Merge branch 'db-rework2' of https://github.com/e-alfred/ocdownloader
castorinop Feb 5, 2019
ba7bfcd
Fix deprecated OC_API
castorinop Feb 8, 2019
3317465
Fix deprecated OCP\DB calls
castorinop Feb 8, 2019
f150c06
typo
castorinop Feb 8, 2019
3b38853
fix mad merge
castorinop Feb 8, 2019
0f5747d
move getBackends method to Backend Service
castorinop Feb 14, 2019
628bb55
Become DB Service
castorinop Feb 14, 2019
4a667d6
API queue, use DB Service
castorinop Feb 14, 2019
bad5871
DB Service add filters by status
castorinop Feb 20, 2019
1d6cd1f
Use filters for view
castorinop Feb 20, 2019
42341e7
accept POST for filter views
castorinop Feb 20, 2019
0934409
Backend Service update status from backend
castorinop Feb 20, 2019
d136247
Implements Update Status via Backend for API queue
castorinop Feb 20, 2019
fa31f7d
fix bad refactory code
castorinop Feb 20, 2019
de71400
Update Doc Goals
castorinop Feb 20, 2019
3898616
Better markdown doc
castorinop Feb 20, 2019
a159ed2
Backend Service get status from downloader
castorinop Feb 21, 2019
7609401
YTDL fix constructor
castorinop Feb 21, 2019
c33b21c
API controller fix dependences and docs
castorinop Feb 21, 2019
52a9c9d
style info span as block
castorinop Feb 21, 2019
ff3ec96
UI single view
castorinop Feb 22, 2019
65566bb
remove old routes
castorinop Feb 22, 2019
0d7f455
UI: move URI form and events to single view.
castorinop Feb 22, 2019
3156a72
UI: change base url to API
castorinop Feb 22, 2019
a3b5f20
update minified
castorinop Feb 22, 2019
e565970
UI: update navigation template to SPA
castorinop Feb 22, 2019
71ba52e
update doc
castorinop Feb 22, 2019
3dae014
DB Service: Implements addqueue moved from backendDownloader interface
castorinop Feb 25, 2019
9131fbe
UI, Show Hide handler
castorinop Feb 25, 2019
93b8e22
Cleanup YTDL backend constructor
castorinop Feb 25, 2019
3e75884
Cleanup HTTP backend constructor
castorinop Feb 25, 2019
5d382a7
API add count
castorinop Feb 27, 2019
c1ea716
use namespaces for add styles and scripts
castorinop Apr 6, 2019
f295b4a
UI: similar view of files app
castorinop Apr 6, 2019
8ce7284
cleanup queue response
castorinop Apr 6, 2019
1cc9a57
CI: first try. from bookmarks app
castorinop Apr 6, 2019
b11488a
remove branches
castorinop Apr 6, 2019
dcf5a03
max version 16
castorinop Apr 6, 2019
6d1e488
fix typo.
castorinop Apr 6, 2019
a9875bf
cleanup old code
castorinop Apr 6, 2019
6aba46c
fix extra bracket
castorinop Apr 6, 2019
207595f
add test script
castorinop Apr 6, 2019
03ff9bf
copy Identifier Trait from Files External
castorinop Apr 9, 2019
202de59
resolve conflicts to merge e-alfred legacy code
castorinop Apr 9, 2019
731c95c
merge missing files
castorinop Apr 9, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
language: php
php:
- 7.1
- 7.2

env:
global:
- APP_NAME=ocdownloader
- PHP_COVERAGE=FALSE
matrix:
- DB=sqlite SERVER=nextcloud/travis_ci/master SERVER_BRANCH=master
- DB=mysql SERVER=nextcloud/travis_ci/master SERVER_BRANCH=master PHP_COVERAGE=TRUE
- DB=pgsql SERVER=nextcloud/travis_ci/master SERVER_BRANCH=master

matrix:
fast_finish: true

# branches:
# only:
# - master
#- /^stable\d+(\.\d+)?$/

before_install:
- wget https://raw.githubusercontent.com/$SERVER/before_install.sh
- . ./before_install.sh "$APP_NAME" "$SERVER_BRANCH" "$DB"
- cd ../core || cd ../server
- php occ app:enable $APP_NAME

before_script:
# Test lint
- cd apps/$APP_NAME
- find . -name \*.php -exec php -l "{}" \;

script:
- echo hello test
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ UWP Windows 8.1/10 app: https://github.com/e-alfred/ocDownloader_WindowsDesktop

If you want to write your own app or extension, this would be highly welcome. ocDownloader has an API (look at controller/lib/api.php here: https://github.com/e-alfred/ocdownloader/blob/master/controller/lib/api.php) that allows you to add and list downloads using ocDownloader.


## New Features
* Provide nextcloud API
* Implement Backends

## TO DO
* API Count, Cleanup, Hide, Pause, Remove
* Simplify API Syntax
* UI Use API
* Single Page Aplication UI
* Use Nextcloud Theme
* Cleanup Code
* Integration Tests
* Unit Tests

## ARIA2 installation
You have to install Aria2 on your system. To do this on Debian/Ubuntu you can use the following command:

Expand Down
2 changes: 1 addition & 1 deletion appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
\OC::$server->getNavigationManager()->add([
'id' => 'ocdownloader',
'order' => 10,
'href' => \OC::$server->getURLGenerator()->linkToRoute('ocdownloader.Index.Add'),
'href' => \OC::$server->getURLGenerator()->linkToRoute('ocdownloader.Index.All'),
'icon' => \OC::$server->getURLGenerator()->imagePath('ocdownloader', 'ocdownloader.svg'),
'name' => 'ocDownloader'
]);
Expand Down
193 changes: 99 additions & 94 deletions appinfo/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,105 +14,110 @@
use OCP\AppFramework\App;
use OCP\IContainer;

use OC\AppFramework\Utility\SimpleContainer;

use OCA\ocDownloader\Service\BackendService;
use \OCA\ocDownloader\Config\IBackendProvider;

use OCA\ocDownloader\Controller\Index;
use OCA\ocDownloader\Controller\HttpDownloader;
use OCA\ocDownloader\Controller\FtpDownloader;
use OCA\ocDownloader\Controller\YTDownloader;
use OCA\ocDownloader\Controller\BTDownloader;
use OCA\ocDownloader\Controller\Queue;
use OCA\ocDownloader\Controller\Updater;
use OCA\ocDownloader\Controller\PersonalSettings;
use OCA\ocDownloader\Controller\AdminSettings;

class Application extends App

class Application extends App implements IBackendProvider
{
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'),
$Container->query('Request'),
$Container->query('CurrentUID'),
$Container->getServer()->getL10N('ocdownloader')
);
});

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

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

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

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

$container->registerService('QueueController', function (IContainer $Container) {
return new Queue(
$Container->query('AppName'),
$Container->query('Request'),
$Container->query('CurrentUID'),
$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'),
$Container->query('Request'),
$Container->query('CurrentUID'),
$Container->getServer()->getL10N('ocdownloader')
);
});
}
public function __construct (Array $URLParams = Array ())
{
parent::__construct ('ocdownloader', $URLParams);
$container = $this->getContainer ();

$backendService = $container->query('OCA\\ocDownloader\\Service\\BackendService');
$backendService->registerBackendProvider($this);
//$backendService->getBackends();


$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'),
$Container->query ('Request'),
$Container->query ('CurrentUID'),
$Container->getServer ()->getL10N ('ocdownloader')
);
});


$container->registerService ('QueueController', function (IContainer $Container)
{
return new Queue
(
$Container->query ('AppName'),
$Container->query ('Request'),
$Container->query ('CurrentUID'),
$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'),
$Container->query ('Request'),
$Container->query ('CurrentUID'),
$Container->getServer ()->getL10N ('ocdownloader')
);
});

/* $container->registerService('APIController', function(SimpleContainer $Container) {
return new ApiController
(
$Container->query ('AppName'),
$Container->query ('Request'),
);
});*/

}

public function getBackends() {
$container = $this->getContainer();

$backends = [
$container->query('OCA\ocDownloader\Backend\MagnetBackend'),
$container->query('OCA\ocDownloader\Backend\YTDLBackend'),
$container->query('OCA\ocDownloader\Backend\HttpBackend'),
$container->query('OCA\ocDownloader\Backend\FtpBackend'),
];

return $backends;
}
}
1 change: 1 addition & 0 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
<nextcloud min-version="14" max-version="16" />
<lib>curl</lib>
</dependencies>
<namespace>ocDownloader</namespace>
</info>
43 changes: 10 additions & 33 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
'routes' => [
// Index
['name' => 'Index#Add', 'url' => '/add', 'verb' => 'GET'],
['name' => 'Index#All', 'url' => '/all', 'verb' => 'GET'],
['name' => 'Index#All', 'url' => '/', 'verb' => 'GET'],
['name' => 'Index#Completes', 'url' => '/completes', 'verb' => 'GET'],
['name' => 'Index#Actives', 'url' => '/actives', 'verb' => 'GET'],
['name' => 'Index#Waitings', 'url' => '/waitings', 'verb' => 'GET'],
Expand Down Expand Up @@ -58,37 +58,14 @@
['name' => 'PersonalSettings#Get', 'url' => '/personalsettings/get', 'verb' => 'GET'],

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

],
'ocs' => [
//API
['name' => 'Api#Handler', 'url' => '/api/handler', 'verb' => 'POST'],
['name' => 'Api#Add', 'url' => '/api/add', 'verb' => 'POST'],
['name' => 'Api#getQueue', 'url' => '/api/queue', 'verb' => 'POST'],
['name' => 'Api#getCount', 'url' => '/api/queue/count', 'verb' => 'POST']
]
));

$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
);

\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
);

\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
);
4 changes: 2 additions & 2 deletions controller/adminsettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
use OCP\IL10N;
use OCP\IRequest;

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

class AdminSettings extends Controller
{
Expand Down
Loading