mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-nostr.git
synced 2025-12-13 05:26:47 +00:00
🎨 feat(notification): add private disk for PDF uploads and update download route with signed URL.
This commit is contained in:
@@ -26,7 +26,8 @@ class Notification extends Model implements HasMedia
|
||||
$this
|
||||
->addMediaCollection('pdf')
|
||||
->acceptsMimeTypes(['application/pdf'])
|
||||
->singleFile();
|
||||
->singleFile()
|
||||
->useDisk('private');
|
||||
}
|
||||
|
||||
public function einundzwanzigPleb(): BelongsTo
|
||||
|
||||
@@ -36,10 +36,16 @@ return [
|
||||
'throw' => false,
|
||||
],
|
||||
|
||||
'private' => [
|
||||
'driver' => 'local',
|
||||
'root' => storage_path('app/private'),
|
||||
'throw' => false,
|
||||
],
|
||||
|
||||
'public' => [
|
||||
'driver' => 'local',
|
||||
'root' => storage_path('app/public'),
|
||||
'url' => env('APP_URL').'/storage',
|
||||
'url' => env('APP_URL') . '/storage',
|
||||
'visibility' => 'public',
|
||||
'throw' => false,
|
||||
],
|
||||
|
||||
@@ -60,14 +60,15 @@ $save = function () {
|
||||
$notification = \App\Models\Notification::query()
|
||||
->orderBy('created_at', 'desc')
|
||||
->create([
|
||||
'einundzwanzig_pleb_id' => $this->currentPleb->id,
|
||||
'category' => $this->form->category,
|
||||
'name' => $this->form->name,
|
||||
'description' => $this->form->description,
|
||||
]);
|
||||
'einundzwanzig_pleb_id' => $this->currentPleb->id,
|
||||
'category' => $this->form->category,
|
||||
'name' => $this->form->name,
|
||||
'description' => $this->form->description,
|
||||
]);
|
||||
|
||||
$notification
|
||||
->addMedia($this->file->getRealPath())
|
||||
->usingName($this->file->getClientOriginalName())
|
||||
->toMediaCollection('pdf');
|
||||
|
||||
$this->form->reset();
|
||||
@@ -78,7 +79,7 @@ $save = function () {
|
||||
->get();
|
||||
};
|
||||
|
||||
$delete = function($id) {
|
||||
$delete = function ($id) {
|
||||
$notification = new WireNotification($this);
|
||||
$notification->confirm([
|
||||
'title' => 'Post löschen',
|
||||
@@ -91,7 +92,7 @@ $delete = function($id) {
|
||||
]);
|
||||
};
|
||||
|
||||
$deleteNow = function($id) {
|
||||
$deleteNow = function ($id) {
|
||||
$notification = \App\Models\Notification::query()->find($id);
|
||||
$notification->delete();
|
||||
$this->news = \App\Models\Notification::query()
|
||||
@@ -142,8 +143,10 @@ $deleteNow = function($id) {
|
||||
</div>
|
||||
<ul class="flex flex-nowrap md:block mr-3 md:mr-0">
|
||||
@foreach(\App\Enums\NewsCategory::selectOptions() as $category)
|
||||
<li class="mr-0.5 md:mr-0 md:mb-0.5" 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">
|
||||
<li class="mr-0.5 md:mr-0 md:mb-0.5"
|
||||
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>
|
||||
<span
|
||||
class="text-sm font-medium text-amber-500">{{ $category['label'] }}</span>
|
||||
@@ -163,7 +166,8 @@ $deleteNow = function($id) {
|
||||
|
||||
<div class="space-y-2">
|
||||
@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">
|
||||
<!-- Avatar -->
|
||||
<div class="shrink-0 mt-1.5">
|
||||
@@ -185,7 +189,8 @@ $deleteNow = function($id) {
|
||||
<footer class="flex flex-wrap text-sm">
|
||||
<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">
|
||||
<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">
|
||||
<svg class="mr-2 fill-current" width="16"
|
||||
height="16"
|
||||
@@ -209,7 +214,7 @@ $deleteNow = function($id) {
|
||||
<x-button
|
||||
xs
|
||||
target="_blank"
|
||||
:href="$post->getFirstMediaUrl('pdf')"
|
||||
:href="url()->temporarySignedRoute('dl', now()->addMinutes(30), ['media' => $post->getFirstMedia('pdf')])"
|
||||
label="Öffnen"
|
||||
primary icon="cloud-arrow-down"/>
|
||||
@if($canEdit)
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
||||
|
||||
Route::redirect('/', '/association/profile');
|
||||
|
||||
Route::get('dl/{media}', function (Media $media, Request $request) {
|
||||
return response()->download($media->getPath(), $media->name);
|
||||
})
|
||||
->name('dl')
|
||||
->middleware('signed');
|
||||
|
||||
Reference in New Issue
Block a user