mirror of
https://github.com/pelican-dev/panel.git
synced 2025-09-08 09:58:37 +02:00
Add file name Validation
This commit is contained in:
parent
3543b4773a
commit
d9c2e7646a
@ -136,6 +136,7 @@ class ListFiles extends ListRecords
|
|||||||
->form([
|
->form([
|
||||||
TextInput::make('name')
|
TextInput::make('name')
|
||||||
->label(trans('server/file.actions.rename.name'))
|
->label(trans('server/file.actions.rename.name'))
|
||||||
|
->rules(File::getRulesForField('name'))
|
||||||
->default(fn (File $file) => $file->name)
|
->default(fn (File $file) => $file->name)
|
||||||
->required(),
|
->required(),
|
||||||
])
|
])
|
||||||
@ -189,6 +190,7 @@ class ListFiles extends ListRecords
|
|||||||
->form([
|
->form([
|
||||||
TextInput::make('location')
|
TextInput::make('location')
|
||||||
->label(trans('server/file.actions.move.new_location'))
|
->label(trans('server/file.actions.move.new_location'))
|
||||||
|
->rules(File::getRulesForField('name'))
|
||||||
->hint(trans('server/file.actions.move.new_location_hint'))
|
->hint(trans('server/file.actions.move.new_location_hint'))
|
||||||
->required()
|
->required()
|
||||||
->live(),
|
->live(),
|
||||||
@ -349,6 +351,7 @@ class ListFiles extends ListRecords
|
|||||||
->form([
|
->form([
|
||||||
TextInput::make('location')
|
TextInput::make('location')
|
||||||
->label(trans('server/file.actions.move.directory'))
|
->label(trans('server/file.actions.move.directory'))
|
||||||
|
->rules(File::getRulesForField('name'))
|
||||||
->hint(trans('server/file.actions.move.directory_hint'))
|
->hint(trans('server/file.actions.move.directory_hint'))
|
||||||
->required()
|
->required()
|
||||||
->live(),
|
->live(),
|
||||||
@ -451,6 +454,7 @@ class ListFiles extends ListRecords
|
|||||||
->form([
|
->form([
|
||||||
TextInput::make('name')
|
TextInput::make('name')
|
||||||
->label(trans('server/file.actions.new_file.file_name'))
|
->label(trans('server/file.actions.new_file.file_name'))
|
||||||
|
->rules(File::getRulesForField('name'))
|
||||||
->required(),
|
->required(),
|
||||||
Select::make('lang')
|
Select::make('lang')
|
||||||
->label(trans('server/file.actions.new_file.syntax'))
|
->label(trans('server/file.actions.new_file.syntax'))
|
||||||
@ -492,6 +496,7 @@ class ListFiles extends ListRecords
|
|||||||
->form([
|
->form([
|
||||||
TextInput::make('name')
|
TextInput::make('name')
|
||||||
->label(trans('server/file.actions.new_folder.folder_name'))
|
->label(trans('server/file.actions.new_folder.folder_name'))
|
||||||
|
->rules(File::getRulesForField('name'))
|
||||||
->required(),
|
->required(),
|
||||||
]),
|
]),
|
||||||
HeaderAction::make('upload')
|
HeaderAction::make('upload')
|
||||||
@ -556,9 +561,9 @@ class ListFiles extends ListRecords
|
|||||||
->form([
|
->form([
|
||||||
TextInput::make('searchTerm')
|
TextInput::make('searchTerm')
|
||||||
->label(trans('server/file.actions.global_search.search_term'))
|
->label(trans('server/file.actions.global_search.search_term'))
|
||||||
->placeholder(trans('server/file.actions.global_search.search_term_placeholder'))
|
->rules(array_merge(File::getRulesForField('name'), ['regex:/^[^*]*\*?[^*]*$/']))
|
||||||
->required()
|
->required()
|
||||||
->regex('/^[^*]*\*?[^*]*$/')
|
->placeholder(trans('server/file.actions.global_search.search_term_placeholder'))
|
||||||
->minValue(3),
|
->minValue(3),
|
||||||
])
|
])
|
||||||
->action(fn ($data) => redirect(SearchFiles::getUrl([
|
->action(fn ($data) => redirect(SearchFiles::getUrl([
|
||||||
|
@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Contracts\Validatable;
|
||||||
use App\Livewire\AlertBanner;
|
use App\Livewire\AlertBanner;
|
||||||
use App\Repositories\Daemon\DaemonFileRepository;
|
use App\Repositories\Daemon\DaemonFileRepository;
|
||||||
|
use App\Traits\HasValidation;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
@ -26,10 +28,16 @@ use Sushi\Sushi;
|
|||||||
* @property bool $is_symlink
|
* @property bool $is_symlink
|
||||||
* @property string $mime_type
|
* @property string $mime_type
|
||||||
*/
|
*/
|
||||||
class File extends Model
|
class File extends Model implements Validatable
|
||||||
{
|
{
|
||||||
|
use HasValidation;
|
||||||
use Sushi;
|
use Sushi;
|
||||||
|
|
||||||
|
/** @var array<array-key, string[]> */
|
||||||
|
public static array $validationRules = [
|
||||||
|
'name' => ['required', 'string', 'not_regex:/[{}#]/'],
|
||||||
|
];
|
||||||
|
|
||||||
protected int $sushiInsertChunkSize = 100;
|
protected int $sushiInsertChunkSize = 100;
|
||||||
|
|
||||||
public const ARCHIVE_MIMES = [
|
public const ARCHIVE_MIMES = [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user