This commit is contained in:
2024-05-23 16:54:06 +02:00
parent fc2b66528b
commit 3f26df05b5
26 changed files with 1193 additions and 0 deletions

8
app/HasThumbnail.php Normal file
View File

@@ -0,0 +1,8 @@
<?php
namespace App;
interface HasThumbnail
{
public function getThumbnail() : string;
}

View File

@@ -0,0 +1,68 @@
<?php
namespace App\Http\Controllers;
use App\Http\Requests\StoreImageRequest;
use App\Http\Requests\UpdateImageRequest;
use App\Models\Image;
use Illuminate\Support\Facades\Storage;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
class ImageController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(StoreImageRequest $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(Image $image) : BinaryFileResponse
{
return response()->file(Storage::disk('images')->path($image->album->id . '/original/' . $image->id));
}
/**
* Show the form for editing the specified resource.
*/
public function edit(Image $image)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(UpdateImageRequest $request, Image $image)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Image $image)
{
//
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class StoreImageRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return false;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
//
];
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UpdateImageRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return false;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
//
];
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace App\Livewire\Drawer\Album;
use Livewire\Component;
use Livewire\Features\SupportFileUploads\WithFileUploads;
class AddImage extends Component
{
use WithFileUploads;
public $media = [];
public function render()
{
return view('livewire.drawer.album.add-image');
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace App\Livewire\Drawer\Album;
use App\Models\Category;
use Carbon\Carbon;
use Livewire\Component;
use Livewire\Attributes\Validate;
use Livewire\Attributes\Locked;
use Livewire\Attributes\Computed;
class Create extends Component
{
public Category $category;
#[Validate('required|min:3')]
public string $name;
#[Validate('required|date')]
public string $capture_date_string;
#[Computed]
public function captureDate() : Carbon {
return Carbon::parse($this->capture_date_string);
}
public function mount(Category $category) : void {
$this->category = $category;
}
public function save() : void {
$this->validate();
}
public function render()
{
return view('livewire.drawer.album.create');
}
}

22
app/Models/Image.php Normal file
View File

@@ -0,0 +1,22 @@
<?php
namespace App\Models;
use App\HasThumbnail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Image extends Model implements HasThumbnail
{
use HasFactory;
public function album(): BelongsTo
{
return $this->belongsTo(Album::class);
}
public function getThumbnail() : string {
return route('image.show', $this);
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace App\Policies;
use App\Models\Image;
use App\Models\User;
use Illuminate\Auth\Access\Response;
class ImagePolicy
{
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
//
}
/**
* Determine whether the user can view the model.
*/
public function view(User $user, Image $image): bool
{
//
}
/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
//
}
/**
* Determine whether the user can update the model.
*/
public function update(User $user, Image $image): bool
{
//
}
/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, Image $image): bool
{
//
}
/**
* Determine whether the user can restore the model.
*/
public function restore(User $user, Image $image): bool
{
//
}
/**
* Determine whether the user can permanently delete the model.
*/
public function forceDelete(User $user, Image $image): bool
{
//
}
}

View File

@@ -0,0 +1,64 @@
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Gate;
use Laravel\Telescope\IncomingEntry;
use Laravel\Telescope\Telescope;
use Laravel\Telescope\TelescopeApplicationServiceProvider;
class TelescopeServiceProvider extends TelescopeApplicationServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
// Telescope::night();
$this->hideSensitiveRequestDetails();
$isLocal = $this->app->environment('local');
Telescope::filter(function (IncomingEntry $entry) use ($isLocal) {
return $isLocal ||
$entry->isReportableException() ||
$entry->isFailedRequest() ||
$entry->isFailedJob() ||
$entry->isScheduledTask() ||
$entry->hasMonitoredTag();
});
}
/**
* Prevent sensitive request details from being logged by Telescope.
*/
protected function hideSensitiveRequestDetails(): void
{
if ($this->app->environment('local')) {
return;
}
Telescope::hideRequestParameters(['_token']);
Telescope::hideRequestHeaders([
'cookie',
'x-csrf-token',
'x-xsrf-token',
]);
}
/**
* Register the Telescope gate.
*
* This gate determines who can access Telescope in non-local environments.
*/
protected function gate(): void
{
Gate::define('viewTelescope', function ($user) {
return in_array($user->email, [
//
]);
});
}
}

View File

@@ -0,0 +1,74 @@
<?php
namespace App\View\Components\Form;
use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
class Upload extends Component
{
/**
* Create a new component instance.
*/
public function __construct(
public string $name = 'file',
public bool|int $multiple = false,
public bool|int $validate = true,
public bool|int $preview = true,
public bool|int $required = false,
public bool|int $disabled = false,
public array|string $accept = ['image/png', 'image/jpeg', 'image/webp', 'image/avif'],
public string $size = '8MB',
public int $number = 10,
public string $label = '',
public string $sizeHuman = '',
public array|string $acceptHuman = [],
) {
}
/**
* Get the view / contents that represent the component.
*/
public function render(): View|Closure|string
{
// Set boolean values
if (! $this->multiple) {
$this->multiple = 0;
}
if (! $this->validate) {
$this->validate = 0;
}
if (! $this->preview) {
$this->preview = 0;
}
if (! $this->required) {
$this->required = 0;
}
if (! $this->disabled) {
$this->disabled = 0;
}
// Prepare accept files to JSON
if (is_string($this->accept)) {
$this->accept = explode(',', $this->accept);
}
$this->accept = array_map('trim', $this->accept);
$this->accept = array_filter($this->accept);
$this->accept = array_unique($this->accept);
$this->accept = array_values($this->accept);
$this->accept = array_map('strtolower', $this->accept);
$fileTypes = $this->accept;
$this->accept = json_encode($this->accept);
// Set size human for UI
$this->sizeHuman = $this->size;
// Prepare files types for UI
foreach ($fileTypes as $type) {
$new = explode('/', $type);
if (array_key_exists(1, $new)) {
$this->acceptHuman[] = ".{$new[1]}";
}
}
$this->acceptHuman = implode(', ', $this->acceptHuman);
return view('components.form.upload');
}
}