From 5d3919466f8d3ad0b1ea3632b85b5c4cb7ff3d2c Mon Sep 17 00:00:00 2001 From: HolgerHatGarKeineNode Date: Thu, 2 Feb 2023 15:54:47 +0100 Subject: [PATCH] md5 media file names --- .../Commands/Database/RenameFileToMd5.php | 45 +++++++++++++++++++ .../Livewire/BookCase/CommentBookCase.php | 1 + app/Http/Livewire/Tables/BookCaseTable.php | 2 + app/Nova/BitcoinEvent.php | 15 ++++--- app/Nova/Course.php | 8 +++- app/Nova/Lecturer.php | 8 +++- app/Nova/LibraryItem.php | 10 +++-- app/Nova/Meetup.php | 3 +- 8 files changed, 79 insertions(+), 13 deletions(-) create mode 100644 app/Console/Commands/Database/RenameFileToMd5.php diff --git a/app/Console/Commands/Database/RenameFileToMd5.php b/app/Console/Commands/Database/RenameFileToMd5.php new file mode 100644 index 00000000..601d8ff7 --- /dev/null +++ b/app/Console/Commands/Database/RenameFileToMd5.php @@ -0,0 +1,45 @@ +where('file_name', 'ilike', '%ö%') + ->orWhere('file_name', 'ilike', '%ä%') + ->orWhere('file_name', 'ilike', '%ü%') + ->orWhere('file_name', 'ilike', '%ß%') + ->get(); + foreach ($media as $item) { + $md5FileName = md5($item->file_name).'.'.$item->extension; + $item->file_name = $md5FileName; + Storage::disk('public') + ->move($item->getPath(), dirname($item->getPath()).'/'.$md5FileName); + $item->save(); + } + + return Command::SUCCESS; + } +} diff --git a/app/Http/Livewire/BookCase/CommentBookCase.php b/app/Http/Livewire/BookCase/CommentBookCase.php index 7e3ce867..fa8a4a53 100644 --- a/app/Http/Livewire/BookCase/CommentBookCase.php +++ b/app/Http/Livewire/BookCase/CommentBookCase.php @@ -41,6 +41,7 @@ class CommentBookCase extends Component $this->bookCase ->addMedia($this->photo) + ->usingFileName(md5($this->photo->getClientOriginalName()) . '.' . $this->photo->getClientOriginalExtension()) ->toMediaCollection('images'); return to_route('bookCases.comment.bookcase', ['country' => $this->country, 'bookCase' => $this->bookCase->id]); diff --git a/app/Http/Livewire/Tables/BookCaseTable.php b/app/Http/Livewire/Tables/BookCaseTable.php index 36045df9..ecc48204 100644 --- a/app/Http/Livewire/Tables/BookCaseTable.php +++ b/app/Http/Livewire/Tables/BookCaseTable.php @@ -151,10 +151,12 @@ class BookCaseTable extends DataTableComponent $orangePill ->addMedia($this->photo) ->preservingOriginal() + ->usingFileName(md5($this->photo->getClientOriginalName()).'.'.$this->photo->getClientOriginalExtension()) ->toMediaCollection('images'); $orangePill->load(['media']); $this->currentModal ->addMedia($this->photo) + ->usingFileName(md5($this->photo->getClientOriginalName()).'.'.$this->photo->getClientOriginalExtension()) ->toMediaCollection('images'); if ($this->orangepill['comment']) { $this->currentModal->comment($this->orangepill['comment'], null); diff --git a/app/Nova/BitcoinEvent.php b/app/Nova/BitcoinEvent.php index e97ee583..bfe985f8 100644 --- a/app/Nova/BitcoinEvent.php +++ b/app/Nova/BitcoinEvent.php @@ -66,7 +66,9 @@ class BitcoinEvent extends Resource ->sortable(), Images::make(__('Logo'), 'logo') - ->conversionOnIndexView('thumb'), + ->showStatistics() + ->conversionOnIndexView('thumb') + ->setFileName(fn($originalFilename, $extension, $model) => md5($originalFilename).'.'.$extension), Boolean::make(__('Show worldwide'), 'show_worldwide') ->help(__('If checked, the event will be shown everywhere.')), @@ -85,21 +87,24 @@ class BitcoinEvent extends Resource ->rules('required', 'string'), Markdown::make(__('Description'), 'description') - ->rules('required', 'string') - ->hideFromIndex(), + ->rules('required', 'string') + ->hideFromIndex(), Text::make('Link') ->rules('required', 'string'), BelongsTo::make(__('Venue'), 'venue', Venue::class) - ->searchable()->showCreateRelationButton()->withSubtitles(), + ->searchable() + ->showCreateRelationButton() + ->withSubtitles(), BelongsTo::make(__('Created By'), 'createdBy', User::class) ->canSee(function ($request) { return $request->user() ->hasRole('super-admin'); }) - ->searchable()->withSubtitles(), + ->searchable() + ->withSubtitles(), ]; } diff --git a/app/Nova/Course.php b/app/Nova/Course.php index 80b7caf4..0261989c 100644 --- a/app/Nova/Course.php +++ b/app/Nova/Course.php @@ -85,12 +85,16 @@ class Course extends Resource ->sortable(), Images::make(__('Main picture'), 'logo') - ->conversionOnIndexView('thumb'), + ->showStatistics() + ->conversionOnIndexView('thumb') + ->setFileName(fn($originalFilename, $extension, $model) => md5($originalFilename).'.'.$extension), // todo: english Images::make(__('Images'), 'images') + ->showStatistics() ->conversionOnIndexView('thumb') - ->help(__('Upload images here to insert them later in the Markdown Description. But you have to save before.')), + ->help(__('Upload images here to insert them later in the Markdown Description. But you have to save before.')) + ->setFileName(fn($originalFilename, $extension, $model) => md5($originalFilename).'.'.$extension), Tags::make(__('Tags')) ->type('course') diff --git a/app/Nova/Lecturer.php b/app/Nova/Lecturer.php index 92571fbf..b0b58cd0 100644 --- a/app/Nova/Lecturer.php +++ b/app/Nova/Lecturer.php @@ -79,11 +79,15 @@ class Lecturer extends Resource ->sortable(), Images::make('Avatar', 'avatar') - ->conversionOnIndexView('thumb'), + ->showStatistics() + ->conversionOnIndexView('thumb') + ->setFileName(fn($originalFilename, $extension, $model) => md5($originalFilename).'.'.$extension), Images::make(__('Images'), 'images') + ->showStatistics() ->conversionOnIndexView('thumb') - ->help('Upload images here to insert them later in the Markdown Description. But you have to save before.'), + ->help('Upload images here to insert them later in the Markdown Description. But you have to save before.') + ->setFileName(fn($originalFilename, $extension, $model) => md5($originalFilename).'.'.$extension), Text::make('Name') ->rules('required', 'string'), diff --git a/app/Nova/LibraryItem.php b/app/Nova/LibraryItem.php index ae38ec71..04ff4db0 100644 --- a/app/Nova/LibraryItem.php +++ b/app/Nova/LibraryItem.php @@ -105,16 +105,20 @@ class LibraryItem extends Resource Images::make(__('Main picture'), 'main') ->conversionOnIndexView('thumb') - ->showStatistics(), + ->showStatistics() + ->setFileName(fn($originalFilename, $extension, $model) => md5($originalFilename).'.'.$extension), Images::make(__('Images'), 'images') ->conversionOnIndexView('thumb') ->help('Upload images here to insert them later in the Markdown Description. But you have to save before.') ->hideFromIndex() - ->showStatistics(), + ->showStatistics() + ->setFileName(fn($originalFilename, $extension, $model) => md5($originalFilename).'.'.$extension), Files::make(__('Downloadable File'), 'single_file') - ->help(__('Please contact the admins for new file types, otherwise pack the files in a ZIP! (Currently: PDF, ZIP)')), + ->showStatistics() + ->help(__('Please contact the admins for new file types, otherwise pack the files in a ZIP! (Currently: PDF, ZIP)')) + ->setFileName(fn($originalFilename, $extension, $model) => md5($originalFilename).'.'.$extension), Select::make(__('Language Code'), 'language_code') ->options( diff --git a/app/Nova/Meetup.php b/app/Nova/Meetup.php index 9185d951..c0cbddf7 100644 --- a/app/Nova/Meetup.php +++ b/app/Nova/Meetup.php @@ -79,7 +79,8 @@ class Meetup extends Resource Images::make(__('Logo'), 'logo') ->conversionOnIndexView('thumb') - ->showStatistics(), + ->showStatistics() + ->setFileName(fn($originalFilename, $extension, $model) => md5($originalFilename).'.'.$extension), Text::make('Name') ->rules('required', 'string')