fixed issues of download folder not being updated promptly
This commit is contained in:
@@ -35,9 +35,7 @@ class Aria2Controller extends Controller
|
|||||||
$this->downloadDir = $this->settings->get('ncd_downloader_dir') ?? "/Downloads";
|
$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;
|
||||||
|
|
||||||
$this->aria2->init();
|
$this->aria2->init();
|
||||||
$this->dbconn = new DBConn();
|
$this->dbconn = new DBConn();
|
||||||
}
|
}
|
||||||
@@ -84,8 +82,8 @@ class Aria2Controller extends Controller
|
|||||||
}
|
}
|
||||||
public function Update()
|
public function Update()
|
||||||
{
|
{
|
||||||
File::syncFolder($this->downloadDir);
|
$resp = File::syncFolder();
|
||||||
return new JSONResponse([]);
|
//return new JSONResponse($resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createActionItem($name, $path)
|
private function createActionItem($name, $path)
|
||||||
@@ -99,6 +97,7 @@ class Aria2Controller extends Controller
|
|||||||
{
|
{
|
||||||
//$path = $this->request->getRequestUri();
|
//$path = $this->request->getRequestUri();
|
||||||
$counter = $this->aria2->getCounters();
|
$counter = $this->aria2->getCounters();
|
||||||
|
$this->Update();
|
||||||
switch (strtolower($path)) {
|
switch (strtolower($path)) {
|
||||||
case "active":
|
case "active":
|
||||||
$resp = $this->aria2->tellActive();
|
$resp = $this->aria2->tellActive();
|
||||||
|
|||||||
@@ -361,9 +361,9 @@ user-agent=Transmission/2.77
|
|||||||
seed-ratio=0.1
|
seed-ratio=0.1
|
||||||
bt-seed-unverified=true
|
bt-seed-unverified=true
|
||||||
max-overall-upload-limit=1M
|
max-overall-upload-limit=1M
|
||||||
#on-download-complete=$this->onDownloadComplete
|
#on-download-complete=
|
||||||
#on-download-error=$this->onDownloadError
|
#on-download-error=
|
||||||
#on-download-start=$this->onDownloadStart
|
#on-download-start=
|
||||||
save-session=$this->sessionFile
|
save-session=$this->sessionFile
|
||||||
input-file=$this->sessionFile
|
input-file=$this->sessionFile
|
||||||
log=$this->logFile
|
log=$this->logFile
|
||||||
|
|||||||
@@ -2,21 +2,33 @@
|
|||||||
namespace OCA\NCDownloader\Tools;
|
namespace OCA\NCDownloader\Tools;
|
||||||
|
|
||||||
use OCA\NCDownloader\Tools\Helper;
|
use OCA\NCDownloader\Tools\Helper;
|
||||||
use OC\Files\Filesystem;
|
use OCA\NCDownloader\Tools\Settings;
|
||||||
use OC\Files\Utils\Scanner;
|
use OC\Files\Utils\Scanner;
|
||||||
use \OCP\EventDispatcher\IEventDispatcher;
|
use \OCP\EventDispatcher\IEventDispatcher;
|
||||||
|
|
||||||
class File
|
class File
|
||||||
{
|
{
|
||||||
public static function syncFolder($dir)
|
public static function syncFolder($dir = null)
|
||||||
{
|
{
|
||||||
$user = \OC::$server->getUserSession()->getUser()->getUID();
|
$user = \OC::$server->getUserSession()->getUser()->getUID();
|
||||||
|
if (!isset($dir)) {
|
||||||
|
$settings = new Settings($user);
|
||||||
|
$downloadDir = $settings->get('ncd_downloader_dir') ?? "/Downloads";
|
||||||
|
$rootFolder = Helper::getUserFolder($user);
|
||||||
|
$path = $rootFolder . "/" . ltrim($downloadDir, '/\\');
|
||||||
|
} else {
|
||||||
|
$path = $dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
$realDir =\OC::$server->getSystemConfig()->getValue('datadirectory') . "/" . $path;
|
||||||
|
if (!(Helper::folderUpdated($realDir))) {
|
||||||
|
return ['message' => "no change"];
|
||||||
|
}
|
||||||
$logger = \OC::$server->getLogger();
|
$logger = \OC::$server->getLogger();
|
||||||
$scanner = new Scanner($user, \OC::$server->getDatabaseConnection(), \OC::$server->query(IEventDispatcher::class), $logger);
|
$scanner = new Scanner($user, \OC::$server->getDatabaseConnection(), \OC::$server->query(IEventDispatcher::class), $logger);
|
||||||
$path = Filesystem::getRoot() . "/" . ltrim($dir, '/\\');
|
|
||||||
try {
|
try {
|
||||||
$scanner->scan($path);
|
$scanner->scan($path);
|
||||||
// Helper::debug($logger->getLogPath());
|
// Helper::debug($logger->getLogPath());
|
||||||
//$logger->warning($logger->getLogPath(),['app' =>'Ncdownloader']);
|
//$logger->warning($logger->getLogPath(),['app' =>'Ncdownloader']);
|
||||||
} catch (ForbiddenException $e) {
|
} catch (ForbiddenException $e) {
|
||||||
$logger->warning("Make sure you're running the scan command only as the user the web server runs as");
|
$logger->warning("Make sure you're running the scan command only as the user the web server runs as");
|
||||||
@@ -24,5 +36,7 @@ class File
|
|||||||
|
|
||||||
$logger->warning("Exception during scan: " . $e->getMessage() . $e->getTraceAsString());
|
$logger->warning("Exception during scan: " . $e->getMessage() . $e->getTraceAsString());
|
||||||
}
|
}
|
||||||
|
return ['message' => "changed"];
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace OCA\NCDownloader\Tools;
|
namespace OCA\NCDownloader\Tools;
|
||||||
|
|
||||||
use OCA\NCDownloader\Tools\aria2Options;
|
use OCA\NCDownloader\Tools\aria2Options;
|
||||||
|
use OC\Files\Filesystem;
|
||||||
|
|
||||||
class Helper
|
class Helper
|
||||||
{
|
{
|
||||||
@@ -242,7 +243,7 @@ class Helper
|
|||||||
public static function getTableTitles($type = null)
|
public static function getTableTitles($type = null)
|
||||||
{
|
{
|
||||||
$general = ['filename', 'status', 'actions'];
|
$general = ['filename', 'status', 'actions'];
|
||||||
if(!isset($type)){
|
if (!isset($type)) {
|
||||||
return $general;
|
return $general;
|
||||||
}
|
}
|
||||||
$titles = [
|
$titles = [
|
||||||
@@ -253,5 +254,38 @@ class Helper
|
|||||||
];
|
];
|
||||||
return $titles[$type];
|
return $titles[$type];
|
||||||
}
|
}
|
||||||
|
// the relative home folder of a nextcloud user
|
||||||
|
public static function getUserFolder($uid = null)
|
||||||
|
{
|
||||||
|
if (!empty($rootFolder = Filesystem::getRoot())) {
|
||||||
|
return $rootFolder;
|
||||||
|
} else if (isset($uid)) {
|
||||||
|
return "/" . strtolower($uid) . "/files";
|
||||||
|
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function folderUpdated($dir)
|
||||||
|
{
|
||||||
|
if (!file_exists($dir)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$checkFile = $dir . "/.lastmodified";
|
||||||
|
if (!file_exists($checkFile)) {
|
||||||
|
$time = \filemtime($dir);
|
||||||
|
file_put_contents($checkFile, $time);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$lastModified = (int) file_get_contents($checkFile);
|
||||||
|
|
||||||
|
$time = \filemtime($dir);
|
||||||
|
|
||||||
|
if ($time > $lastModified) {
|
||||||
|
file_put_contents($checkFile, $time);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user