first commit

This commit is contained in:
huangjx
2021-09-09 22:03:08 +08:00
commit f2a2365102
74 changed files with 33916 additions and 0 deletions

23
appinfo/app.php Normal file
View File

@@ -0,0 +1,23 @@
<?php
/**
* ownCloud - ncdownloader
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the LICENSE file.
*
* @author Xavier Beurois <www.sgc-univ.net>
* @copyright Xavier Beurois 2015
*/
namespace OCA\NcDownloader\AppInfo;
\OC::$server->getNavigationManager()->add([
'id' => 'ncdownloader',
'order' => 10,
'href' => \OC::$server->getURLGenerator()->linkToRoute('ncdownloader.Main.Index'),
'icon' => \OC::$server->getURLGenerator()->imagePath('ncdownloader', 'ncdownloader.svg'),
'name' => 'ncdownloader'
]);
//\OCP\App::registerAdmin('ncdownloader', 'settings/admin');
//\OCP\App::registerPersonal('ncdownloader', 'settings/personal');

80
appinfo/application.php Normal file
View File

@@ -0,0 +1,80 @@
<?php
namespace OCA\NcDownloader\AppInfo;
use OCA\NcDownloader\Controller\MainController;
use OCA\NcDownloader\Controller\Aria2Controller;
use OCA\NcDownloader\Tools\Aria2;
use OCA\NcDownloader\Tools\Settings;
use OCP\AppFramework\App;
use OCP\IContainer;
use \OC\Files\Filesystem;
class Application extends App
{
public function __construct(array $urlParams = array())
{
parent::__construct('ncdownloader', $urlParams);
$container = $this->getContainer();
$container->registerService('UserId', function (IContainer $container) {
$user = \OC::$server->getUserSession()->getUser();
return ($user) ? $user->getUID() : '';
});
$container->registerService('Aria2', function (IContainer $container) {
$uid = $container->query('UserId');
return new Aria2($this->getConfig($uid));
});
$container->registerService('Settings', function (IContainer $container) {
$uid = $container->query('UserId');
return new Settings($uid);
});
$container->registerService('MainController', function (IContainer $container) {
return new MainController(
$container->query('AppName'),
$container->query('Request'),
$container->query('UserId'),
\OC::$server->getL10N('ncdownloader'),
\OC::$server->getRootFolder(),
$container->query('Aria2')
);
});
$container->registerService('Aria2Controller', function (IContainer $container) {
return new Aria2Controller(
$container->query('AppName'),
$container->query('Request'),
$container->query('UserId'),
\OC::$server->getL10N('ncdownloader'),
\OC::$server->getRootFolder(),
$container->query('Aria2')
);
});
}
private function getConfig($uid)
{
//$this->config = \OC::$server->getAppConfig();
$this->settings = new Settings($uid);
$this->userFolder = Filesystem::getRoot();
$this->dataDir = \OC::$server->getSystemConfig()->getValue('datadirectory');
//relative nextcloud user path
$this->downloadDir = $this->settings->get('ncd_downloader_dir') ?? "/Downloads";
$this->torrentsDir = $this->settings->get('torrents_dir');
//get the absolute path
$this->realDownloadDir = $this->dataDir . $this->userFolder . $this->downloadDir;
$aria2_dir = $this->dataDir . "/aria2";
$this->appPath = \OC::$server->getAppManager()->getAppPath('ncdownloader');
$settings['seed_time'] = $this->settings->get("ncd_seed_time");
$settings['seed_ratio'] = $this->settings->get("ncd_seed_ratio");
if (is_array($customSettings = $this->settings->getAria2())) {
$settings = array_merge($customSettings, $settings);
}
$token = $this->settings->setType(1)->get('ncd_rpctoken');
$config = ['dir' => $this->realDownloadDir, 'conf_dir' => $aria2_dir, 'token' => $token, 'settings' => $settings];
return $config;
}
}

32
appinfo/info.xml Normal file
View File

@@ -0,0 +1,32 @@
<?xml version="1.0"?>
<info xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/info.xsd">
<id>ncdownloader</id>
<name>Nc Downloader</name>
<summary>Aria2 and youtube-dl web gui for nextcloud</summary>
<description><![CDATA[Nexcloud Frontend for Aria2 and Youtube-dl]]></description>
<version>0.0.1</version>
<licence>agpl</licence>
<author mail="freefallbenson@gmail.com" homepage="https://github.com/shiningw">jiaxinhuang</author>
<namespace>NcDownloader</namespace>
<category>tools</category>
<bugs>https://github.com/shiningw</bugs>
<dependencies>
<nextcloud min-version="18" max-version="22"/>
</dependencies>
<navigations>
<navigation>
<name>ncdownloader</name>
<route>ncdownloader.Main.Index</route>
</navigation>
</navigations>
<settings>
<admin>OCA\NcDownloader\Settings\Admin</admin>
<personal>OCA\NcDownloader\Settings\Personal</personal>
<admin-section>OCA\NcDownloader\Settings\AdminSection</admin-section>
<personal-section>OCA\NcDownloader\Settings\PersonalSection</personal-section>
</settings>
<commands>
<command>OCA\NcDownloader\Command\Aria2Command</command>
</commands>
</info>

28
appinfo/routes.php Normal file
View File

@@ -0,0 +1,28 @@
<?php
/**
* Create your routes in here. The name is the lowercase name of the controller
* without the controller part, the stuff after the hash is the method.
* e.g. page#index -> OCA\NcDownloader\Controller\Aria2Controller->index()
*
* The controller class has to be registered in the application.php file since
* it's instantiated in there
*/
return [
'routes' => [
['name' => 'Main#Index', 'url' => '/', 'verb' => 'GET'],
['name' => 'main#newDownload', 'url' => '/new', 'verb' => 'POST'],
['name' => 'Aria2#Action', 'url' => '/aria2/{path}', 'verb' => 'POST'],
['name' => 'Aria2#getStatus', 'url' => '/status/{path}', 'verb' => 'POST'],
['name' => 'Aria2#Update', 'url' => '/update', 'verb' => 'GET'],
//['name' => 'main#checkStatus', 'url' => '/checkstatus', 'verb' => 'POST'],
// AdminSettings
['name' => 'Settings#Admin', 'url' => '/admin/save', 'verb' => 'POST'],
// PersonalSettings
['name' => 'Settings#Personal', 'url' => '/personal/save', 'verb' => 'POST'],
['name' => 'Settings#aria2Get', 'url' => '/personal/aria2/get', 'verb' => 'POST'],
['name' => 'Settings#aria2Save', 'url' => '/personal/aria2/save', 'verb' => 'POST'],
['name' => 'Settings#aria2Delete', 'url' => '/personal/aria2/delete', 'verb' => 'POST'],
]
];