fixed issues with nc24(close #60);other improvements

This commit is contained in:
huangjx
2022-05-20 15:46:06 +08:00
parent 02fb165405
commit ac4aaa0c07
3 changed files with 30 additions and 8 deletions

View File

@@ -94,7 +94,7 @@ class YoutubeController extends Controller
}
$yt->dbDlPath = Helper::getDownloadDir();
$resp = $yt->forceIPV4()->download($url);
folderScan::sync();
folderScan::sync(true);
return new JSONResponse($resp);
}
private function downloadUrlSite($url)

View File

@@ -9,6 +9,7 @@ use OCA\NCDownloader\Tools\Settings;
use OCP\IUser;
use OC\Files\Filesystem;
use OC_Util;
use Psr\Log\LoggerInterface;
class Helper
{
@@ -113,8 +114,7 @@ class Helper
public static function cleanString($string)
{
$replace = array
(
$replace = array(
'/[áàâãªä]/u' => 'a',
'/[ÁÀÂÃÄ]/u' => 'A',
'/[ÍÌÎÏ]/u' => 'I',
@@ -502,4 +502,24 @@ class Helper
{
return self::getSettings('ncd_downloader_dir', "/Downloads");
}
public static function getVersion(): array
{
return \OC_Util::getVersion();
}
public static function isLegacyVersion(): bool
{
return (version_compare(implode(".", self::getVersion()), '20.0.0') <= 0);
}
public static function query($key)
{
return self::isLegacyVersion() ? \OC::$server->query($key) : \OC::$server->get($key);
}
public static function getLogger()
{
return (version_compare(implode(".", self::getVersion()), '24.0.0') <= 0) ? \OC::$server->getLogger() : \OC::$server->get(LoggerInterface::class);
}
public static function getDatabaseConnection()
{
return self::isLegacyVersion() ? \OC::$server->getDatabaseConnection() : \OC::$server->get(\OCP\IDBConnection::class);
}
}

View File

@@ -1,4 +1,5 @@
<?php
namespace OCA\NCDownloader\Tools;
use OCA\NCDownloader\Tools\Helper;
@@ -45,11 +46,11 @@ class folderScan
$this->scan();
return ['message' => "changed"];
}
//force update
//force update
public function scan()
{
$this->logger = \OC::$server->getLogger();
$this->scanner = new Scanner($this->user, \OC::$server->getDatabaseConnection(), \OC::$server->query(IEventDispatcher::class), $this->logger);
$this->logger = Helper::getLogger();
$this->scanner = new Scanner($this->user, Helper::getDatabaseConnection(), Helper::query(IEventDispatcher::class), $this->logger);
try {
$this->scanner->scan($this->path);
return ['status' => true, 'path' => $this->path];
@@ -64,8 +65,9 @@ class folderScan
}
//update only folder is modified
public static function sync($path = null, $user = null)
public static function sync($force = false, $path = null, $user = null)
{
return self::create($path, $user)->update();
$inst = self::create($path, $user);
return $force ? $inst->scan() : $inst->update();
}
}