mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-nostr.git
synced 2025-12-14 06:36:46 +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
|
$this
|
||||||
->addMediaCollection('pdf')
|
->addMediaCollection('pdf')
|
||||||
->acceptsMimeTypes(['application/pdf'])
|
->acceptsMimeTypes(['application/pdf'])
|
||||||
->singleFile();
|
->singleFile()
|
||||||
|
->useDisk('private');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function einundzwanzigPleb(): BelongsTo
|
public function einundzwanzigPleb(): BelongsTo
|
||||||
|
|||||||
@@ -36,10 +36,16 @@ 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'),
|
||||||
'url' => env('APP_URL').'/storage',
|
'url' => env('APP_URL') . '/storage',
|
||||||
'visibility' => 'public',
|
'visibility' => 'public',
|
||||||
'throw' => false,
|
'throw' => false,
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -60,14 +60,15 @@ $save = function () {
|
|||||||
$notification = \App\Models\Notification::query()
|
$notification = \App\Models\Notification::query()
|
||||||
->orderBy('created_at', 'desc')
|
->orderBy('created_at', 'desc')
|
||||||
->create([
|
->create([
|
||||||
'einundzwanzig_pleb_id' => $this->currentPleb->id,
|
'einundzwanzig_pleb_id' => $this->currentPleb->id,
|
||||||
'category' => $this->form->category,
|
'category' => $this->form->category,
|
||||||
'name' => $this->form->name,
|
'name' => $this->form->name,
|
||||||
'description' => $this->form->description,
|
'description' => $this->form->description,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$notification
|
$notification
|
||||||
->addMedia($this->file->getRealPath())
|
->addMedia($this->file->getRealPath())
|
||||||
|
->usingName($this->file->getClientOriginalName())
|
||||||
->toMediaCollection('pdf');
|
->toMediaCollection('pdf');
|
||||||
|
|
||||||
$this->form->reset();
|
$this->form->reset();
|
||||||
@@ -78,7 +79,7 @@ $save = function () {
|
|||||||
->get();
|
->get();
|
||||||
};
|
};
|
||||||
|
|
||||||
$delete = function($id) {
|
$delete = function ($id) {
|
||||||
$notification = new WireNotification($this);
|
$notification = new WireNotification($this);
|
||||||
$notification->confirm([
|
$notification->confirm([
|
||||||
'title' => 'Post löschen',
|
'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 = \App\Models\Notification::query()->find($id);
|
||||||
$notification->delete();
|
$notification->delete();
|
||||||
$this->news = \App\Models\Notification::query()
|
$this->news = \App\Models\Notification::query()
|
||||||
@@ -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)
|
||||||
|
|||||||
@@ -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');
|
||||||
|
|||||||
Reference in New Issue
Block a user