Skip to content
Permalink
Browse files
Prohibit extension change when renaming a file
  • Loading branch information
sebastienheyd committed Nov 3, 2021
1 parent 53f0f23 commit 4e4c5e56ee48e0311f972bc971582a67d8ce1725
@@ -9,9 +9,11 @@
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\UploadedFile;
use Illuminate\Validation\Rule;
use Illuminate\View\View;
use Image;
use Sebastienheyd\BoilerplateMediaManager\Models\Breadcrumb;
use Sebastienheyd\BoilerplateMediaManager\Models\File;
use Sebastienheyd\BoilerplateMediaManager\Models\Path;
use UnexpectedValueException;
use Validator;
@@ -209,12 +211,27 @@ public function paste(Request $request)
*
* @param Request $request
*
* @return JsonResponse|ResponseFactory
* @return JsonResponse
*/
public function rename(Request $request)
{
if(! $request->isXmlHttpRequest()) {
abort(403);
}

$validator = Validator::make($request->post(), [
'path' => 'required',
'type' => ['required', Rule::in(['folder', 'file'])],
'fileName' => 'required',
'newName' => 'required',
]);

if ($validator->fails()) {
return response()->json(['status' => 'error', 'message' => $validator->errors()->first()]);
}

try {
$path = new Path($request->input('path'));
$path = new Path($request->post('path'));
$path->rename($request->input('fileName'), $request->input('newName'));

return response()->json(['status' => 'success']);
@@ -34,6 +34,9 @@ public function __construct($file)
*/
public function rename($newName)
{
$newName = preg_replace('#\.'.$this->pathinfo['extension'].'$#i', '', $newName);
$newName = $newName.'.'.$this->pathinfo['extension'];

foreach ($this->getThumbs() as $thumb) {
$this->storage->move($thumb['fullpath'], $thumb['dirname'].'/'.$newName);
}
@@ -186,17 +189,19 @@ public function toArray()
$ts = filemtime($this->getFullPath());

return [
'download' => '',
'icon' => $this->getIcon(),
'thumb' => $this->getThumbUrl().'?'.$ts,
'type' => $this->detectFileType(),
'name' => basename($this->file),
'isDir' => false,
'size' => $this->getFilesize(),
'link' => route('mediamanager.index', ['path' => $this->file], false),
'url' => $this->storage->url($this->file).'?'.$ts,
'time' => $this->getFileChangeTime(),
'ts' => $ts,
'download' => '',
'icon' => $this->getIcon(),
'thumb' => $this->getThumbUrl().'?'.$ts,
'type' => $this->detectFileType(),
'name' => basename($this->file),
'filename' => $this->pathinfo['filename'],
'extension' => $this->pathinfo['extension'],
'isDir' => false,
'size' => $this->getFilesize(),
'link' => route('mediamanager.index', ['path' => $this->file], false),
'url' => $this->storage->url($this->file).'?'.$ts,
'time' => $this->getFileChangeTime(),
'ts' => $ts,
];
}

Some generated files are not rendered by default. Learn more.

0 comments on commit 4e4c5e5

Please sign in to comment.