Stuff
This commit is contained in:
parent
49ac7f48e0
commit
6ef747b027
6 changed files with 86 additions and 3 deletions
|
@ -104,11 +104,16 @@ class PublicController extends BaseController
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log::error("Get Image failed", ["image_id" => $image->id]);
|
||||||
return abort(500, "Something go wrong");
|
return abort(500, "Something go wrong");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function tryReturnFromCache($cacheName, $tenant_id, $gallery_id, $image_id) {
|
private function tryReturnFromCache($cacheName, $tenant_id, $gallery_id, $image_id) {
|
||||||
|
$image = Image::query()->where("id", "=", $image_id)->firstOrFail();
|
||||||
|
if($image->refreshCache) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
if(Storage::disk('cache')->exists($cacheName)) {
|
if(Storage::disk('cache')->exists($cacheName)) {
|
||||||
$this->addAccessLog($tenant_id, $gallery_id, $image_id, "Cache", Storage::disk('cache')->size($cacheName));
|
$this->addAccessLog($tenant_id, $gallery_id, $image_id, "Cache", Storage::disk('cache')->size($cacheName));
|
||||||
return Storage::disk('cache')->response($cacheName, null, ['Cache-Control'=> 'max-age='.(60*60*24).', public']);
|
return Storage::disk('cache')->response($cacheName, null, ['Cache-Control'=> 'max-age='.(60*60*24).', public']);
|
||||||
|
|
|
@ -10,6 +10,7 @@ use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Routing\Controller as BaseController;
|
use Illuminate\Routing\Controller as BaseController;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Redirect;
|
use Illuminate\Support\Facades\Redirect;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
|
@ -59,6 +60,23 @@ class TenantController extends BaseController
|
||||||
return view("tenant.watermark");
|
return view("tenant.watermark");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function deleteWatermark() {
|
||||||
|
DB::beginTransaction();
|
||||||
|
$tenant = Tenant::query()->where("id", "=", session("current_tenant_id"))->firstOrFail();
|
||||||
|
$oldImage = Image::query()->where("id", "=", $tenant->watermark)->first();
|
||||||
|
if(!is_null($oldImage)) {
|
||||||
|
Storage::disk($oldImage->driver)->delete($oldImage->path);
|
||||||
|
$oldImage->deleted_at = date("Y-m-d H:i:s");
|
||||||
|
$oldImage->saveOrFail();
|
||||||
|
}
|
||||||
|
$tenant->watermark = null;
|
||||||
|
$tenant->saveOrFail();
|
||||||
|
|
||||||
|
DB::statement("UPDATE images SET refreshCache = 1 WHERE gallery IN (SELECT `id` FROM `galleries` WHERE `tenant` = 1);");
|
||||||
|
DB::commit();
|
||||||
|
return \redirect("/s/watermark");
|
||||||
|
}
|
||||||
|
|
||||||
public function watermarkSave(Request $request) {
|
public function watermarkSave(Request $request) {
|
||||||
$validated = $request->validate([
|
$validated = $request->validate([
|
||||||
'files.0' => 'required|image'
|
'files.0' => 'required|image'
|
||||||
|
@ -88,6 +106,10 @@ class TenantController extends BaseController
|
||||||
$tenant->watermark = $image->id;
|
$tenant->watermark = $image->id;
|
||||||
$tenant->saveOrFail();
|
$tenant->saveOrFail();
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
DB::statement("UPDATE images SET refreshCache = 1 WHERE gallery IN (SELECT `id` FROM `galleries` WHERE `tenant` = 1);");
|
||||||
|
DB::commit();
|
||||||
|
|
||||||
return \redirect("/s/watermark");
|
return \redirect("/s/watermark");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,7 +112,10 @@ class ResizeImage implements ShouldQueue
|
||||||
|
|
||||||
|
|
||||||
$img->save($tmpfname);
|
$img->save($tmpfname);
|
||||||
|
Log::info("Update cache for Image", ["id" => $image->id, "size" => $this->size]);
|
||||||
Storage::disk("cache")->put($cacheName."_".$this->size, file_get_contents($tmpfname));
|
Storage::disk("cache")->put($cacheName."_".$this->size, file_get_contents($tmpfname));
|
||||||
|
$image->refreshCache = false;
|
||||||
|
$image->saveOrFail();
|
||||||
unlink($tmpfname);
|
unlink($tmpfname);
|
||||||
|
|
||||||
//Watermark
|
//Watermark
|
||||||
|
@ -120,7 +123,7 @@ class ResizeImage implements ShouldQueue
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getImage(Tenant $tenant, Gallery $gallery, Image $image, $cacheName) {
|
private function getImage(Tenant $tenant, Gallery $gallery, Image $image, $cacheName) {
|
||||||
if (Storage::disk('cache')->exists($cacheName."_orginal")) {
|
if (Storage::disk('cache')->exists($cacheName."_orginal") && $image->refreshCache == false) {
|
||||||
$file = Storage::disk("cache")->get($cacheName."_orginal");
|
$file = Storage::disk("cache")->get($cacheName."_orginal");
|
||||||
} else {
|
} else {
|
||||||
$this->addAccessLog($tenant->id, $gallery->id, $image->id, "Access", $image->size);
|
$this->addAccessLog($tenant->id, $gallery->id, $image->id, "Access", $image->size);
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class ImageRefreshCache extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table("images", function (Blueprint $table) {
|
||||||
|
$table->boolean("refreshCache")->default(false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,16 +1,38 @@
|
||||||
@extends('layout/template')
|
@extends('layout/template')
|
||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
<h1>Watermark</h1>
|
<h1>Watermark for {{ $current_tenant->name }}</h1>
|
||||||
|
<p>
|
||||||
|
<div class="alert alert-info">
|
||||||
|
If you set/change/delete the Watermark it will effect your space and traffic in the following ways:
|
||||||
|
<ul>
|
||||||
|
<li>Your Space will increase by the size of the Watermark</li>
|
||||||
|
<li>All cached Images need to be regenerate that will increase your traffic (one time)</li>
|
||||||
|
<li>If you add new Images the Watermark need to be downloaded, that will increase your traffic (each time)</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</p>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
|
<h3>Update Watermark</h3>
|
||||||
<form method="post" enctype="multipart/form-data">
|
<form method="post" enctype="multipart/form-data">
|
||||||
@csrf
|
@csrf
|
||||||
<input type="file" name="files[]" class="form-control" >
|
<input type="file" name="files[]" class="form-control" >
|
||||||
<input type="submit" value="Upload Watermark" class="btn btn-outline-success">
|
<input type="submit" value="Upload Watermark" class="btn btn-outline-success">
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
@if (!is_null($current_tenant->watermark))
|
||||||
|
<h3>Delete Watermark</h3>
|
||||||
|
<a href="/s/watermark/delete" class="btn btn-outline-danger">Delete Watermark</a>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
Current Watermark:<br>
|
||||||
|
@if (!is_null($current_tenant->watermark))
|
||||||
|
<img src="/s/watermark/image" style="max-width: 100%;">
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-6">Current Watermark:<br><img src="/s/watermark/image" style="max-width: 100%;"></div>
|
|
||||||
</div>
|
</div>
|
||||||
@if ($errors->any())
|
@if ($errors->any())
|
||||||
<div class="alert alert-danger">
|
<div class="alert alert-danger">
|
||||||
|
|
|
@ -48,6 +48,7 @@ Route::middleware([\App\Http\Middleware\TenanMiddleware::class])->group(function
|
||||||
Route::get("/s/watermark", [\App\Http\Controllers\TenantController::class, 'watermarkView']);
|
Route::get("/s/watermark", [\App\Http\Controllers\TenantController::class, 'watermarkView']);
|
||||||
Route::post("/s/watermark", [\App\Http\Controllers\TenantController::class, 'watermarkSave']);
|
Route::post("/s/watermark", [\App\Http\Controllers\TenantController::class, 'watermarkSave']);
|
||||||
Route::get("/s/watermark/image", [\App\Http\Controllers\PublicController::class, "returnWatermakeFile"]);
|
Route::get("/s/watermark/image", [\App\Http\Controllers\PublicController::class, "returnWatermakeFile"]);
|
||||||
|
Route::get("/s/watermark/delete", [\App\Http\Controllers\TenantController::class, "deleteWatermark"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::get("/{name}", [\App\Http\Controllers\PublicController::class, 'listGalleriesView'])->middleware([\App\Http\Middleware\TenanMiddleware::class]);
|
Route::get("/{name}", [\App\Http\Controllers\PublicController::class, 'listGalleriesView'])->middleware([\App\Http\Middleware\TenanMiddleware::class]);
|
||||||
|
|
Loading…
Reference in a new issue