storage url o'zgartirildi
This commit is contained in:
49
app/Console/Commands/StorageHealthCheck.php
Normal file
49
app/Console/Commands/StorageHealthCheck.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Throwable;
|
||||
|
||||
class StorageHealthCheck extends Command
|
||||
{
|
||||
protected $signature = 'storage:health-check {disk? : Disk name, defaults to filesystems.default}';
|
||||
|
||||
protected $description = 'Check current storage disk, write/read/delete a test file, and print its public URL.';
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$disk = $this->argument('disk') ?: config('filesystems.default');
|
||||
$path = 'healthcheck/' . now()->format('YmdHis') . '-' . uniqid() . '.txt';
|
||||
|
||||
$this->line('default=' . config('filesystems.default'));
|
||||
$this->line('disk=' . $disk);
|
||||
$this->line('endpoint=' . (config("filesystems.disks.{$disk}.endpoint") ?: '-'));
|
||||
$this->line('url=' . (config("filesystems.disks.{$disk}.url") ?: '-'));
|
||||
$this->line('bucket=' . (config("filesystems.disks.{$disk}.bucket") ?: '-'));
|
||||
$this->line('path_style=' . json_encode(config("filesystems.disks.{$disk}.use_path_style_endpoint")));
|
||||
|
||||
try {
|
||||
$stored = Storage::disk($disk)->put($path, 'ok');
|
||||
|
||||
if (!$stored) {
|
||||
$this->error("put=false path={$path}");
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$exists = Storage::disk($disk)->exists($path);
|
||||
$this->line('put=ok');
|
||||
$this->line('exists=' . ($exists ? 'yes' : 'no'));
|
||||
$this->line('public_url=' . Storage::disk($disk)->url($path));
|
||||
|
||||
Storage::disk($disk)->delete($path);
|
||||
$this->line('delete=ok');
|
||||
} catch (Throwable $e) {
|
||||
$this->error(get_class($e) . ': ' . $e->getMessage());
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -10,12 +10,17 @@ class Uploads
|
||||
{
|
||||
public static function store(UploadedFile $file, string $path, ?string $disk = null): string
|
||||
{
|
||||
$diskName = $disk ?: config('filesystems.default');
|
||||
$storedPath = $disk ? $file->store($path, $disk) : $file->store($path);
|
||||
|
||||
if (!$storedPath) {
|
||||
throw new RuntimeException("File upload failed: {$path}");
|
||||
}
|
||||
|
||||
if (!Storage::disk($diskName)->exists($storedPath)) {
|
||||
throw new RuntimeException("Uploaded file was not found on disk [{$diskName}]: {$storedPath}");
|
||||
}
|
||||
|
||||
return $storedPath;
|
||||
}
|
||||
|
||||
@@ -28,5 +33,10 @@ class Uploads
|
||||
if (!$stored) {
|
||||
throw new RuntimeException("File upload failed: {$path}");
|
||||
}
|
||||
|
||||
$diskName = $disk ?: config('filesystems.default');
|
||||
if (!Storage::disk($diskName)->exists($path)) {
|
||||
throw new RuntimeException("Uploaded file was not found on disk [{$diskName}]: {$path}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ return [
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('FILESYSTEM_DISK', 'local'),
|
||||
'default' => env('FILESYSTEM_DISK', env('FILESYSTEM_DRIVER', 's3')),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
||||
@@ -21,6 +21,23 @@
|
||||
|
||||
<!-- JavaScript for delete confirmation -->
|
||||
<script>
|
||||
window.PreviewImage = window.PreviewImage || function(event) {
|
||||
var input = event && event.target
|
||||
? event.target
|
||||
: document.activeElement || document.getElementById('uploadImage') || document.getElementById('poster');
|
||||
var preview = document.getElementById('uploadPreview');
|
||||
|
||||
if (!input || !input.files || !input.files[0] || !preview) {
|
||||
return;
|
||||
}
|
||||
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(readerEvent) {
|
||||
preview.src = readerEvent.target.result;
|
||||
};
|
||||
reader.readAsDataURL(input.files[0]);
|
||||
};
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const deleteForms = document.querySelectorAll('.delete-alert');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user