eeprom/src/LandingRoutes.php

49 lines
1.4 KiB
PHP
Raw Normal View History

2023-11-09 20:29:57 +00:00
<?php
namespace EEPROM;
use stdClass;
use Index\Routing\Route;
use Index\Routing\RouteHandler;
class LandingRoutes extends RouteHandler {
public function __construct(
private DatabaseContext $dbCtx
) {}
#[Route('GET', '/')]
public function getIndex($response) {
$response->accelRedirect('/index.html');
$response->setContentType('text/html; charset=utf-8');
}
#[Route('GET', '/stats.json')]
public function getStats() {
$dbConn = $this->dbCtx->getConnection();
$stats = new stdClass;
$stats->files = 0;
$stats->size = 0;
$stats->types = 0;
$stats->members = 0;
$result = $dbConn->query('SELECT COUNT(upload_id), SUM(upload_size), COUNT(DISTINCT upload_type) FROM prm_uploads WHERE upload_deleted IS NULL');
2023-11-09 20:29:57 +00:00
if($result->next()) {
$stats->files = $result->getInteger(0);
$stats->size = $result->getInteger(1);
$stats->types = $result->getInteger(2);
}
$result = $dbConn->query('SELECT COUNT(user_id) FROM prm_users WHERE user_restricted IS NULL');
if($result->next())
$stats->members = $result->getInteger(0);
return $stats;
}
#[Route('GET', '/eeprom.js')]
public function getEepromJs($response) {
$response->accelRedirect('/js/eeprom-v1.0.js');
$response->setContentType('application/javascript; charset=utf-8');
}
}