diff --git a/app/Http/Controllers/PublicController.php b/app/Http/Controllers/PublicController.php index bb132c7..127304a 100644 --- a/app/Http/Controllers/PublicController.php +++ b/app/Http/Controllers/PublicController.php @@ -59,7 +59,9 @@ class PublicController extends BaseController "pages" => ($g->count() / 10), "preview" => $preview, "next" => $next], - "data" => \App\Http\Resources\Gallery::collection($r)]); + "data" => [ + "galleries" => \App\Http\Resources\Gallery::collection($r) + ]]); } public function listGalleriesView($name, Request $request) { $tenant = Tenant::query()->where("url", "=", $name)->firstOrFail(); @@ -82,6 +84,28 @@ class PublicController extends BaseController return view("themes.tenant.".$theme.".list", ["galleries" => $galleries, "tenant" => $tenant]); } + public function listGalleryImagesViewAPI($tenant, $gallery, Request $request) { + $tenant = Tenant::query()->where("url", "=", $tenant)->firstOrFail(); + $gallery = Gallery::getByTenantAndUrl($tenant->id, $gallery); + if($gallery->status == "online" || (Auth::check() && $gallery->status == "preview" && Auth::user()->id == $tenant->owner)) { + $images = Image::query() + ->where("gallery", "=", $gallery->id) + ->whereNull("deleted_at") + ->orderBy("rating") + ->orderBy("DateTimeOriginal") + ->get(); + } else { + abort( 404); + } + + $parser = new \Parsedown(); + $gallery->html = $parser->parse($gallery->description); + + return response()->json(["data" => ["gallery" => new \App\Http\Resources\Gallery($gallery), "images" => \App\Http\Resources\Image::collection(collect(($images)))]]); + + return view("themes.gallery.".$theme.".list", ["gallery" => $gallery, "tenant" => $tenant, "images" => $images]); + } + public function listGalleryImagesView($tenant, $gallery, Request $request) { $tenant = Tenant::query()->where("url", "=", $tenant)->firstOrFail(); $gallery = Gallery::getByTenantAndUrl($tenant->id, $gallery); diff --git a/app/Http/Resources/Gallery.php b/app/Http/Resources/Gallery.php index aeb21ac..c5419b3 100644 --- a/app/Http/Resources/Gallery.php +++ b/app/Http/Resources/Gallery.php @@ -15,12 +15,14 @@ class Gallery extends JsonResource public function toArray($request) { $data = []; - $data["id"] = $this->id; + #$data["id"] = $this->id; $data["name"] = $this->name; $data["created"] = $this->gallery_create_time; $data["url"] = [ "name" => $this->url, - "url" => url("/".$this->getTenant()->url."/".$this->url)]; + "url" => url("/".$this->getTenant()->url."/".$this->url), + "json" => url("/".$this->getTenant()->url."/".$this->url.".json"), + ]; $data["mainImage"] = [ "id" => $this->main_image, "url" => [ @@ -29,8 +31,11 @@ class Gallery extends JsonResource "big" => url("/".$this->getTenant()->url."/".$this->url."/".$this->main_image."/file?size=big") ]]; $data["description"] = $this->description; - $data["tags"] = json_decode($this->tags); + $t = json_decode($this->tags); + foreach ($t as $i => $g) { + $t[$i] = trim($g); + } + $data["tags"] = $t; return $data; - #return parent::toArray($request); } } diff --git a/app/Http/Resources/Image.php b/app/Http/Resources/Image.php new file mode 100644 index 0000000..3dbe2a4 --- /dev/null +++ b/app/Http/Resources/Image.php @@ -0,0 +1,31 @@ +id; + $d["name"] = $this->name; + $d["description"] = $this->description; + $d["filename"] = $this->filename; + $d["size"] = $this->size; + $d["exit"] = ["DateTimeOriginal" => $this->DateTimeOriginal]; + $d["url"] = [ + "small" => url("/".$this->getGallery()->getTenant()->url."/".$this->getGallery()->url."/".$this->id."/file?size=small"), + "medium" => url("/".$this->getGallery()->getTenant()->url."/".$this->getGallery()->url."/".$this->id."/file?size=medium"), + "big" => url("/".$this->getGallery()->getTenant()->url."/".$this->getGallery()->url."/".$this->id."/file?size=big") + ]; + return $d; + } +} diff --git a/app/Models/Image.php b/app/Models/Image.php index fd7b8c1..025f7a6 100644 --- a/app/Models/Image.php +++ b/app/Models/Image.php @@ -42,4 +42,9 @@ class Image extends Authenticatable protected $casts = [ ]; + public function getGallery() + { + $gallery = Gallery::query()->where("id", "=", $this->gallery)->firstOrFail(); + return $gallery; + } } diff --git a/routes/web.php b/routes/web.php index d1d7928..421e10c 100644 --- a/routes/web.php +++ b/routes/web.php @@ -62,8 +62,8 @@ Route::middleware([\App\Http\Middleware\TenanMiddleware::class, \App\Http\Middle Route::get("/{name}.json", [\App\Http\Controllers\PublicController::class, 'listGalleriesViewAPI'])->middleware([\App\Http\Middleware\TenanMiddleware::class]); Route::get("/{name}", [\App\Http\Controllers\PublicController::class, 'listGalleriesView'])->middleware([\App\Http\Middleware\TenanMiddleware::class]); +Route::get("/{tenant}/{gallery}.json", [\App\Http\Controllers\PublicController::class, 'listGalleryImagesViewAPI'])->middleware([\App\Http\Middleware\TenanMiddleware::class]); Route::get("/{tenant}/{gallery}", [\App\Http\Controllers\PublicController::class, 'listGalleryImagesView'])->middleware([\App\Http\Middleware\TenanMiddleware::class]); -Route::get("/{tenant}/{gallery}.json", [\App\Http\Controllers\PublicController::class, 'listGalleryImagesView'])->middleware([\App\Http\Middleware\TenanMiddleware::class]); Route::get("/{tenant}/{gallery}/{image}/file", [\App\Http\Controllers\PublicController::class, 'returnImageFile']);