Skip to content

Commit

Permalink
only show fixes when its a duplicate
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvarga committed Oct 21, 2024
1 parent 6712ee1 commit 528fe8a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion resources/js/components/assets/Upload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<div class="ml-4 px-2 flex items-center gap-2" v-if="status === 'error'">
{{ error }}
<dropdown-list v-if="errorStatus === 422">
<dropdown-list v-if="errorStatus === 409">
<template #trigger>
<button class="ml-4 btn btn-xs" v-text="`${__('Fix')}...`" />
</template>
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/assets/Uploader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export default {
msg = __('Upload failed. The file might be larger than is allowed by your server.');
}
} else {
if (status === 422) {
if ([422, 409].includes(status)) {
msg = Object.values(response.errors)[0][0]; // Get first validation message.
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/Http/Controllers/CP/Assets/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException;
use Statamic\Assets\AssetUploader;
use Statamic\Assets\UploadedReplacementFile;
use Statamic\Contracts\Assets\Asset as AssetContract;
Expand Down Expand Up @@ -97,7 +98,11 @@ public function store(Request $request)
$validator = Validator::make(['path' => $path], ['path' => new UploadableAssetPath($container)]);

if (! in_array($request->option, ['timestamp', 'overwrite'])) {
$validator->validate();
try {
$validator->validate();
} catch (ValidationException $e) {
throw $e->status(409);
}
}

$asset = $container->asset($path) ?? $container->makeAsset($path);
Expand Down

0 comments on commit 528fe8a

Please sign in to comment.