Added manual hashes.

This commit is contained in:
2026-07-01 17:59:50 +02:00
parent e42f0852b1
commit 77f777b647
4 changed files with 94 additions and 2 deletions

View File

@@ -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
{

View File

@@ -14,6 +14,11 @@ export function HashesManager( wire ) {
*/
isCalculating: false,
/**
*
*/
manualHashesModal: false,
/**
* An error on hash calculation.
* @type {any|null}

View File

@@ -59,7 +59,55 @@
<span x-show="error" x-text="error" class="form-error-text" x-cloak></span>
<button type="button" class="btn primary" :disabled="isCalculating" @click="handleSubmitFile()">Add Hashes</button>
<button type="button" class="btn" :disabled="isCalculating" @click="manualHashesModal = true;">Provide hash manually</button>
<button type="button" class="btn primary" :disabled="isCalculating" @click="handleSubmitFile()">Add hashes</button>
</div>
<div
class="modal-overlay"
x-show="manualHashesModal"
x-effect="manualHashesModal && $nextTick(() => window.refreshIcons($el))"
x-cloak
x-transition.opacity.duration.300ms
@keydown.escape.window="manualHashesModal = false"
@focus="window.refreshIcons($el)"
@close-manual-modal.window="manualHashesModal = false"
>
<div @click.outside="manualHashesModal = false" class="modal-window">
<div class="modal-header">
<span class="modal-title">Provide hash manually</span>
<button type="button" @click="manualHashesModal = false" class="modal-close">
<i data-lucide="x" size="18"></i>
</button>
</div>
<div class="modal-content">
<div class="form-group">
<label class="form-label">Filename</label>
<input type="text" wire:model="manualFilename" class="form-input" maxlength="512">
@error('manualFilename') <span class="form-error-text">{{ $message }}</span> @enderror
</div>
<div class="form-group">
<label class="form-label">CRC32</label>
<input type="text" wire:model="manualCRC32" class="form-input" maxlength="512">
@error('manualCRC32') <span class="form-error-text">{{ $message }}</span> @enderror
</div>
<div class="form-group">
<label class="form-label">SHA-1</label>
<input type="text" wire:model="manualSHA1" class="form-input" maxlength="512">
@error('manualSHA1') <span class="form-error-text">{{ $message }}</span> @enderror
</div>
<button type="button" class="btn primary" style="width: 100%; justify-content: center;" wire:click="addManualHash" wire:loading.attr="disabled">
<i data-lucide="plus" size="14"></i> Add
</button>
</div>
</div>
</div>
</div>

View File

@@ -11,7 +11,7 @@
<div class="modal-header">
<span class="modal-title">Write a review</span>
<button @click="reviewModalOpen = false" class="modal-close">
<button type="button" @click="reviewModalOpen = false" class="modal-close">
<i data-lucide="x" size="18"></i>
</button>
</div>