forked from projects/file-explorer
Compare commits
13 Commits
feature/go
...
main
Author | SHA1 | Date | |
---|---|---|---|
557dda99d6 | |||
a5c9596397 | |||
461361d2ed | |||
a67b93ac99 | |||
5fcc7c78bb | |||
bca12e5483 | |||
c1e1ab081f | |||
4826805f57 | |||
ca9a18987b | |||
0e53f0a199 | |||
831466cba9 | |||
12730b8bcd | |||
a574c3a89a |
@ -7,8 +7,8 @@ xdebug_enabled: false
|
|||||||
additional_hostnames: []
|
additional_hostnames: []
|
||||||
additional_fqdns: []
|
additional_fqdns: []
|
||||||
database:
|
database:
|
||||||
type: mariadb
|
type: postgres
|
||||||
version: "10.11"
|
version: "17"
|
||||||
use_dns_when_possible: true
|
use_dns_when_possible: true
|
||||||
composer_version: "2"
|
composer_version: "2"
|
||||||
web_environment: []
|
web_environment: []
|
||||||
|
@ -7,17 +7,14 @@ on:
|
|||||||
- main
|
- main
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: remote
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: docker/login-action@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
|
@ -17,4 +17,4 @@ RUN docker-php-ext-install pdo pdo_mysql mysqli gd opcache intl zip calendar dom
|
|||||||
RUN pecl install apcu && docker-php-ext-enable apcu
|
RUN pecl install apcu && docker-php-ext-enable apcu
|
||||||
|
|
||||||
WORKDIR /var/www/project
|
WORKDIR /var/www/project
|
||||||
RUN composer install --no-dev --optimize-autoloader --no-suggest --no-progress
|
RUN composer install --optimize-autoloader --no-suggest --no-progress
|
||||||
|
@ -2,7 +2,6 @@ import { Controller } from '@hotwired/stimulus';
|
|||||||
|
|
||||||
export default class extends Controller {
|
export default class extends Controller {
|
||||||
connect() {
|
connect() {
|
||||||
console.log(this.element);
|
|
||||||
this.element.querySelector('input').addEventListener('change', () => {
|
this.element.querySelector('input').addEventListener('change', () => {
|
||||||
this.element.querySelector('button[type="submit"]').click();
|
this.element.querySelector('button[type="submit"]').click();
|
||||||
});
|
});
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
body {
|
body {
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
a:hover {
|
||||||
|
color: deepskyblue;
|
||||||
|
text-decoration: underline;
|
||||||
}
|
}
|
@ -15,6 +15,7 @@
|
|||||||
"symfony/flex": "^2",
|
"symfony/flex": "^2",
|
||||||
"symfony/form": "^7.1",
|
"symfony/form": "^7.1",
|
||||||
"symfony/framework-bundle": "7.1.*",
|
"symfony/framework-bundle": "7.1.*",
|
||||||
|
"symfony/mime": "7.1.*",
|
||||||
"symfony/runtime": "7.1.*",
|
"symfony/runtime": "7.1.*",
|
||||||
"symfony/stimulus-bundle": "^2.22",
|
"symfony/stimulus-bundle": "^2.22",
|
||||||
"symfony/twig-bundle": "7.1.*",
|
"symfony/twig-bundle": "7.1.*",
|
||||||
@ -22,7 +23,8 @@
|
|||||||
"symfony/yaml": "7.1.*",
|
"symfony/yaml": "7.1.*",
|
||||||
"symfonycasts/tailwind-bundle": "^0.6.1",
|
"symfonycasts/tailwind-bundle": "^0.6.1",
|
||||||
"twig/extra-bundle": "^2.12|^3.0",
|
"twig/extra-bundle": "^2.12|^3.0",
|
||||||
"twig/twig": "^2.12|^3.0"
|
"twig/twig": "^2.12|^3.0",
|
||||||
|
"ext-fileinfo": "*"
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"allow-plugins": {
|
"allow-plugins": {
|
||||||
|
169
composer.lock
generated
169
composer.lock
generated
@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "8278464727736866734f277693979fb2",
|
"content-hash": "46ba6e6e4f31d38d71c65f5acfdff136",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "composer/semver",
|
"name": "composer/semver",
|
||||||
@ -1993,6 +1993,90 @@
|
|||||||
],
|
],
|
||||||
"time": "2024-11-13T14:25:32+00:00"
|
"time": "2024-11-13T14:25:32+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "symfony/mime",
|
||||||
|
"version": "v7.1.6",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/symfony/mime.git",
|
||||||
|
"reference": "caa1e521edb2650b8470918dfe51708c237f0598"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/symfony/mime/zipball/caa1e521edb2650b8470918dfe51708c237f0598",
|
||||||
|
"reference": "caa1e521edb2650b8470918dfe51708c237f0598",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=8.2",
|
||||||
|
"symfony/polyfill-intl-idn": "^1.10",
|
||||||
|
"symfony/polyfill-mbstring": "^1.0"
|
||||||
|
},
|
||||||
|
"conflict": {
|
||||||
|
"egulias/email-validator": "~3.0.0",
|
||||||
|
"phpdocumentor/reflection-docblock": "<3.2.2",
|
||||||
|
"phpdocumentor/type-resolver": "<1.4.0",
|
||||||
|
"symfony/mailer": "<6.4",
|
||||||
|
"symfony/serializer": "<6.4.3|>7.0,<7.0.3"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"egulias/email-validator": "^2.1.10|^3.1|^4",
|
||||||
|
"league/html-to-markdown": "^5.0",
|
||||||
|
"phpdocumentor/reflection-docblock": "^3.0|^4.0|^5.0",
|
||||||
|
"symfony/dependency-injection": "^6.4|^7.0",
|
||||||
|
"symfony/process": "^6.4|^7.0",
|
||||||
|
"symfony/property-access": "^6.4|^7.0",
|
||||||
|
"symfony/property-info": "^6.4|^7.0",
|
||||||
|
"symfony/serializer": "^6.4.3|^7.0.3"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Symfony\\Component\\Mime\\": ""
|
||||||
|
},
|
||||||
|
"exclude-from-classmap": [
|
||||||
|
"/Tests/"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Fabien Potencier",
|
||||||
|
"email": "fabien@symfony.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Symfony Community",
|
||||||
|
"homepage": "https://symfony.com/contributors"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Allows manipulating MIME messages",
|
||||||
|
"homepage": "https://symfony.com",
|
||||||
|
"keywords": [
|
||||||
|
"mime",
|
||||||
|
"mime-type"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"source": "https://github.com/symfony/mime/tree/v7.1.6"
|
||||||
|
},
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"url": "https://symfony.com/sponsor",
|
||||||
|
"type": "custom"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://github.com/fabpot",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||||
|
"type": "tidelift"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"time": "2024-10-25T15:11:02+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/options-resolver",
|
"name": "symfony/options-resolver",
|
||||||
"version": "v7.1.9",
|
"version": "v7.1.9",
|
||||||
@ -2222,6 +2306,89 @@
|
|||||||
],
|
],
|
||||||
"time": "2024-09-09T11:45:10+00:00"
|
"time": "2024-09-09T11:45:10+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "symfony/polyfill-intl-idn",
|
||||||
|
"version": "v1.31.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/symfony/polyfill-intl-idn.git",
|
||||||
|
"reference": "c36586dcf89a12315939e00ec9b4474adcb1d773"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/c36586dcf89a12315939e00ec9b4474adcb1d773",
|
||||||
|
"reference": "c36586dcf89a12315939e00ec9b4474adcb1d773",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=7.2",
|
||||||
|
"symfony/polyfill-intl-normalizer": "^1.10"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"ext-intl": "For best performance"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"thanks": {
|
||||||
|
"url": "https://github.com/symfony/polyfill",
|
||||||
|
"name": "symfony/polyfill"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"files": [
|
||||||
|
"bootstrap.php"
|
||||||
|
],
|
||||||
|
"psr-4": {
|
||||||
|
"Symfony\\Polyfill\\Intl\\Idn\\": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Laurent Bassin",
|
||||||
|
"email": "laurent@bassin.info"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Trevor Rowbotham",
|
||||||
|
"email": "trevor.rowbotham@pm.me"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Symfony Community",
|
||||||
|
"homepage": "https://symfony.com/contributors"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions",
|
||||||
|
"homepage": "https://symfony.com",
|
||||||
|
"keywords": [
|
||||||
|
"compatibility",
|
||||||
|
"idn",
|
||||||
|
"intl",
|
||||||
|
"polyfill",
|
||||||
|
"portable",
|
||||||
|
"shim"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"source": "https://github.com/symfony/polyfill-intl-idn/tree/v1.31.0"
|
||||||
|
},
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"url": "https://symfony.com/sponsor",
|
||||||
|
"type": "custom"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://github.com/fabpot",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||||
|
"type": "tidelift"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"time": "2024-09-09T11:45:10+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/polyfill-intl-normalizer",
|
"name": "symfony/polyfill-intl-normalizer",
|
||||||
"version": "v1.31.0",
|
"version": "v1.31.0",
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
twig:
|
twig:
|
||||||
file_name_pattern: '*.twig'
|
file_name_pattern: '*.twig'
|
||||||
|
globals:
|
||||||
|
routing_service: '@App\Service\Twig\RoutingService'
|
||||||
|
|
||||||
when@test:
|
when@test:
|
||||||
twig:
|
twig:
|
||||||
|
@ -11,11 +11,23 @@ use Symfony\Component\Routing\Attribute\Route;
|
|||||||
|
|
||||||
class HomeController extends AbstractController
|
class HomeController extends AbstractController
|
||||||
{
|
{
|
||||||
#[Route(path: '/files', name: 'app_home', methods: [Request::METHOD_GET])]
|
#[Route(
|
||||||
public function __invoke(FileSystemService $fileSystemService): Response
|
path: '/files/{dirs?}',
|
||||||
|
name: 'app_home',
|
||||||
|
requirements: ['dirs' => '.+'],
|
||||||
|
defaults: ['dirs' => ''],
|
||||||
|
methods: [Request::METHOD_GET]
|
||||||
|
)]
|
||||||
|
public function __invoke(FileSystemService $fileSystemService, string $dirs): Response
|
||||||
{
|
{
|
||||||
|
if ($fileSystemService->isFile(substr_replace($dirs, '', -1))) {
|
||||||
|
return $this->render('file.html.twig', [
|
||||||
|
'file' => $fileSystemService->getFile((string) substr_replace($dirs, '', -1)),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->render('home.html.twig', [
|
return $this->render('home.html.twig', [
|
||||||
'content' => $fileSystemService->getDirs(),
|
'content' => $fileSystemService->getDirs($dirs),
|
||||||
'fileForm' => $this->createForm(UploadFileForm::class),
|
'fileForm' => $this->createForm(UploadFileForm::class),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
28
src/Controller/ServeFileController.php
Normal file
28
src/Controller/ServeFileController.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Service\FileSystemService;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||||
|
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
|
class ServeFileController extends AbstractController
|
||||||
|
{
|
||||||
|
public function __construct(private FileSystemService $fileSystemService)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route("/serve/{filePath}", name: "serve_file")]
|
||||||
|
public function __invoke(string $filePath): BinaryFileResponse
|
||||||
|
{
|
||||||
|
$file = $this->fileSystemService->getFile($filePath);
|
||||||
|
$path = $file->getPath() . '/' . $file->getName();
|
||||||
|
|
||||||
|
$response = new BinaryFileResponse($path);
|
||||||
|
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $file->getName());
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
}
|
@ -23,7 +23,7 @@ class UploadController extends AbstractController
|
|||||||
$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->file);
|
$fileSystemService->uploadFile($fileData->files);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->redirectToRoute('app_home');
|
return $this->redirectToRoute('app_home');
|
||||||
|
@ -17,7 +17,7 @@ class UploadFileForm extends AbstractType
|
|||||||
{
|
{
|
||||||
$builder
|
$builder
|
||||||
->setAction($this->urlGenerator->generate('app_upload'))
|
->setAction($this->urlGenerator->generate('app_upload'))
|
||||||
->add('file', FileType::class, [
|
->add('files', FileType::class, [
|
||||||
'attr' => ['class' => 'hidden'],
|
'attr' => ['class' => 'hidden'],
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
]);
|
]);
|
||||||
|
@ -6,22 +6,27 @@ namespace App\Objects;
|
|||||||
|
|
||||||
use SplFileInfo;
|
use SplFileInfo;
|
||||||
|
|
||||||
class DirContent
|
readonly class DirContent
|
||||||
{
|
{
|
||||||
private function __construct(
|
private function __construct(
|
||||||
private readonly string $name,
|
private string $name,
|
||||||
private readonly int $size,
|
private int $size,
|
||||||
private readonly string $type,
|
private string $type,
|
||||||
)
|
private string $path,
|
||||||
{
|
private string $content,
|
||||||
|
private string $mimeType,
|
||||||
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function make(SplFileInfo $fileInfo): DirContent
|
public static function make(SplFileInfo $fileInfo, string $content = ''): DirContent
|
||||||
{
|
{
|
||||||
return new self(
|
return new self(
|
||||||
$fileInfo->getBasename(),
|
$fileInfo->getBasename(),
|
||||||
$fileInfo->getSize() ?? 0,
|
$fileInfo->getSize() ?? 0,
|
||||||
$fileInfo->getType() ?? 'N/A',
|
$fileInfo->getType() ?? 'N/A',
|
||||||
|
$fileInfo->getPath(),
|
||||||
|
$content,
|
||||||
|
mime_content_type($fileInfo->getPath() . '/' . $fileInfo->getFilename()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,10 +49,25 @@ class DirContent
|
|||||||
return $this->type;
|
return $this->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getHumanReadableSize()
|
public function getPath(): string
|
||||||
|
{
|
||||||
|
return $this->path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getContent(): string
|
||||||
|
{
|
||||||
|
return $this->content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMimeType(): string
|
||||||
|
{
|
||||||
|
return $this->mimeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getHumanReadableSize(): string
|
||||||
{
|
{
|
||||||
$bytes = $this->size;
|
$bytes = $this->size;
|
||||||
$size = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
|
$size = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
||||||
$factor = floor((strlen((string) $bytes) - 1) / 3);
|
$factor = floor((strlen((string) $bytes) - 1) / 3);
|
||||||
|
|
||||||
return sprintf("%.1f %s", $bytes / (1024 ** $factor), $size[$factor]);
|
return sprintf("%.1f %s", $bytes / (1024 ** $factor), $size[$factor]);
|
||||||
|
@ -7,7 +7,7 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
|
|||||||
class UploadedFileData
|
class UploadedFileData
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var UploadedFile[] $file
|
* @var UploadedFile[] $files
|
||||||
*/
|
*/
|
||||||
public array $file;
|
public array $files;
|
||||||
}
|
}
|
@ -4,6 +4,7 @@ namespace App\Service;
|
|||||||
|
|
||||||
use App\Objects\DirContent;
|
use App\Objects\DirContent;
|
||||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||||
|
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;
|
||||||
@ -20,10 +21,10 @@ class FileSystemService
|
|||||||
/**
|
/**
|
||||||
* @return DirContent[]
|
* @return DirContent[]
|
||||||
*/
|
*/
|
||||||
public function getDirs(): array
|
public function getDirs(string $dirs): array
|
||||||
{
|
{
|
||||||
$finder = new Finder();
|
$finder = new Finder();
|
||||||
$finder->in($this->dir);
|
$finder->in($this->getTotalPath($dirs));
|
||||||
|
|
||||||
$contents = [];
|
$contents = [];
|
||||||
|
|
||||||
@ -40,7 +41,40 @@ class FileSystemService
|
|||||||
public function uploadFile(array $files): void
|
public function uploadFile(array $files): void
|
||||||
{
|
{
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
$this->filesystem->dumpFile($this->dir . '/' . $file->getClientOriginalName(), $file->getContent());
|
$this->filesystem->dumpFile($this->getTotalPath($file->getClientOriginalName()), $file->getContent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isFile(string $dirs): bool
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$this->filesystem->readFile($this->getTotalPath($dirs));
|
||||||
|
} catch (IOException) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFile(string $filePath): DirContent
|
||||||
|
{
|
||||||
|
$dirs = explode('/', $filePath);
|
||||||
|
$fileName = array_pop($dirs);
|
||||||
|
|
||||||
|
$finder = new Finder();
|
||||||
|
$finder->in($this->getTotalPath(implode('/', $dirs)));
|
||||||
|
|
||||||
|
foreach ($finder as $file) {
|
||||||
|
if ($file->getFilename() === $fileName) {
|
||||||
|
return DirContent::make($file, $this->filesystem->readFile($this->getTotalPath($filePath)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new \RuntimeException('File not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getTotalPath(string $filePath): string
|
||||||
|
{
|
||||||
|
return $this->dir . '/' . $filePath;
|
||||||
|
}
|
||||||
}
|
}
|
25
src/Service/Twig/RoutingService.php
Normal file
25
src/Service/Twig/RoutingService.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Service\Twig;
|
||||||
|
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||||
|
|
||||||
|
class RoutingService
|
||||||
|
{
|
||||||
|
public function __construct(private UrlGeneratorInterface $urlGenerator)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function goBack(Request $request): string
|
||||||
|
{
|
||||||
|
$dirsString = $request->attributes->get('dirs', '');
|
||||||
|
$dirs = explode('/', $dirsString);
|
||||||
|
if (array_pop($dirs) === '') {
|
||||||
|
array_pop($dirs);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->urlGenerator->generate('app_home', ['dirs' => implode('/', $dirs)]);
|
||||||
|
}
|
||||||
|
}
|
@ -1,13 +1,24 @@
|
|||||||
|
{% if file.name == '..' %}
|
||||||
|
{% set link = routing_service.goBack(app.request) %}
|
||||||
|
{% else %}
|
||||||
|
{% set link = path('app_home', {dirs: app.request.attributes.get('dirs', '/') ~ file.name ~ '/'}) %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
<tr class="border-b">
|
<tr class="border-b">
|
||||||
<th scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">
|
<th scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">
|
||||||
{% if file.type == 'dir' %}
|
<a href="{{ link }}">
|
||||||
{{ ux_icon('folder:closed', {height: '32px', width: '32px'}) }}
|
{% if file.type == 'dir' %}
|
||||||
{% else %}
|
{{ ux_icon('folder:closed', {height: '32px', width: '32px'}) }}
|
||||||
{{ ux_icon('file:default', {height: '32px', width: '32px'}) }}
|
{% else %}
|
||||||
{% endif %}
|
{{ ux_icon('file:default', {height: '32px', width: '32px'}) }}
|
||||||
|
{% endif %}
|
||||||
|
</a>
|
||||||
</th>
|
</th>
|
||||||
<td class="px-6 py-4">
|
<td class="px-6 py-4">
|
||||||
{{ file.name }}
|
<a href="{{ link }}">
|
||||||
|
{{ file.name }}
|
||||||
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td class="px-6 py-4">
|
<td class="px-6 py-4">
|
||||||
{{ file.size }}
|
{{ file.size }}
|
||||||
|
@ -14,6 +14,9 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
{% if app.request.requestUri != '/files' %}
|
||||||
|
{% include '_partials/_row.html.twig' with {file: {name: '..', size: '-', type: 'dir'}} %}
|
||||||
|
{% endif %}
|
||||||
{% for dirContent in content %}
|
{% for dirContent in content %}
|
||||||
{% include '_partials/_row.html.twig' with {file: dirContent} %}
|
{% include '_partials/_row.html.twig' with {file: dirContent} %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@ -24,12 +27,14 @@
|
|||||||
|
|
||||||
{{ form_start(fileForm, {'attr': {'data-controller': 'upload-file'}}) }}
|
{{ form_start(fileForm, {'attr': {'data-controller': 'upload-file'}}) }}
|
||||||
<div class="flex items-center justify-center max-w-4xl mt-5">
|
<div class="flex items-center justify-center max-w-4xl mt-5">
|
||||||
<label for="upload_file_form_file" class="flex flex-col items-center justify-center w-full h-64 border-2 border-gray-300 border-dashed rounded-lg cursor-pointer bg-gray-50 dark:hover:bg-gray-800 dark:bg-gray-700 hover:bg-gray-100 dark:border-gray-600 dark:hover:border-gray-500 dark:hover:bg-gray-600">
|
<label for="upload_file_form_files"
|
||||||
|
class="flex flex-col items-center justify-center w-full h-64 border-2 border-gray-300 border-dashed rounded-lg cursor-pointer bg-gray-50 dark:hover:bg-gray-800 dark:bg-gray-700 hover:bg-gray-100 dark:border-gray-600 dark:hover:border-gray-500 dark:hover:bg-gray-600">
|
||||||
<div class="flex flex-col items-center justify-center pt-5 pb-6">
|
<div class="flex flex-col items-center justify-center pt-5 pb-6">
|
||||||
{{ ux_icon('file:upload', {height: '64px', width: '64px'}) }}
|
{{ ux_icon('file:upload', {height: '64px', width: '64px'}) }}
|
||||||
<p class="mb-2 text-sm text-gray-500 dark:text-gray-400"><span class="font-semibold">Click to upload</span> or drag and drop</p>
|
<p class="mb-2 text-sm text-gray-500 dark:text-gray-400"><span class="font-semibold">Click to upload</span>
|
||||||
|
or drag and drop</p>
|
||||||
</div>
|
</div>
|
||||||
{{ form_widget(fileForm.file) }}
|
{{ form_widget(fileForm.files) }}
|
||||||
<button type="submit" class="hidden"></button>
|
<button type="submit" class="hidden"></button>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
25
templates/file.html.twig
Normal file
25
templates/file.html.twig
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
{{ file.name }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<div class="max-w-2xl mx-auto my-8 p-6 bg-white shadow-lg rounded-lg border">
|
||||||
|
<a href="{{ routing_service.goBack(app.request) }}" class="inline-flex items-center text-blue-600 hover:text-blue-800 font-medium transition-colors">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2"
|
||||||
|
stroke="currentColor" class="w-5 h-5 mr-2">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" d="M15 19l-7-7 7-7"/>
|
||||||
|
</svg>
|
||||||
|
Back
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<div class="mt-6 text-gray-700 overflow-auto max-h-96">
|
||||||
|
{% if file.mimeType starts with 'image' %}
|
||||||
|
<img src="{{ path('serve_file', {filePath: file.name}) }}" alt="">
|
||||||
|
{% else %}
|
||||||
|
<p class="whitespace-pre-wrap leading-relaxed break-all text-balance">{{ file.content|raw }}</p>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
@ -3,7 +3,7 @@
|
|||||||
{% block title %}Home{% endblock %}
|
{% block title %}Home{% endblock %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<center class="container mt-5">
|
<center class="container mt-5 mx-auto">
|
||||||
{% include '_partials/_table.html.twig' %}
|
{% include '_partials/_table.html.twig' %}
|
||||||
</center>
|
</center>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user