🎨 feat(notification): add private disk for PDF uploads and update download route with signed URL.

This commit is contained in:
fsociety
2024-10-25 20:06:19 +02:00
parent 603eed4c46
commit 3055bfa196
4 changed files with 34 additions and 14 deletions

View File

@@ -26,7 +26,8 @@ class Notification extends Model implements HasMedia
$this $this
->addMediaCollection('pdf') ->addMediaCollection('pdf')
->acceptsMimeTypes(['application/pdf']) ->acceptsMimeTypes(['application/pdf'])
->singleFile(); ->singleFile()
->useDisk('private');
} }
public function einundzwanzigPleb(): BelongsTo public function einundzwanzigPleb(): BelongsTo

View File

@@ -36,6 +36,12 @@ return [
'throw' => false, 'throw' => false,
], ],
'private' => [
'driver' => 'local',
'root' => storage_path('app/private'),
'throw' => false,
],
'public' => [ 'public' => [
'driver' => 'local', 'driver' => 'local',
'root' => storage_path('app/public'), 'root' => storage_path('app/public'),

View File

@@ -68,6 +68,7 @@ $save = function () {
$notification $notification
->addMedia($this->file->getRealPath()) ->addMedia($this->file->getRealPath())
->usingName($this->file->getClientOriginalName())
->toMediaCollection('pdf'); ->toMediaCollection('pdf');
$this->form->reset(); $this->form->reset();
@@ -142,8 +143,10 @@ $deleteNow = function($id) {
</div> </div>
<ul class="flex flex-nowrap md:block mr-3 md:mr-0"> <ul class="flex flex-nowrap md:block mr-3 md:mr-0">
@foreach(\App\Enums\NewsCategory::selectOptions() as $category) @foreach(\App\Enums\NewsCategory::selectOptions() as $category)
<li class="mr-0.5 md:mr-0 md:mb-0.5" wire:key="category_{{ $category['value'] }}"> <li class="mr-0.5 md:mr-0 md:mb-0.5"
<div class="flex items-center px-2.5 py-2 rounded-lg whitespace-nowrap bg-white dark:bg-gray-800"> wire:key="category_{{ $category['value'] }}">
<div
class="flex items-center px-2.5 py-2 rounded-lg whitespace-nowrap bg-white dark:bg-gray-800">
<i class="fa-sharp-duotone fa-solid fa-{{ $category['icon'] }} shrink-0 fill-current text-amber-500 mr-2"></i> <i class="fa-sharp-duotone fa-solid fa-{{ $category['icon'] }} shrink-0 fill-current text-amber-500 mr-2"></i>
<span <span
class="text-sm font-medium text-amber-500">{{ $category['label'] }}</span> class="text-sm font-medium text-amber-500">{{ $category['label'] }}</span>
@@ -163,7 +166,8 @@ $deleteNow = function($id) {
<div class="space-y-2"> <div class="space-y-2">
@forelse($news as $post) @forelse($news as $post)
<article wire:key="post_{{ $post->id }}" class="bg-white dark:bg-gray-800 shadow-sm rounded-xl p-5"> <article wire:key="post_{{ $post->id }}"
class="bg-white dark:bg-gray-800 shadow-sm rounded-xl p-5">
<div class="flex flex-start space-x-4"> <div class="flex flex-start space-x-4">
<!-- Avatar --> <!-- Avatar -->
<div class="shrink-0 mt-1.5"> <div class="shrink-0 mt-1.5">
@@ -185,7 +189,8 @@ $deleteNow = function($id) {
<footer class="flex flex-wrap text-sm"> <footer class="flex flex-wrap text-sm">
<div <div
class="flex items-center after:block after:content-['·'] last:after:content-[''] after:text-sm after:text-gray-400 dark:after:text-gray-600 after:px-2"> class="flex items-center after:block after:content-['·'] last:after:content-[''] after:text-sm after:text-gray-400 dark:after:text-gray-600 after:px-2">
<div class="font-medium text-amber-500 hover:text-amber-600 dark:hover:text-amber-400"> <div
class="font-medium text-amber-500 hover:text-amber-600 dark:hover:text-amber-400">
<div class="flex items-center"> <div class="flex items-center">
<svg class="mr-2 fill-current" width="16" <svg class="mr-2 fill-current" width="16"
height="16" height="16"
@@ -209,7 +214,7 @@ $deleteNow = function($id) {
<x-button <x-button
xs xs
target="_blank" target="_blank"
:href="$post->getFirstMediaUrl('pdf')" :href="url()->temporarySignedRoute('dl', now()->addMinutes(30), ['media' => $post->getFirstMedia('pdf')])"
label="Öffnen" label="Öffnen"
primary icon="cloud-arrow-down"/> primary icon="cloud-arrow-down"/>
@if($canEdit) @if($canEdit)

View File

@@ -1,5 +1,13 @@
<?php <?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
Route::redirect('/', '/association/profile'); Route::redirect('/', '/association/profile');
Route::get('dl/{media}', function (Media $media, Request $request) {
return response()->download($media->getPath(), $media->name);
})
->name('dl')
->middleware('signed');