1
0
Files
TaskBoard/backend/app/functions/routing.php
Falknat b4263bfe3f Добавлена загрузка rar, zip
1. Правка фронта
2. Правка бекенда
2026-01-12 07:01:31 +07:00

66 lines
2.0 KiB
PHP

<?php
// Обработка статических файлов
function routing_static_files() {
$requestUri = $_SERVER['REQUEST_URI'] ?? '';
$path = parse_url($requestUri, PHP_URL_PATH);
// Отдача файлов из /public/ (принудительное скачивание)
if (strpos($path, '/public/') === 0) {
$file = dirname(dirname(__DIR__)) . $path;
if (is_file($file)) {
header('Content-Type: application/octet-stream');
header('Content-Length: ' . filesize($file));
header('Content-Disposition: attachment; filename="' . basename($file) . '"');
readfile($file);
exit;
}
http_response_code(404);
exit;
}
// Игнорирование favicon и прочих статических запросов
if (preg_match('/\.(ico|css|js|woff|woff2|ttf|eot)$/i', $requestUri)) {
http_response_code(404);
exit;
}
}
// Проверка авторизации для API
function check_ApiAuth($publicActions = []) {
$requestUri = $_SERVER['REQUEST_URI'] ?? '';
if (strpos($requestUri, '/api/') !== false) {
$input = json_decode(file_get_contents('php://input'), true);
$action = $input['action'] ?? null;
// Публичные действия — без авторизации
if (!in_array($action, $publicActions)) {
$account = new Account();
$result = $account->check_session($_COOKIE['session'] ?? null);
if (!$result['success']) {
RestApi::response($result, 403);
}
}
}
}
// Функция роутинга API
function handleRouting($routes = []) {
$request = $_SERVER['REQUEST_URI'];
$path = parse_url($request, PHP_URL_PATH);
if (isset($routes[$path])) {
$file_path = $routes[$path];
global $_POST, $_FILES, $_SERVER, $_GET;
include $file_path;
exit;
}
}