eeprom/src/LandingRoutes.php

48 lines
1.4 KiB
PHP
Raw Normal View History

2023-11-09 20:29:57 +00:00
<?php
namespace EEPROM;
use stdClass;
2024-03-29 23:21:40 +00:00
use Index\Http\Routing\{HttpGet,RouteHandler};
2023-11-09 20:29:57 +00:00
class LandingRoutes extends RouteHandler {
public function __construct(
private DatabaseContext $dbCtx
) {}
2024-03-29 23:21:40 +00:00
#[HttpGet('/')]
2023-11-09 20:29:57 +00:00
public function getIndex($response) {
$response->accelRedirect('/index.html');
$response->setContentType('text/html; charset=utf-8');
}
2024-03-29 23:21:40 +00:00
#[HttpGet('/stats.json')]
2023-11-09 20:29:57 +00:00
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;
}
2024-03-29 23:21:40 +00:00
#[HttpGet('/eeprom.js')]
2023-11-09 20:29:57 +00:00
public function getEepromJs($response) {
2024-02-02 21:00:24 +00:00
$response->accelRedirect('/scripts/eepromv1.js');
2023-11-09 20:29:57 +00:00
$response->setContentType('application/javascript; charset=utf-8');
}
}