From 5c05ce5e8bb9064ecef4abc161dd71df5cc2f5a0 Mon Sep 17 00:00:00 2001 From: huangjx Date: Wed, 16 Feb 2022 21:15:37 +0800 Subject: [PATCH] moved settings button to bottom and made it collapsible;use nc's built-in filepicker to set download and torrents folders;fixed issues of youtube-dl filenames exceeding the maximum length --- lib/Controller/MainController.php | 5 ++++- lib/Tools/Helper.php | 8 +++++--- lib/Tools/Youtube.php | 4 ++-- package.json | 2 ++ src/css/style.scss | 6 +++++- src/index.js | 4 ---- src/settings.js | 16 ++++++++++++++++ templates/Navigation.php | 6 +----- templates/settings/Settings.php | 28 ++++++++++++++++++++++++++++ webpack.app.js | 10 +++++++--- 10 files changed, 70 insertions(+), 19 deletions(-) create mode 100644 templates/settings/Settings.php diff --git a/lib/Controller/MainController.php b/lib/Controller/MainController.php index dddd7af..f4b6af5 100644 --- a/lib/Controller/MainController.php +++ b/lib/Controller/MainController.php @@ -33,6 +33,7 @@ class MainController extends Controller OC_Util::setupFS(); $this->aria2 = $aria2; $this->aria2->init(); + $this->urlGenerator = \OC::$server->getURLGenerator(); $this->dbconn = new DbHelper(); $this->counters = new Counters($aria2, $this->dbconn, $UserId); } @@ -51,7 +52,9 @@ class MainController extends Controller $params['aria2_installed'] = $this->aria2->isInstalled(); $params['youtube_installed'] = (bool) Helper::findBinaryPath('youtube-dl'); $params['counter'] = $this->counters->getCounters(); - + $params['settings_url'] = $this->urlGenerator->linkToRoute("settings.PersonalSettings.index", ['section' => 'ncdownloader']); + $params['admin_settings_url'] = $this->urlGenerator->linkToRoute("settings.AdminSettings.index", ['section' => 'ncdownloader']); + $params['is_admin'] = \OC_User::isAdminUser($this->uid); $response = new TemplateResponse($this->appName, 'Index', $params); return $response; diff --git a/lib/Tools/Helper.php b/lib/Tools/Helper.php index 65114af..8405cbf 100644 --- a/lib/Tools/Helper.php +++ b/lib/Tools/Helper.php @@ -9,6 +9,7 @@ class Helper { public const DOWNLOADTYPE = ['ARIA2' => 1, 'YOUTUBE-DL' => 2, 'OTHERS' => 3]; public const STATUS = ['ACTIVE' => 1, 'PAUSED' => 2, 'COMPLETE' => 3, 'WAITING' => 4, 'ERROR' => 5]; + const MAXLEN = 255; public static function isUrl($URL) { @@ -41,7 +42,7 @@ class Helper public static function isGetUrlSite($url) { $host = parse_url($url, PHP_URL_HOST); - $sites = ['twitter.com', 'www.twitter.com']; + //$sites = ['twitter.com', 'www.twitter.com']; return (bool) (in_array($host, $sites)); } public static function parseUrl($url) @@ -66,10 +67,11 @@ class Helper public static function getFilename($url) { if (self::isMagnet($url)) { - return self::parseUrl($url)['dn']; + $filename = self::parseUrl($url)['dn']; } else { - return self::getUrlPath($url); + $filename = self::getUrlPath($url); } + return substr($filename, 0, self::MAXLEN); } public static function formatBytes($size, $precision = 2) { diff --git a/lib/Tools/Youtube.php b/lib/Tools/Youtube.php index e8a9f60..b75a32f 100644 --- a/lib/Tools/Youtube.php +++ b/lib/Tools/Youtube.php @@ -15,7 +15,7 @@ class Youtube private $options = []; private $downloadDir; private $timeout = 60 * 60 * 10; //10 hours - private $outTpl = "%(id)s-%(title)s.%(ext)s"; + private $outTpl = "%(id)s-%(title).64s.%(ext)s"; private $defaultDir = "/tmp/downloads"; private $env = []; @@ -66,7 +66,7 @@ class Youtube if (Helper::ffmpegInstalled()) { $this->addOption('--prefer-ffmpeg'); $this->addOption('--add-metadata'); - $this->setOption('--metadata-from-title', "%(artist)s-%(title)s"); + $this->setOption('--metadata-from-title', "%(artist)s-%(title).64s"); $this->addOption('--extract-audio'); } $pos = strrpos($this->outTpl, '.'); diff --git a/package.json b/package.json index f1b51da..df6b9d7 100755 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "stylelint:fix": "stylelint src --fix" }, "dependencies": { + "toastr": "^2.1.4", "v-tooltip": "^4.0.0-alpha.1" }, "engines": { @@ -63,6 +64,7 @@ "vue": "^3.2.20", "vue-loader": "^16.0.0-beta.10", "vue-svg-loader": "^0.17.0-beta.2", + "webpack": "^5.69.0", "webpack-cli": "^4.9.0" } } diff --git a/src/css/style.scss b/src/css/style.scss index f2c1277..7a99d38 100644 --- a/src/css/style.scss +++ b/src/css/style.scss @@ -1,3 +1,7 @@ +#ncdownloader-settings-collapsible-container { + padding-left: 4%; +} + .action-item { position: relative; } @@ -114,7 +118,7 @@ div .number { padding-top: 0.3em; } -.app-ncdownloader #app-content-wrapper { +.app-ncdownloader #app-content-wrapper { flex-wrap: wrap; } diff --git a/src/index.js b/src/index.js index 2b78a84..6a67ba0 100644 --- a/src/index.js +++ b/src/index.js @@ -31,10 +31,6 @@ window.addEventListener('DOMContentLoaded', function () { helper.aria2Toggle(data); }).send(); }) - eventHandler.add("click", '#ncdownloader-user-settings button', function (e) { - let link = helper.generateUrl(e.target.getAttribute('path')); - window.location.href = link; - }) eventHandler.add("click", "#app-navigation", "#search-download", helper.showDownload); delegate('#ncdownloader-table-wrapper', { target: '[data-tippy-content]' } diff --git a/src/settings.js b/src/settings.js index 87a0656..74bf450 100644 --- a/src/settings.js +++ b/src/settings.js @@ -126,4 +126,20 @@ window.addEventListener('DOMContentLoaded', function () { } settingsForm.getInstance().setParent("custom-youtube-dl-settings-container").render(input); }).send(); + const filepicker = function (event) { + let element = event.target; + OC.dialogs.filepicker( + t('ncdownloader', 'Select a directory'), + function (path) { + if (element.value !== path) { + element.value = path; + } + }, + false, + 'httpd/unix-directory', + true + ); + } + eventHandler.add('click', "#ncd_downloader_dir", filepicker); + eventHandler.add('click', "#ncd_torrents_dir", filepicker); }); \ No newline at end of file diff --git a/templates/Navigation.php b/templates/Navigation.php index 3fd606c..75e0447 100644 --- a/templates/Navigation.php +++ b/templates/Navigation.php @@ -23,11 +23,6 @@ $aria2_installed = $_['aria2_installed']; -
- -
+ inc('settings/Settings'));?> \ No newline at end of file diff --git a/templates/settings/Settings.php b/templates/settings/Settings.php new file mode 100644 index 0000000..3a24141 --- /dev/null +++ b/templates/settings/Settings.php @@ -0,0 +1,28 @@ + +
+
+ +
+ +
\ No newline at end of file diff --git a/webpack.app.js b/webpack.app.js index 51532ea..01f2bbc 100644 --- a/webpack.app.js +++ b/webpack.app.js @@ -4,9 +4,9 @@ const { VueLoaderPlugin } = require('vue-loader') module.exports = { - experiments: { + /* experiments: { asset: true - }, + },*/ entry: { app: './src/index.js', appSettings: './src/settings.js' @@ -72,5 +72,9 @@ module.exports = { jquery: "jQuery", "window.jQuery": "jquery" }), - ] + ], + externals: { + jquery: 'jQuery', + OC: "OC" + }, }; \ No newline at end of file