diff --git a/app/Console/Commands/CalculateAllHashes.php b/app/Console/Commands/CalculateAllHashes.php new file mode 100644 index 0000000..44468c2 --- /dev/null +++ b/app/Console/Commands/CalculateAllHashes.php @@ -0,0 +1,38 @@ +cursor()->each(function ($entryHash) { + if( ( $hash = HashesHelpers::findHashes( $entryHash->hash_sha1 ) ) !== null ){ + $entryHash->filename = $hash->filename; + $entryHash->hash_crc32 = $hash->crc32; + $entryHash->hash_sha1 = $hash->sha1; + $entryHash->verified = HashesHelpers::getReferenceName( $hash->dat_reference_id ); + $entryHash->save(); + } else { + if( !$entryHash->hash_crc32 || !$entryHash->hash_sha1 ) + $entryHash->delete(); + else { + if (!$entryHash->filename) + $entryHash->filename = "Unknown"; + $entryHash->verified = 'No'; + $entryHash->save(); + } + } + }); + + $this->info('Hashes calculated'); + } +} diff --git a/app/Http/Requests/StoreEntryRequest.php b/app/Http/Requests/StoreEntryRequest.php index 91a5de9..331029a 100644 --- a/app/Http/Requests/StoreEntryRequest.php +++ b/app/Http/Requests/StoreEntryRequest.php @@ -106,7 +106,9 @@ class StoreEntryRequest extends FormRequest $rules['new-game-genre'] = 'required_with:new-game-title|integer|nullable|exists:genres,id'; } - if( section_must_be( ['translations', 'romhacks'], $section ) ){ + $bypassHashes = $isEdit && $this->user()->can('moderate', $this->route('entry') ) && ($this->input('bypass_hashes') !== null); + + if( section_must_be( ['translations', 'romhacks'], $section ) && !$bypassHashes ){ $rules['hashes'] = 'array|required|min:1'; $rules['hashes.*.filename'] = 'required|string|max:512'; $rules['hashes.*.hash_crc32'] = 'required|string|max:512'; diff --git a/app/Livewire/HashesUpload.php b/app/Livewire/HashesUpload.php index 2aa5a91..335176a 100644 --- a/app/Livewire/HashesUpload.php +++ b/app/Livewire/HashesUpload.php @@ -34,7 +34,8 @@ class HashesUpload extends Component public function mount( array $oldHashes = [] ): void { foreach ($oldHashes as $hash) { - $this->addHash( $hash['filename'], $hash['hash_crc32'], $hash['hash_sha1'], $hash['verified'] ); + if( isset( $hash['filename'], $hash['hash_crc32'], $hash['hash_sha1'], $hash['verified'] ) ) + $this->addHash( $hash['filename'], $hash['hash_crc32'], $hash['hash_sha1'], $hash['verified'] ); } } diff --git a/resources/views/submissions/form.blade.php b/resources/views/submissions/form.blade.php index 3526f88..511a97a 100644 --- a/resources/views/submissions/form.blade.php +++ b/resources/views/submissions/form.blade.php @@ -234,6 +234,9 @@ @if( section_must_be(['romhacks', 'homebrew'], $section ) ) @endif + @if( section_must_be( ['romhacks', 'translations'], $section ) ) + + @endif @endcan