From 77f777b64745e15a5c07bc23ded13fea7e8dc357 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Wed, 1 Jul 2026 17:59:50 +0200 Subject: [PATCH] Added manual hashes. --- app/Livewire/HashesUpload.php | 39 +++++++++++++++ .../js/SubmissionsClass/HashesManager.js | 5 ++ .../views/livewire/hashes-upload.blade.php | 50 ++++++++++++++++++- resources/views/reviews/submit.blade.php | 2 +- 4 files changed, 94 insertions(+), 2 deletions(-) diff --git a/app/Livewire/HashesUpload.php b/app/Livewire/HashesUpload.php index 335176a..5d7d102 100644 --- a/app/Livewire/HashesUpload.php +++ b/app/Livewire/HashesUpload.php @@ -25,6 +25,10 @@ class HashesUpload extends Component */ public array $hashes = []; + public ?string $manualFilename = ""; + public ?string $manualCRC32 = ""; + public ?string $manualSHA1 = ""; + /** * Prepare old hashes. * @@ -87,6 +91,41 @@ class HashesUpload extends Component array_splice($this->hashes, $index, 1); } + private function checkCrc32($attribute, $value, $fail) + { + if (!preg_match('/^[a-f0-9]{8}$/i', $value)) { + $fail("CRC32 is invalid"); + } + } + + private function checkSha1($attribute, $value, $fail) + { + if (!preg_match('/^[a-f0-9]{40}$/i', $value)) { + $fail("SHA1 is invalid"); + } + } + + public function addManualHash() + { + $this->validate([ + 'manualFilename' => "required|string|max:512", + 'manualCRC32' => ['required', 'string', 'max:512', $this->checkCrc32(...) ], + 'manualSHA1' => ['required', 'string', 'max:512', $this->checkSha1(...) ], + ], [ + 'manualFilename.required' => 'Please enter a filename.', + 'manualCRC32.required' => 'Please enter a crc32.', + 'manualSHA1.required' => 'Please enter a SHA1.', + 'manualFilename.max' => 'Filename has to be less than 512 characters.', + 'manualCRC32.max' => 'CRC32 has to be less than 512 characters.', + 'manualSHA1.max' => 'SHA1 has to be less than 512 characters.', + ]); + + $this->addHash( $this->manualFilename, $this->manualCRC32, $this->manualSHA1 ); + + $this->reset(['manualFilename','manualCRC32','manualSHA1']); + $this->dispatch('close-manual-modal'); + } + public function render(): View { diff --git a/resources/js/SubmissionsClass/HashesManager.js b/resources/js/SubmissionsClass/HashesManager.js index b785286..79aab38 100644 --- a/resources/js/SubmissionsClass/HashesManager.js +++ b/resources/js/SubmissionsClass/HashesManager.js @@ -14,6 +14,11 @@ export function HashesManager( wire ) { */ isCalculating: false, + /** + * + */ + manualHashesModal: false, + /** * An error on hash calculation. * @type {any|null} diff --git a/resources/views/livewire/hashes-upload.blade.php b/resources/views/livewire/hashes-upload.blade.php index 9995910..44f5709 100644 --- a/resources/views/livewire/hashes-upload.blade.php +++ b/resources/views/livewire/hashes-upload.blade.php @@ -59,7 +59,55 @@ - + + + diff --git a/resources/views/reviews/submit.blade.php b/resources/views/reviews/submit.blade.php index 844ee64..8f4e505 100644 --- a/resources/views/reviews/submit.blade.php +++ b/resources/views/reviews/submit.blade.php @@ -11,7 +11,7 @@ -- 2.39.5