new helper function to retrieve settings
This commit is contained in:
@@ -32,8 +32,7 @@ class Aria2Controller extends Controller
|
|||||||
$this->l10n = $IL10N;
|
$this->l10n = $IL10N;
|
||||||
$this->rootFolder = $rootFolder;
|
$this->rootFolder = $rootFolder;
|
||||||
$this->urlGenerator = \OC::$server->getURLGenerator();
|
$this->urlGenerator = \OC::$server->getURLGenerator();
|
||||||
$this->settings = new Settings($UserId);
|
$this->downloadDir = Helper::getDownloadDir();
|
||||||
$this->downloadDir = $this->settings->get('ncd_downloader_dir') ?? "/Downloads";
|
|
||||||
OC_Util::setupFS();
|
OC_Util::setupFS();
|
||||||
//$this->config = \OC::$server->getAppConfig();
|
//$this->config = \OC::$server->getAppConfig();
|
||||||
$this->aria2 = $aria2;
|
$this->aria2 = $aria2;
|
||||||
|
|||||||
@@ -38,10 +38,9 @@ class MainController extends Controller
|
|||||||
$this->dbconn = new DbHelper();
|
$this->dbconn = new DbHelper();
|
||||||
$this->counters = new Counters($aria2, $this->dbconn, $UserId);
|
$this->counters = new Counters($aria2, $this->dbconn, $UserId);
|
||||||
$this->youtube = $youtube;
|
$this->youtube = $youtube;
|
||||||
$this->settings = new Settings($this->uid);
|
|
||||||
$this->isAdmin = \OC_User::isAdminUser($this->uid);
|
$this->isAdmin = \OC_User::isAdminUser($this->uid);
|
||||||
$this->hideError = $this->settings->get("ncd_hide_errors", false);
|
$this->hideError = Helper::getSettings("ncd_hide_errors", false);
|
||||||
$this->disable_bt_nonadmin = $this->settings->setType($this->settings::TYPE['SYSTEM'])->get("ncd_disable_bt", false);
|
$this->disable_bt_nonadmin = Helper::getSettings("ncd_disable_bt", false, Settings::TYPE["SYSTEM"]);
|
||||||
$this->accessDenied = $this->l10n->t("Sorry,only admin users can download files via BT!");
|
$this->accessDenied = $this->l10n->t("Sorry,only admin users can download files via BT!");
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ class SettingsController extends Controller
|
|||||||
{
|
{
|
||||||
$saved = json_decode($this->settings->get("custom_youtube_dl_settings"), 1);
|
$saved = json_decode($this->settings->get("custom_youtube_dl_settings"), 1);
|
||||||
$params = $this->request->getParams();
|
$params = $this->request->getParams();
|
||||||
foreach ($data as $key => $value) {
|
foreach ($params as $key => $value) {
|
||||||
unset($saved[$key]);
|
unset($saved[$key]);
|
||||||
}
|
}
|
||||||
$resp = $this->settings->save("custom_youtube_dl_settings", json_encode($saved));
|
$resp = $this->settings->save("custom_youtube_dl_settings", json_encode($saved));
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ use OCA\NCDownloader\Tools\Aria2;
|
|||||||
use OCA\NCDownloader\Tools\DbHelper;
|
use OCA\NCDownloader\Tools\DbHelper;
|
||||||
use OCA\NCDownloader\Tools\folderScan;
|
use OCA\NCDownloader\Tools\folderScan;
|
||||||
use OCA\NCDownloader\Tools\Helper;
|
use OCA\NCDownloader\Tools\Helper;
|
||||||
use OCA\NCDownloader\Tools\Settings;
|
|
||||||
use OCA\NCDownloader\Tools\Youtube;
|
use OCA\NCDownloader\Tools\Youtube;
|
||||||
use OCP\AppFramework\Controller;
|
use OCP\AppFramework\Controller;
|
||||||
use OCP\AppFramework\Http\JSONResponse;
|
use OCP\AppFramework\Http\JSONResponse;
|
||||||
@@ -26,8 +25,7 @@ class YoutubeController extends Controller
|
|||||||
$this->uid = $UserId;
|
$this->uid = $UserId;
|
||||||
$this->urlGenerator = \OC::$server->getURLGenerator();
|
$this->urlGenerator = \OC::$server->getURLGenerator();
|
||||||
$this->l10n = $IL10N;
|
$this->l10n = $IL10N;
|
||||||
$this->settings = new Settings($UserId);
|
$this->downloadDir = Helper::getDownloadDir();
|
||||||
$this->downloadDir = $this->settings->get('ncd_downloader_dir') ?? "/Downloads";
|
|
||||||
$this->dbconn = new DbHelper();
|
$this->dbconn = new DbHelper();
|
||||||
$this->youtube = $youtube;
|
$this->youtube = $youtube;
|
||||||
$this->aria2 = $aria2;
|
$this->aria2 = $aria2;
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class Personal implements ISettings {
|
|||||||
*/
|
*/
|
||||||
public function getForm() {
|
public function getForm() {
|
||||||
$parameters = [
|
$parameters = [
|
||||||
"ncd_downloader_dir" => $this->settings->get("ncd_downloader_dir"),
|
"ncd_downloader_dir" => Helper::getDownloadDir(),
|
||||||
"ncd_torrents_dir" => $this->settings->get("ncd_torrents_dir"),
|
"ncd_torrents_dir" => $this->settings->get("ncd_torrents_dir"),
|
||||||
"ncd_seed_ratio" => $this->settings->get("ncd_seed_ratio"),
|
"ncd_seed_ratio" => $this->settings->get("ncd_seed_ratio"),
|
||||||
'ncd_seed_time_unit' => $this->settings->get("ncd_seed_time_unit"),
|
'ncd_seed_time_unit' => $this->settings->get("ncd_seed_time_unit"),
|
||||||
|
|||||||
@@ -399,16 +399,12 @@ class Helper
|
|||||||
|
|
||||||
public static function getRealDownloadDir($uid = null): string
|
public static function getRealDownloadDir($uid = null): string
|
||||||
{
|
{
|
||||||
$uid = $uid ?? self::getUID();
|
$dlDir = self::getDownloadDir();;
|
||||||
$settings = new Settings($uid);
|
|
||||||
$dlDir = $settings->get('ncd_downloader_dir') ?? "/Downloads";
|
|
||||||
return self::getLocalFolder($dlDir);
|
return self::getLocalFolder($dlDir);
|
||||||
}
|
}
|
||||||
public static function getRealTorrentsDir($uid = null): string
|
public static function getRealTorrentsDir($uid = null): string
|
||||||
{
|
{
|
||||||
$uid = $uid ?? self::getUID();
|
$dir = self::getSettings('ncd_torrents_dir', "/Torrents");
|
||||||
$settings = new Settings($uid);
|
|
||||||
$dir = $settings->get('ncd_torrents_dir') ?? "/Torrents";
|
|
||||||
return self::getLocalFolder($dir);
|
return self::getLocalFolder($dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -422,14 +418,24 @@ class Helper
|
|||||||
return self::getUser()->getUID();
|
return self::getUser()->getUID();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getYoutubeConfig($uid = null): array
|
public static function getSettings($key, $default = null, int $type = Settings::TYPE['USER'])
|
||||||
|
{
|
||||||
|
$settings = self::newSettings();
|
||||||
|
return $settings->setType($type)->get($key, $default);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function newSettings($uid = null)
|
||||||
{
|
{
|
||||||
$uid = $uid ?? self::getUID();
|
$uid = $uid ?? self::getUID();
|
||||||
$settings = new Settings($uid);
|
return Settings::create($uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getYoutubeConfig($uid = null): array
|
||||||
|
{
|
||||||
$config = [
|
$config = [
|
||||||
'binary' => $settings->setType(Settings::TYPE['SYSTEM'])->get("ncd_yt_binary"),
|
'binary' => self::getSettings("ncd_yt_binary", null, Settings::TYPE['SYSTEM']),
|
||||||
'downloadDir' => Helper::getRealDownloadDir(),
|
'downloadDir' => Helper::getRealDownloadDir(),
|
||||||
'settings' => $settings->setType(Settings::TYPE['USER'])->getYoutube(),
|
'settings' => self::newSettings()->getYoutube(),
|
||||||
];
|
];
|
||||||
return $config;
|
return $config;
|
||||||
}
|
}
|
||||||
@@ -438,7 +444,7 @@ class Helper
|
|||||||
{
|
{
|
||||||
$options = [];
|
$options = [];
|
||||||
$uid = $uid ?? self::getUID();
|
$uid = $uid ?? self::getUID();
|
||||||
$settings = new Settings($uid);
|
$settings = self::newSettings($uid);
|
||||||
$realDownloadDir = Helper::getRealDownloadDir($uid);
|
$realDownloadDir = Helper::getRealDownloadDir($uid);
|
||||||
$torrentsDir = Helper::getRealTorrentsDir($uid);
|
$torrentsDir = Helper::getRealTorrentsDir($uid);
|
||||||
$appPath = self::getAppPath();
|
$appPath = self::getAppPath();
|
||||||
@@ -467,7 +473,7 @@ class Helper
|
|||||||
{
|
{
|
||||||
return \OC::$server->getAppManager()->getAppPath('ncdownloader');
|
return \OC::$server->getAppManager()->getAppPath('ncdownloader');
|
||||||
}
|
}
|
||||||
public static function folderUpdated(string $dir):bool
|
public static function folderUpdated(string $dir): bool
|
||||||
{
|
{
|
||||||
if (!file_exists($dir)) {
|
if (!file_exists($dir)) {
|
||||||
return false;
|
return false;
|
||||||
@@ -486,4 +492,8 @@ class Helper
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
public static function getDownloadDir(): string
|
||||||
|
{
|
||||||
|
return self::getSettings('ncd_downloader_dir', "/Downloads");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,7 @@ class folderScan
|
|||||||
|
|
||||||
public function getDefaultPath()
|
public function getDefaultPath()
|
||||||
{
|
{
|
||||||
$settings = new Settings($this->user);
|
return Helper::getDownloadDir();
|
||||||
return $settings->get('ncd_downloader_dir') ?? "/Downloads";
|
|
||||||
}
|
}
|
||||||
public static function create($path = null, $user = null)
|
public static function create($path = null, $user = null)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user