Compare commits
2 Commits
bugfix/upl
...
main
Author | SHA1 | Date | |
---|---|---|---|
a5c9596397 | |||
461361d2ed |
@ -9,15 +9,12 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
runs-on: remote
|
runs-on: remote
|
||||||
steps:
|
steps:
|
||||||
- uses: https://git.simonis.lol/actions/checkout@v4
|
|
||||||
- uses: https://git.simonis.lol/actions/login@v1
|
|
||||||
with:
|
|
||||||
registry: git.simonis.lol
|
|
||||||
username: ${{ vars.DOCKER_USER }}
|
|
||||||
password: ${{ vars.DOCKER_PW }}
|
|
||||||
|
|
||||||
- name: build
|
- name: Checkout
|
||||||
run: docker build -t git.simonis.lol/sites/file-explorer:latest .
|
uses: https://git.simonis.lol/actions/checkout@v2
|
||||||
|
|
||||||
- name: push
|
- name: Build
|
||||||
run: docker push git.simonis.lol/sites/file-explorer:latest
|
run: docker buildx build -t git.simonis.lol/projects/file-explorer:latest .
|
||||||
|
|
||||||
|
- name: Push
|
||||||
|
run: docker push git.simonis.lol/projects/file-explorer:latest
|
@ -28,7 +28,7 @@ class HomeController extends AbstractController
|
|||||||
|
|
||||||
return $this->render('home.html.twig', [
|
return $this->render('home.html.twig', [
|
||||||
'content' => $fileSystemService->getDirs($dirs),
|
'content' => $fileSystemService->getDirs($dirs),
|
||||||
'fileForm' => $this->createForm(UploadFileForm::class, data: ['dirs' => $dirs]),
|
'fileForm' => $this->createForm(UploadFileForm::class),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -13,24 +13,17 @@ use Symfony\Component\Routing\Attribute\Route;
|
|||||||
|
|
||||||
class UploadController extends AbstractController
|
class UploadController extends AbstractController
|
||||||
{
|
{
|
||||||
#[Route(
|
#[Route(path: '/upload', name: 'app_upload', methods: Request::METHOD_POST)]
|
||||||
path: '/upload/{dirs?}',
|
|
||||||
name: 'app_upload',
|
|
||||||
requirements: ['dirs' => '.+'],
|
|
||||||
defaults: ['dirs' => ''],
|
|
||||||
methods: Request::METHOD_POST,
|
|
||||||
)]
|
|
||||||
public function __invoke(
|
public function __invoke(
|
||||||
FileSystemService $fileSystemService,
|
FileSystemService $fileSystemService,
|
||||||
Request $request,
|
Request $request,
|
||||||
string $dirs,
|
|
||||||
): Response
|
): Response
|
||||||
{
|
{
|
||||||
$fileData = new UploadedFileData(dir: $dirs);
|
$fileData = new UploadedFileData();
|
||||||
$form = $this->createForm(UploadFileForm::class, $fileData)->handleRequest($request);
|
$form = $this->createForm(UploadFileForm::class, $fileData)->handleRequest($request);
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
$fileSystemService->uploadFile($fileData);
|
$fileSystemService->uploadFile($fileData->files);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->redirectToRoute('app_home');
|
return $this->redirectToRoute('app_home');
|
||||||
|
@ -16,7 +16,7 @@ class UploadFileForm extends AbstractType
|
|||||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||||
{
|
{
|
||||||
$builder
|
$builder
|
||||||
->setAction($this->urlGenerator->generate('app_upload', ['dirs' => $options['data']['dirs']]))
|
->setAction($this->urlGenerator->generate('app_upload'))
|
||||||
->add('files', FileType::class, [
|
->add('files', FileType::class, [
|
||||||
'attr' => ['class' => 'hidden'],
|
'attr' => ['class' => 'hidden'],
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
|
@ -6,13 +6,8 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
|
|||||||
|
|
||||||
class UploadedFileData
|
class UploadedFileData
|
||||||
{
|
{
|
||||||
public function __construct(
|
/**
|
||||||
/**
|
* @var UploadedFile[] $files
|
||||||
* @var UploadedFile[] $files
|
*/
|
||||||
*/
|
public array $files;
|
||||||
public array $files = [],
|
|
||||||
|
|
||||||
public string $dir = '',
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -3,20 +3,18 @@
|
|||||||
namespace App\Service;
|
namespace App\Service;
|
||||||
|
|
||||||
use App\Objects\DirContent;
|
use App\Objects\DirContent;
|
||||||
use App\Objects\UploadedFileData;
|
|
||||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||||
use Symfony\Component\Filesystem\Exception\IOException;
|
use Symfony\Component\Filesystem\Exception\IOException;
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
use Symfony\Component\Finder\Finder;
|
use Symfony\Component\Finder\Finder;
|
||||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||||
use Symfony\Component\HttpFoundation\RequestStack;
|
|
||||||
|
|
||||||
class FileSystemService
|
class FileSystemService
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
#[Autowire(env: 'DATA_DIR')]
|
#[Autowire(env: 'DATA_DIR')]
|
||||||
private readonly string $dir,
|
private readonly string $dir,
|
||||||
private readonly Filesystem $filesystem,
|
private readonly Filesystem $filesystem,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,11 +35,13 @@ class FileSystemService
|
|||||||
return $contents;
|
return $contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function uploadFile(UploadedFileData $files): void
|
/**
|
||||||
|
* @param UploadedFile[] $files
|
||||||
|
*/
|
||||||
|
public function uploadFile(array $files): void
|
||||||
{
|
{
|
||||||
dd($files);
|
foreach ($files as $file) {
|
||||||
foreach ($files->files as $file) {
|
$this->filesystem->dumpFile($this->getTotalPath($file->getClientOriginalName()), $file->getContent());
|
||||||
$this->filesystem->dumpFile($files->dir . $this->getTotalPath($file->getClientOriginalName()), $file->getContent());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user