added attachment temp download link

added simple attachs list
fixed area seeder
pull/49/head
A1Gard 5 months ago
parent fc5a288067
commit 3ff5f7543d

@ -9,6 +9,10 @@ use App\Models\Access;
use App\Models\Clip;
use Illuminate\Http\Request;
use App\Helper;
use Spatie\Image\Enums\AlignPosition;
use Spatie\Image\Enums\Fit;
use Spatie\Image\Enums\Unit;
use Spatie\Image\Image;
use function App\Helpers\hasCreateRoute;
class ClipController extends XController
@ -67,7 +71,28 @@ class ClipController extends XController
// }
if ($request->has('cover')){
$clip->cover = $this->storeFile('cover',$clip, 'clips');
$key = 'cover';
$format = $request->file($key)->guessExtension();
if (strtolower($format) == 'png'){
$format = 'webp';
}
$i = Image::load($request->file($key)->getPathname())
->optimize()
// ->nonQueued()
->format($format);
if (getSetting('watermark2')) {
$i->watermark(public_path('upload/images/logo.png'),
AlignPosition::BottomLeft, 5, 5, Unit::Percent,
config('app.media.watermark_size'), Unit::Percent,
config('app.media.watermark_size'), Unit::Percent, Fit::Contain,
config('app.media.watermark_opacity'));
}
$i->save(storage_path() . '/app/public/cover/optimized-'. $clip->$key);
}
if ($request->has('clip')){
$clip->file = $this->storeFile('clip',$clip, 'clips');
}

@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\Models\Attachment;
use App\Models\Comment;
use App\Models\Customer;
use App\Models\Gallery;
@ -27,6 +28,10 @@ class ClientController extends Controller
public function post(Post $post)
{
if ($post->status = 0 && !auth()->check()){
return abort(403);
}
$area = 'post';
$title = $post->title;
$subtitle = $post->subtitle;
@ -35,6 +40,9 @@ class ClientController extends Controller
}
public function gallery(Gallery $gallery)
{
if ($gallery->status = 0 && !auth()->check()){
return abort(403);
}
$area = 'gallery';
$title = $gallery->title;
$subtitle = \Str::limit(strip_tags($gallery->description),15);
@ -120,4 +128,12 @@ class ClientController extends Controller
$posts = $group->posts()->orderByDesc('id')->paginate($this->paginate);
return view('client.group', compact('area', 'posts', 'title', 'subtitle','group'));
}
public function attachDl(Attachment $attachment){
$attachment->increment('downloads');
$file = (storage_path().'/app/public/attachments/'. $attachment->file);
if (file_exists($file)) {
return response()->download($file);
}
}
}

@ -26,7 +26,7 @@ class AttachmentSaveRequest extends FormRequest
'title' => ['required','string','min:2'],
'body' => ['nullable','string'],
'subtitle' => ['nullable','string'],
'file' => ['nullable','mimes:png,jpg,svg,mp4,pdf,docx,zip,rar','max:'.getMaxUploadSize()]
'file' => ['nullable','mimes:png,jpg,svg,mp4,pdf,docx,zip,rar,mp3','max:'.getMaxUploadSize()]
];
}
}

@ -31,10 +31,14 @@ class Attachment extends Model
public function tempUrl() // WIP
{
if ($this->file == null) {
return asset('/assets/upload/logo.svg');
}
return \URL::temporarySignedRoute(
'client.attach-dl', now()->addMinutes(60), [$this->slug]
);
return \Storage::url('attachments/' . $this->file);
}

@ -25,6 +25,14 @@ class Clip extends Model
return asset('assets/upload/logo.svg');;
}
return \Storage::url('clips/optimized-' . $this->cover);
}
public function imgOriginalUrl()
{
if ($this->cover == null) {
return asset('assets/upload/logo.svg');;
}
return \Storage::url('clips/' . $this->cover);
}

@ -37,7 +37,7 @@ class AreaSeeder extends Seeder
'name' => 'index',
'valid_segments' => json_encode(
["top", "slider", "header", "footer", "menu",
"parallax", "other", "posts", "products", "attachments"
"parallax", "other", "posts", "products"
, "groups", "categories", "category", "group", "index", "ads", "galleries"]
),
'max' => 10,
@ -48,7 +48,7 @@ class AreaSeeder extends Seeder
'name' => 'post',
'valid_segments' => json_encode(
["top", "header", "footer", "menu",
"parallax", "other", "post", "comments", "ads"]
"parallax", "other", "post", "comments", "ads" , "attachments"]
),
'max' => 6,
'preview' => 'client.post',
@ -68,7 +68,7 @@ class AreaSeeder extends Seeder
'name' => 'clip',
'valid_segments' => json_encode(
["top", "header", "footer", "menu",
"parallax", "other", "clip", "comments", "ads"]
"parallax", "other", "clip", "comments", "ads", "attachments"]
),
'max' => 6,
'preview' => 'client.clip',
@ -88,7 +88,7 @@ class AreaSeeder extends Seeder
'name' => 'gallery',
'valid_segments' => json_encode(
["top", "header", "footer", "menu",
"parallax", "other", "gallery", "comments", "ads"]
"parallax", "other", "gallery", "comments", "ads", "attachments"]
),
'max' => 6,
'preview' => 'client.gallery',
@ -108,7 +108,7 @@ class AreaSeeder extends Seeder
'name' => 'product',
'valid_segments' => json_encode(
["top", "header", "footer", "menu",
"parallax", "other", "product", "comments", "ads"]
"parallax", "other", "product", "comments", "ads", "attachments"]
),
'max' => 6,
'preview' => 'client.product',
@ -148,7 +148,7 @@ class AreaSeeder extends Seeder
'name' => 'category',
'valid_segments' => json_encode(
["top", "header", "footer", "menu",
"parallax", "other", "category", "ads", "products_page"]
"parallax", "other", "category", "ads", "products_page", "attachments"]
),
'max' => 6,
'preview' => 'client.attachment',
@ -168,7 +168,7 @@ class AreaSeeder extends Seeder
'name' => 'group',
'valid_segments' => json_encode(
["top", "header", "footer", "menu",
"parallax", "other", "group", "ads", 'posts_page']
"parallax", "other", "group", "ads", 'posts_page', "attachments"]
),
'max' => 6,
'preview' => 'client.group',

@ -137,7 +137,7 @@
</label>
<input name="file" type="file" class="form-control @error('file') is-invalid @enderror"
id="file" placeholder="{{__('File')}}"
accept=".png,.jpg,.svg,.mp4,.pdf,.docx,.zip,.rar"/>
accept=".png,.jpg,.svg,.mp4,.pdf,.docx,.zip,.rar,.mp3"/>
</div>
</div>
<div class="col-md-6 mt-3">

@ -0,0 +1,43 @@
<section class='SimpleAttachmentList'>
<div class="{{gfx()['container']}}">
@if(count($data['attachs']) > 0)
<h2 class="my-3">
{{__("Attachments")}}
</h2>
<table class="table table-striped attach-table table-hover">
<tr>
<th>
{{__("Name")}}
</th>
<th>
{{__("File name")}}
</th>
<th>
{{__("Size")}}
</th>
<th>
-
</th>
</tr>
@foreach($data['attachs'] as $attach)
<tr>
<th>
{{$attach->title}}
</th>
<th>
{{$attach->title}} <span> [ {{$attach->ext}} ] </span>
</th>
<th>
{{formatFileSize($attach->size)}}
</th>
<th>
<a href="{{$attach->tempUrl()}}" class="btn btn-sm btn-outline-primary">
<i class="ri-download-2-line"></i>
</a>
</th>
</tr>
@endforeach
</table>
@endif
</div>
</section>

@ -0,0 +1,10 @@
{
"name": "SimpleAttachmentList",
"version": "1.0",
"author": "xStack",
"email": "xshop@xstack.ir",
"license": "GPL-3.0-or-later",
"url": "https:\/\/xstack.ir",
"author_url": "https:\/\/4xmen.ir",
"packages": []
}

@ -0,0 +1,27 @@
<?php
namespace Resources\Views\Segments;
use App\Models\Part;
class SimpleAttachmentList
{
public static function onAdd(Part $part = null)
{
}
public static function onRemove(Part $part = null)
{
}
public static function onMount(Part $part = null, $model = null)
{
if ($model == null) {
return $part;
}
$part->attachs = $model->attachs;
return $part;
}
}

@ -0,0 +1,12 @@
.SimpleAttachmentList {
// scss\
padding: 2rem 0;
.attach-table {
border-radius: var(--xshop-border-radius);
overflow: hidden;
span{
color: var(--xshop-secondary);
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

@ -364,6 +364,7 @@ Route::name('client.')->group(function (){
Route::get('/group/{group}', [\App\Http\Controllers\ClientController::class,'group'])->name('group');
Route::get('/gallery/{gallery}', [\App\Http\Controllers\ClientController::class,'gallery'])->name('gallery');
Route::get('/search', [\App\Http\Controllers\ClientController::class,'search'])->name('search');
Route::get('attach/download/{attachment}', [\App\Http\Controllers\ClientController::class,'attachDl'])->name('attach-dl');
Route::get('/{post}', [\App\Http\Controllers\ClientController::class,'post'])->name('post');

Loading…
Cancel
Save