From 9845fc05fa520bef4f161c41f84ec329a7384470 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 12 Dec 2021 21:58:17 +0400 Subject: [PATCH] feat: use Appwrite\Detector in database.php --- app/controllers/api/database.php | 49 ++++++++++++-------------------- 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/app/controllers/api/database.php b/app/controllers/api/database.php index d60d055912..a1e0780f19 100644 --- a/app/controllers/api/database.php +++ b/app/controllers/api/database.php @@ -32,7 +32,7 @@ use Appwrite\Network\Validator\Email; use Appwrite\Network\Validator\IP; use Appwrite\Network\Validator\URL; use Appwrite\Utopia\Response; -use DeviceDetector\DeviceDetector; +use Appwrite\Detector\Detector; /** * Create attribute of varying type @@ -529,24 +529,12 @@ App::get('/v1/database/collections/:collectionId/logs') foreach ($logs as $i => &$log) { $log['userAgent'] = (!empty($log['userAgent'])) ? $log['userAgent'] : 'UNKNOWN'; - $dd = new DeviceDetector($log['userAgent']); + $detector = new Detector($log['userAgent']); + $detector->skipBotDetection(); // OPTIONAL: If called, bot detection will completely be skipped (bots will be detected as regular devices then) - $dd->skipBotDetection(); // OPTIONAL: If called, bot detection will completely be skipped (bots will be detected as regular devices then) - - $dd->parse(); - - $os = $dd->getOs(); - $osCode = (isset($os['short_name'])) ? $os['short_name'] : ''; - $osName = (isset($os['name'])) ? $os['name'] : ''; - $osVersion = (isset($os['version'])) ? $os['version'] : ''; - - $client = $dd->getClient(); - $clientType = (isset($client['type'])) ? $client['type'] : ''; - $clientCode = (isset($client['short_name'])) ? $client['short_name'] : ''; - $clientName = (isset($client['name'])) ? $client['name'] : ''; - $clientVersion = (isset($client['version'])) ? $client['version'] : ''; - $clientEngine = (isset($client['engine'])) ? $client['engine'] : ''; - $clientEngineVersion = (isset($client['engine_version'])) ? $client['engine_version'] : ''; + $os = $detector->getOS(); + $client = $detector->getClient(); + $device = $detector->getDevice(); $output[$i] = new Document([ 'event' => $log['event'], @@ -556,19 +544,18 @@ App::get('/v1/database/collections/:collectionId/logs') 'mode' => $log['data']['mode'] ?? null, 'ip' => $log['ip'], 'time' => $log['time'], - - 'osCode' => $osCode, - 'osName' => $osName, - 'osVersion' => $osVersion, - 'clientType' => $clientType, - 'clientCode' => $clientCode, - 'clientName' => $clientName, - 'clientVersion' => $clientVersion, - 'clientEngine' => $clientEngine, - 'clientEngineVersion' => $clientEngineVersion, - 'deviceName' => $dd->getDeviceName(), - 'deviceBrand' => $dd->getBrandName(), - 'deviceModel' => $dd->getModel(), + 'osCode' => $os['osCode'], + 'osName' => $os['osName'], + 'osVersion' => $os['osVersion'], + 'clientType' => $client['clientType'], + 'clientCode' => $client['clientCode'], + 'clientName' => $client['clientName'], + 'clientVersion' => $client['clientVersion'], + 'clientEngine' => $client['clientEngine'], + 'clientEngineVersion' => $client['clientEngineVersion'], + 'deviceName' => $device['deviceName'], + 'deviceBrand' => $device['deviceBrand'], + 'deviceModel' => $device['deviceModel'], ]); $record = $geodb->get($log['ip']);