From 937357b1352744415ad094201565324083d6d12e Mon Sep 17 00:00:00 2001 From: Kekskurse Date: Wed, 20 Jan 2021 21:43:58 +0100 Subject: [PATCH] Stuff --- app/Http/Controllers/PublicController.php | 9 ++++++++- app/Http/Controllers/TenantController.php | 2 +- app/Jobs/ResizeImage.php | 9 ++++++--- .../2021_01_20_192143_image_watermark.php | 4 ++++ resources/views/tenant/watermark.blade.php | 16 +++++++++++----- routes/web.php | 1 + 6 files changed, 31 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/PublicController.php b/app/Http/Controllers/PublicController.php index eb92e0a..39de3b3 100644 --- a/app/Http/Controllers/PublicController.php +++ b/app/Http/Controllers/PublicController.php @@ -62,6 +62,13 @@ class PublicController extends BaseController return view("themes.gallery.gallery-detail.list", ["gallery" => $gallery, "tenant" => $tenant, "images" => $images]); } + public function returnWatermakeFile() { + $tenant = Tenant::query()->where("id", "=", session("current_tenant_id"))->firstOrFail(); + $image = Image::query()->where("id", "=", $tenant->watermark)->firstOrFail(); + $this->addAccessLog($tenant->id, null, $image->id, "Access", $image->size); + return Storage::disk($image->drive)->response($image->path); + } + public function returnImageFile($tenant_url, $gallery_url, $image_id, Request $request) { $sizeName = $request->input("size", "medium"); if(!array_key_exists($sizeName, self::$size)) { @@ -110,7 +117,7 @@ class PublicController extends BaseController } - private function addAccessLog(int $tenant, int $gallery, int $image, string $typ, int $size, $type = "general") { + private function addAccessLog(int $tenant, $gallery, int $image, string $typ, int $size, $type = "general") { $access = new Access(); $access->year = date("Y"); $access->month = date("m"); diff --git a/app/Http/Controllers/TenantController.php b/app/Http/Controllers/TenantController.php index 2880f33..d7a27af 100644 --- a/app/Http/Controllers/TenantController.php +++ b/app/Http/Controllers/TenantController.php @@ -77,6 +77,6 @@ class TenantController extends BaseController $tenant->watermark = $image->id; $tenant->saveOrFail(); - return "OK"; + return \redirect("/s/watermark"); } } diff --git a/app/Jobs/ResizeImage.php b/app/Jobs/ResizeImage.php index 3368a48..00e48c0 100644 --- a/app/Jobs/ResizeImage.php +++ b/app/Jobs/ResizeImage.php @@ -71,10 +71,11 @@ class ResizeImage implements ShouldQueue $img->resize($newWidth, $newHeight); //$img->blur(50); - if($this->size > 500 && !is_null($gallery->watermark)) { + if($this->size > 500 && !is_null($tenant->watermark)) { + Log::info("Add Watermark"); $cacheNameWatermark = ""; - $waterMarkImage = Image::query()->where("id", "=", $tenant->watermark); + $waterMarkImage = Image::query()->where("id", "=", $tenant->watermark)->firstOrFail(); $watermarkSource = $this->getImage($tenant, $gallery, $waterMarkImage, $cacheNameWatermark); $watermark = $manager->make($watermarkSource); @@ -103,6 +104,8 @@ class ResizeImage implements ShouldQueue //$font->angle(45); }); */ + } else { + Log::info("No Watermark"); } @@ -115,7 +118,7 @@ class ResizeImage implements ShouldQueue //Storage::disk("cache")->put($cacheName."_".$this->size, $image->getImageAsString(IMAGETYPE_JPEG, 100)); } - private function getImage($tenant, $gallery, $image, $cacheName) { + private function getImage(Tenant $tenant, Gallery $gallery, Image $image, $cacheName) { if (Storage::disk('cache')->exists($cacheName."_orginal")) { $file = Storage::disk("cache")->get($cacheName."_orginal"); } else { diff --git a/database/migrations/2021_01_20_192143_image_watermark.php b/database/migrations/2021_01_20_192143_image_watermark.php index 82d4e00..4ae4ce8 100644 --- a/database/migrations/2021_01_20_192143_image_watermark.php +++ b/database/migrations/2021_01_20_192143_image_watermark.php @@ -21,6 +21,10 @@ class ImageWatermark extends Migration Schema::table("tenants", function (Blueprint $table) { $table->unsignedBigInteger("watermark")->nullable()->default(null); }); + + Schema::table("access", function (Blueprint $table) { + $table->unsignedBigInteger("gallery")->nullable()->change(); + }); } /** diff --git a/resources/views/tenant/watermark.blade.php b/resources/views/tenant/watermark.blade.php index 3c303d9..9bd91a3 100644 --- a/resources/views/tenant/watermark.blade.php +++ b/resources/views/tenant/watermark.blade.php @@ -2,6 +2,16 @@ @section('content')

Watermark

+
+
+
+ @csrf + + +
+
+
Current Watermark:
+
@if ($errors->any())
@endif -
- @csrf - - -
+ @endsection diff --git a/routes/web.php b/routes/web.php index c795751..6b952fa 100644 --- a/routes/web.php +++ b/routes/web.php @@ -47,6 +47,7 @@ Route::middleware([\App\Http\Middleware\TenanMiddleware::class])->group(function Route::post("/g/{url}/save", [\App\Http\Controllers\GalleryController::class, 'saveImage']); Route::get("/s/watermark", [\App\Http\Controllers\TenantController::class, 'watermarkView']); Route::post("/s/watermark", [\App\Http\Controllers\TenantController::class, 'watermarkSave']); + Route::get("/s/watermark/image", [\App\Http\Controllers\PublicController::class, "returnWatermakeFile"]); }); Route::get("/{name}", [\App\Http\Controllers\PublicController::class, 'listGalleriesView'])->middleware([\App\Http\Middleware\TenanMiddleware::class]);