mirror of
https://github.com/ceratic/MediaCollectorLibary.git
synced 2026-05-13 23:56:46 +02:00
Enhance API functionality and improve JWT authentication
- Added JWT authentication support in AuthService and JwtService. - Implemented token generation and refresh mechanisms. - Updated ApiAuthMiddleware to handle authentication for protected routes. - Created ApiController and BaseApiController for standardized API responses. - Developed MediaController for managing media items with pagination and search capabilities. - Introduced DocsController for serving API documentation via Swagger UI. - Added routes for API documentation and media management. - Improved error handling and response formatting across API endpoints. - Updated composer.json to include necessary JWT and Swagger UI dependencies.
This commit is contained in:
42
routes/api-docs.php
Normal file
42
routes/api-docs.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Slim\Routing\RouteCollectorProxy;
|
||||
use App\Controllers\Api\DocsController;
|
||||
|
||||
// Documentation routes
|
||||
$app->group('/docs', function (RouteCollectorProxy $group) {
|
||||
$docsController = $this->get(DocsController::class);
|
||||
|
||||
// Documentation UI
|
||||
$group->get('/api', [$docsController, 'showDocs']);
|
||||
|
||||
// OpenAPI JSON specification
|
||||
$group->get('/api-docs.json', [$docsController, 'getOpenApiSpec']);
|
||||
|
||||
// Serve Swagger UI assets
|
||||
$group->get('/swagger-ui/{file:.+}', function (Request $request, Response $response, array $args) {
|
||||
$file = $args['file'];
|
||||
$swaggerUiPath = __DIR__ . '/../../vendor/swagger-api/swagger-ui/dist';
|
||||
$filePath = $swaggerUiPath . '/' . $file;
|
||||
|
||||
if (!file_exists($filePath)) {
|
||||
return $response->withStatus(404, 'File not found');
|
||||
}
|
||||
|
||||
$extension = pathinfo($file, PATHINFO_EXTENSION);
|
||||
$contentTypes = [
|
||||
'css' => 'text/css',
|
||||
'js' => 'application/javascript',
|
||||
'png' => 'image/png',
|
||||
'json' => 'application/json',
|
||||
'html' => 'text/html',
|
||||
];
|
||||
|
||||
$contentType = $contentTypes[$extension] ?? 'text/plain';
|
||||
|
||||
$response->getBody()->write(file_get_contents($filePath));
|
||||
return $response->withHeader('Content-Type', $contentType);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user