27 lines
791 B
PHP
27 lines
791 B
PHP
|
<?php
|
||
|
|
||
|
namespace App\Controller;
|
||
|
|
||
|
use App\Service\FileService;
|
||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||
|
use Symfony\Component\HttpFoundation\Request;
|
||
|
use Symfony\Component\Routing\Annotation\Route;
|
||
|
|
||
|
class FileController extends AbstractController
|
||
|
{
|
||
|
#[Route('/user/file/{id}', name: 'app_files', methods: ['GET'])]
|
||
|
public function browse(int $id, Request $request, FileService $fileService): JsonResponse
|
||
|
{
|
||
|
$relativePath = $request->query->get('path', '');
|
||
|
|
||
|
try {
|
||
|
$files = $fileService->list($id, '');
|
||
|
|
||
|
return $this->json(['files' => $files]);
|
||
|
} catch (\Exception $e) {
|
||
|
return $this->json(['error' => $e->getMessage()], 400);
|
||
|
}
|
||
|
}
|
||
|
}
|