feat: use Appwrite\Detector in users.php
This commit is contained in:
parent
2b9f4667f7
commit
3d863d634a
|
@ -15,7 +15,7 @@ use Utopia\Audit\Audit;
|
||||||
use Utopia\Database\Document;
|
use Utopia\Database\Document;
|
||||||
use Utopia\Database\Exception\Duplicate;
|
use Utopia\Database\Exception\Duplicate;
|
||||||
use Utopia\Database\Validator\UID;
|
use Utopia\Database\Validator\UID;
|
||||||
use DeviceDetector\DeviceDetector;
|
use Appwrite\Detector\Detector;
|
||||||
use Appwrite\Database\Validator\CustomId;
|
use Appwrite\Database\Validator\CustomId;
|
||||||
use Utopia\Config\Config;
|
use Utopia\Config\Config;
|
||||||
use Utopia\Database\Database;
|
use Utopia\Database\Database;
|
||||||
|
@ -306,42 +306,29 @@ App::get('/v1/users/:userId/logs')
|
||||||
foreach ($logs as $i => &$log) {
|
foreach ($logs as $i => &$log) {
|
||||||
$log['userAgent'] = (!empty($log['userAgent'])) ? $log['userAgent'] : 'UNKNOWN';
|
$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)
|
$os = $detector->getOS();
|
||||||
|
$client = $detector->getClient();
|
||||||
$dd->parse();
|
$device = $detector->getDevice();
|
||||||
|
|
||||||
$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'] : '';
|
|
||||||
|
|
||||||
$output[$i] = new Document([
|
$output[$i] = new Document([
|
||||||
'event' => $log['event'],
|
'event' => $log['event'],
|
||||||
'ip' => $log['ip'],
|
'ip' => $log['ip'],
|
||||||
'time' => $log['time'],
|
'time' => $log['time'],
|
||||||
|
'osCode' => $os['osCode'],
|
||||||
'osCode' => $osCode,
|
'osName' => $os['osName'],
|
||||||
'osName' => $osName,
|
'osVersion' => $os['osVersion'],
|
||||||
'osVersion' => $osVersion,
|
'clientType' => $client['clientType'],
|
||||||
'clientType' => $clientType,
|
'clientCode' => $client['clientCode'],
|
||||||
'clientCode' => $clientCode,
|
'clientName' => $client['clientName'],
|
||||||
'clientName' => $clientName,
|
'clientVersion' => $client['clientVersion'],
|
||||||
'clientVersion' => $clientVersion,
|
'clientEngine' => $client['clientEngine'],
|
||||||
'clientEngine' => $clientEngine,
|
'clientEngineVersion' => $client['clientEngineVersion'],
|
||||||
'clientEngineVersion' => $clientEngineVersion,
|
'deviceName' => $device['deviceName'],
|
||||||
'deviceName' => $dd->getDeviceName(),
|
'deviceBrand' => $device['deviceBrand'],
|
||||||
'deviceBrand' => $dd->getBrandName(),
|
'deviceModel' => $device['deviceModel'],
|
||||||
'deviceModel' => $dd->getModel(),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$record = $geodb->get($log['ip']);
|
$record = $geodb->get($log['ip']);
|
||||||
|
|
|
@ -97,4 +97,16 @@ class Detector
|
||||||
|
|
||||||
return $this->detctor;
|
return $this->detctor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether to skip bot detection.
|
||||||
|
* It is needed if we want bots to be processed as a simple clients. So we can detect if it is mobile client,
|
||||||
|
* or desktop, or enything else. By default all this information is not retrieved for the bots.
|
||||||
|
*
|
||||||
|
* @param bool $skip
|
||||||
|
*/
|
||||||
|
public function skipBotDetection(bool $skip = true): void
|
||||||
|
{
|
||||||
|
$this->getDetector()->skipBotDetection($skip);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue