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";
|
||||
OC_Util::setupFS();
|
||||
//$this->config = \OC::$server->getAppConfig();
|
||||
|
||||
$this->aria2 = $aria2;
|
||||
|
||||
$this->aria2->init();
|
||||
$this->dbconn = new DBConn();
|
||||
}
|
||||
@@ -84,8 +82,8 @@ class Aria2Controller extends Controller
|
||||
}
|
||||
public function Update()
|
||||
{
|
||||
File::syncFolder($this->downloadDir);
|
||||
return new JSONResponse([]);
|
||||
$resp = File::syncFolder();
|
||||
//return new JSONResponse($resp);
|
||||
}
|
||||
|
||||
private function createActionItem($name, $path)
|
||||
@@ -99,6 +97,7 @@ class Aria2Controller extends Controller
|
||||
{
|
||||
//$path = $this->request->getRequestUri();
|
||||
$counter = $this->aria2->getCounters();
|
||||
$this->Update();
|
||||
switch (strtolower($path)) {
|
||||
case "active":
|
||||
$resp = $this->aria2->tellActive();
|
||||
|
||||
@@ -361,9 +361,9 @@ user-agent=Transmission/2.77
|
||||
seed-ratio=0.1
|
||||
bt-seed-unverified=true
|
||||
max-overall-upload-limit=1M
|
||||
#on-download-complete=$this->onDownloadComplete
|
||||
#on-download-error=$this->onDownloadError
|
||||
#on-download-start=$this->onDownloadStart
|
||||
#on-download-complete=
|
||||
#on-download-error=
|
||||
#on-download-start=
|
||||
save-session=$this->sessionFile
|
||||
input-file=$this->sessionFile
|
||||
log=$this->logFile
|
||||
|
||||
@@ -2,21 +2,33 @@
|
||||
namespace OCA\NCDownloader\Tools;
|
||||
|
||||
use OCA\NCDownloader\Tools\Helper;
|
||||
use OC\Files\Filesystem;
|
||||
use OCA\NCDownloader\Tools\Settings;
|
||||
use OC\Files\Utils\Scanner;
|
||||
use \OCP\EventDispatcher\IEventDispatcher;
|
||||
|
||||
class File
|
||||
{
|
||||
public static function syncFolder($dir)
|
||||
public static function syncFolder($dir = null)
|
||||
{
|
||||
$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();
|
||||
$scanner = new Scanner($user, \OC::$server->getDatabaseConnection(), \OC::$server->query(IEventDispatcher::class), $logger);
|
||||
$path = Filesystem::getRoot() . "/" . ltrim($dir, '/\\');
|
||||
try {
|
||||
$scanner->scan($path);
|
||||
// Helper::debug($logger->getLogPath());
|
||||
// Helper::debug($logger->getLogPath());
|
||||
//$logger->warning($logger->getLogPath(),['app' =>'Ncdownloader']);
|
||||
} catch (ForbiddenException $e) {
|
||||
$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());
|
||||
}
|
||||
return ['message' => "changed"];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace OCA\NCDownloader\Tools;
|
||||
|
||||
use OCA\NCDownloader\Tools\aria2Options;
|
||||
use OC\Files\Filesystem;
|
||||
|
||||
class Helper
|
||||
{
|
||||
@@ -242,7 +243,7 @@ class Helper
|
||||
public static function getTableTitles($type = null)
|
||||
{
|
||||
$general = ['filename', 'status', 'actions'];
|
||||
if(!isset($type)){
|
||||
if (!isset($type)) {
|
||||
return $general;
|
||||
}
|
||||
$titles = [
|
||||
@@ -253,5 +254,38 @@ class Helper
|
||||
];
|
||||
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