diff --git a/app/Actions/Filemanager/GetFileContentsAction.php b/app/Actions/Filemanager/GetFileContentsAction.php index 97098a6..42c0e4c 100644 --- a/app/Actions/Filemanager/GetFileContentsAction.php +++ b/app/Actions/Filemanager/GetFileContentsAction.php @@ -2,13 +2,13 @@ namespace App\Actions\Filemanager; +use finfo; use Illuminate\Http\Request; use League\Flysystem\Filesystem; -use League\MimeTypeDetection\FinfoMimeTypeDetector; class GetFileContentsAction { - public function __construct(public Filesystem $filesystem) {} + public function __construct(public Filesystem $filesystem, public string $path) {} public function execute(Request $r) { @@ -42,8 +42,9 @@ class GetFileContentsAction try { - $mimeTypeDetector = new FinfoMimeTypeDetector(); - $mimeType = $mimeTypeDetector->detectMimeType($r->file, 'string contents'); + $finfo = new finfo(); + // @todo -> get base_path() passed by controller + $mimeType = $finfo->file($this->path . '/' . $r->path . '/' . $r->file, FILEINFO_MIME_TYPE); if (!in_array($mimeType, $editableMimeTypes, true)) { throw new \Exception('File of type "' . $mimeType . '" is not editable'); diff --git a/app/Http/Controllers/FilemanagerController.php b/app/Http/Controllers/FilemanagerController.php index 5df9ef5..b3bec71 100644 --- a/app/Http/Controllers/FilemanagerController.php +++ b/app/Http/Controllers/FilemanagerController.php @@ -43,7 +43,7 @@ class FilemanagerController extends Controller public function getFileContents(Request $r) { - return (new GetFileContentsAction($this->filesystem))->execute($r); + return (new GetFileContentsAction($this->filesystem, $this->path))->execute($r); } public function createFile(Request $r) diff --git a/resources/js/Pages/Filemanager/Components/EditFile.jsx b/resources/js/Pages/Filemanager/Components/EditFile.jsx index 9de31f0..e890dd5 100644 --- a/resources/js/Pages/Filemanager/Components/EditFile.jsx +++ b/resources/js/Pages/Filemanager/Components/EditFile.jsx @@ -12,6 +12,7 @@ const EditFile = ({ editFile, setEditFile }) => { const [fileContents, setFileContents] = useState(''); const [showSpinner, setShowSpinner] = useState(true); + const [isError, setIsError] = useState(false); useEffect(() => { readFile(); @@ -32,6 +33,7 @@ const EditFile = ({ editFile, setEditFile }) => { const errorData = await response.json(); const errorMessage = errorData.error || response.statusText; toast(errorMessage, { type: 'error' }); + setIsError(true); return; } @@ -53,6 +55,7 @@ const EditFile = ({ editFile, setEditFile }) => { } catch (error) { toast('Error reading file', { type: 'error' }) toast(error.message, { type: 'error' }) + setIsError(true); console.error(error) } finally { setShowSpinner(false); @@ -99,23 +102,24 @@ const EditFile = ({ editFile, setEditFile }) => { className="sr-only" /> -