eeprom/src/LandingRoutes.php

47 lines
1.4 KiB
PHP

<?php
namespace EEPROM;
use stdClass;
use Index\Http\Routing\{HttpGet,RouteHandler};
class LandingRoutes extends RouteHandler {
public function __construct(
private DatabaseContext $dbCtx
) {}
#[HttpGet('/')]
public function getIndex($response) {
$response->accelRedirect('/index.html');
$response->setContentType('text/html; charset=utf-8');
}
#[HttpGet('/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');
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;
}
#[HttpGet('/eeprom.js')]
public function getEepromJs($response) {
$response->accelRedirect('/scripts/eepromv1.js');
$response->setContentType('application/javascript; charset=utf-8');
}
}