From 662397c320c062354f9dcb7447a2f5a14e035d61 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Wed, 17 May 2023 23:16:11 -0700 Subject: [PATCH] nx: check version Signed-off-by: Varun Patil --- lib/Controller/PageController.php | 9 ++++++--- lib/Service/BinExt.php | 1 + lib/Util.php | 18 ++++++++++++++++-- templates/native-old.php | 3 +++ 4 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 templates/native-old.php diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 1933e738..9817d2ee 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -3,9 +3,11 @@ namespace OCA\Memories\Controller; use OCA\Files\Event\LoadSidebar; +use OCA\Memories\Service\BinExt; use OCA\Memories\Util; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\ContentSecurityPolicy; +use OCP\AppFramework\Http\Template\PublicTemplateResponse; use OCP\AppFramework\Http\TemplateResponse; use OCP\EventDispatcher\IEventDispatcher; use OCP\IRequest; @@ -40,9 +42,10 @@ class PageController extends Controller */ public function main() { - $user = $this->userSession->getUser(); - if (null === $user) { - return null; + // Check native version if available + $nativeVer = Util::callerNativeVersion(); + if (null !== $nativeVer && version_compare($nativeVer, BinExt::NX_VER_MIN, '<')) { + return new PublicTemplateResponse($this->appName, 'native-old'); } // Scripts diff --git a/lib/Service/BinExt.php b/lib/Service/BinExt.php index a72e2ae0..20e5d4e6 100644 --- a/lib/Service/BinExt.php +++ b/lib/Service/BinExt.php @@ -10,6 +10,7 @@ class BinExt { public const EXIFTOOL_VER = '12.60'; public const GOVOD_VER = '0.1.5'; + public const NX_VER_MIN = '1.0'; /** Copy a binary to temp dir for execution */ public static function getTempBin(string $path, string $name, bool $copy = true): string diff --git a/lib/Util.php b/lib/Util.php index 9a3daef4..08199761 100644 --- a/lib/Util.php +++ b/lib/Util.php @@ -404,12 +404,26 @@ class Util */ public static function callerIsNative(): bool { - $request = \OC::$server->get(\OCP\IRequest::class); - $userAgent = $request->getHeader('User-Agent'); + $userAgent = \OC::$server->get(\OCP\IRequest::class)->getHeader('User-Agent'); return false !== strpos($userAgent, 'MemoriesNative'); } + /** + * Get the version of the native caller. + */ + public static function callerNativeVersion(): ?string + { + $userAgent = \OC::$server->get(\OCP\IRequest::class)->getHeader('User-Agent'); + + $matches = []; + if (preg_match('/MemoriesNative\/([0-9.]+)/', $userAgent, $matches)) { + return $matches[1]; + } + + return null; + } + /** * Kill all instances of a process by name. * Similar to pkill, which may not be available on all systems. diff --git a/templates/native-old.php b/templates/native-old.php new file mode 100644 index 00000000..88c14f33 --- /dev/null +++ b/templates/native-old.php @@ -0,0 +1,3 @@ +
+ Your native app version is too old! Please update to the latest version. +
\ No newline at end of file