new helper function to retrieve settings

This commit is contained in:
huangjx
2022-04-22 18:29:21 +08:00
parent 49477881a9
commit 5ae1685044
7 changed files with 29 additions and 24 deletions

View File

@@ -399,16 +399,12 @@ class Helper
public static function getRealDownloadDir($uid = null): string
{
$uid = $uid ?? self::getUID();
$settings = new Settings($uid);
$dlDir = $settings->get('ncd_downloader_dir') ?? "/Downloads";
$dlDir = self::getDownloadDir();;
return self::getLocalFolder($dlDir);
}
public static function getRealTorrentsDir($uid = null): string
{
$uid = $uid ?? self::getUID();
$settings = new Settings($uid);
$dir = $settings->get('ncd_torrents_dir') ?? "/Torrents";
$dir = self::getSettings('ncd_torrents_dir', "/Torrents");
return self::getLocalFolder($dir);
}
@@ -422,14 +418,24 @@ class Helper
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();
$settings = new Settings($uid);
return Settings::create($uid);
}
public static function getYoutubeConfig($uid = null): array
{
$config = [
'binary' => $settings->setType(Settings::TYPE['SYSTEM'])->get("ncd_yt_binary"),
'binary' => self::getSettings("ncd_yt_binary", null, Settings::TYPE['SYSTEM']),
'downloadDir' => Helper::getRealDownloadDir(),
'settings' => $settings->setType(Settings::TYPE['USER'])->getYoutube(),
'settings' => self::newSettings()->getYoutube(),
];
return $config;
}
@@ -438,7 +444,7 @@ class Helper
{
$options = [];
$uid = $uid ?? self::getUID();
$settings = new Settings($uid);
$settings = self::newSettings($uid);
$realDownloadDir = Helper::getRealDownloadDir($uid);
$torrentsDir = Helper::getRealTorrentsDir($uid);
$appPath = self::getAppPath();
@@ -467,7 +473,7 @@ class Helper
{
return \OC::$server->getAppManager()->getAppPath('ncdownloader');
}
public static function folderUpdated(string $dir):bool
public static function folderUpdated(string $dir): bool
{
if (!file_exists($dir)) {
return false;
@@ -486,4 +492,8 @@ class Helper
}
return false;
}
public static function getDownloadDir(): string
{
return self::getSettings('ncd_downloader_dir', "/Downloads");
}
}

View File

@@ -20,8 +20,7 @@ class folderScan
public function getDefaultPath()
{
$settings = new Settings($this->user);
return $settings->get('ncd_downloader_dir') ?? "/Downloads";
return Helper::getDownloadDir();
}
public static function create($path = null, $user = null)
{