This commit is contained in:
mrilyew 2025-02-17 20:12:06 +03:00
parent ee0dd8c749
commit ca8b6a83fb
4 changed files with 17 additions and 4 deletions

View file

@ -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,

View file

@ -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([

View file

@ -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();
}

View file

@ -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"