diff --git a/Web/Models/Entities/Photo.php b/Web/Models/Entities/Photo.php index 1eb42110..d50cc854 100644 --- a/Web/Models/Entities/Photo.php +++ b/Web/Models/Entities/Photo.php @@ -187,7 +187,7 @@ class Photo extends Media foreach ($sizes as $id => $meta) { if (isset($meta[3]) && !$meta[3]) { $res[$id] = (object) [ - "url" => ovk_scheme(true) . $_SERVER["HTTP_HOST"] . "/photos/thumbnails/" . $this->getId() . "_$id.jpeg", + "url" => ovk_scheme(true) . $_SERVER["HTTP_HOST"] . "/photos/thumbnails/" . $this->getRecord()->hash . "_$id.jpeg", "width" => null, "height" => null, "crop" => null, diff --git a/Web/Models/Repositories/Photos.php b/Web/Models/Repositories/Photos.php index 47c022b5..24ff8070 100644 --- a/Web/Models/Repositories/Photos.php +++ b/Web/Models/Repositories/Photos.php @@ -28,6 +28,17 @@ class Photos return new Photo($photo); } + public function getByHash(string $hash): ?Photo + { + $photo = $this->photos->where("hash", $hash)->fetch(); + + if (!$photo) { + return null; + } + + return new Photo($photo); + } + public function getByOwnerAndVID(int $owner, int $vId): ?Photo { $photo = $this->photos->where([ diff --git a/Web/Presenters/PhotosPresenter.php b/Web/Presenters/PhotosPresenter.php index ebff8f7e..ac830f92 100644 --- a/Web/Presenters/PhotosPresenter.php +++ b/Web/Presenters/PhotosPresenter.php @@ -229,9 +229,9 @@ final class PhotosPresenter extends OpenVKPresenter $this->renderPhoto($photo->getOwner(true)->getId(), $photo->getVirtualId()); } - public function renderThumbnail($id, $size): void + public function renderThumbnail($hash, $size): void { - $photo = $this->photos->get($id); + $photo = $this->photos->getByHash((string) $hash); if (!$photo || $photo->isDeleted()) { $this->notFound(); } diff --git a/Web/routes.yml b/Web/routes.yml index eac95801..7b42dfbe 100644 --- a/Web/routes.yml +++ b/Web/routes.yml @@ -173,8 +173,10 @@ routes: handler: "Photos->photo" - url: "/photo{num}_{num}/like" handler: "Photos->like" - - url: "/photos/thumbnails/{num}_{text}.jpeg" + - url: "/photos/thumbnails/{?hash}_{text}.jpeg" handler: "Photos->thumbnail" + placeholders: + hash: "[A-z0-9\\-_\\/]{15,}" - url: "/photos/{text}" handler: "Photos->absolutePhoto" - url: "/photo{num}_{num}/edit"