mirror of
https://github.com/bitinflow/expose.git
synced 2026-03-13 13:35:54 +00:00
Add statistic tracking
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Server\Http\Controllers\Admin;
|
||||
|
||||
use App\Contracts\ConnectionManager;
|
||||
use App\Contracts\StatisticsRepository;
|
||||
use App\Contracts\UserRepository;
|
||||
use App\Server\Configuration;
|
||||
use App\Server\Connections\ControlConnection;
|
||||
use Illuminate\Http\Request;
|
||||
use Ratchet\ConnectionInterface;
|
||||
|
||||
class GetStatisticsController extends AdminController
|
||||
{
|
||||
protected $keepConnectionOpen = true;
|
||||
|
||||
/** @var StatisticsRepository */
|
||||
protected $statisticsRepository;
|
||||
|
||||
public function __construct(StatisticsRepository $statisticsRepository)
|
||||
{
|
||||
$this->statisticsRepository = $statisticsRepository;
|
||||
}
|
||||
|
||||
public function handle(Request $request, ConnectionInterface $httpConnection)
|
||||
{
|
||||
$from = today()->subWeek()->toDateString();
|
||||
$until = today()->toDateString();
|
||||
|
||||
$this->statisticsRepository->getStatistics($request->get('from', $from), $request->get('until', $until))
|
||||
->then(function ($statistics) use ($httpConnection) {
|
||||
$httpConnection->send(
|
||||
respond_json([
|
||||
'statistics' => $statistics,
|
||||
])
|
||||
);
|
||||
|
||||
$httpConnection->close();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -235,7 +235,12 @@ class ControlMessageController implements MessageComponentInterface
|
||||
if (is_null($user)) {
|
||||
$deferred->reject();
|
||||
} else {
|
||||
$deferred->resolve($user);
|
||||
$this->userRepository
|
||||
->updateLastSharedAt($user['id'])
|
||||
->then(function () use ($deferred, $user) {
|
||||
$deferred->resolve($user);
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Server\Http\Controllers;
|
||||
|
||||
use App\Contracts\ConnectionManager;
|
||||
use App\Contracts\StatisticsCollector;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Server\Configuration;
|
||||
use App\Server\Connections\ControlConnection;
|
||||
@@ -27,10 +28,14 @@ class TunnelMessageController extends Controller
|
||||
|
||||
protected $modifiers = [];
|
||||
|
||||
public function __construct(ConnectionManager $connectionManager, Configuration $configuration)
|
||||
/** @var StatisticsCollector */
|
||||
protected $statisticsCollector;
|
||||
|
||||
public function __construct(ConnectionManager $connectionManager, StatisticsCollector $statisticsCollector, Configuration $configuration)
|
||||
{
|
||||
$this->connectionManager = $connectionManager;
|
||||
$this->configuration = $configuration;
|
||||
$this->statisticsCollector = $statisticsCollector;
|
||||
}
|
||||
|
||||
public function handle(Request $request, ConnectionInterface $httpConnection)
|
||||
@@ -57,6 +62,8 @@ class TunnelMessageController extends Controller
|
||||
return;
|
||||
}
|
||||
|
||||
$this->statisticsCollector->incomingRequest();
|
||||
|
||||
$this->sendRequestToClient($request, $controlConnection, $httpConnection);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user