From 622c9204b2d7150951ebf0287b712042925bdfbc Mon Sep 17 00:00:00 2001 From: Celestora Date: Sun, 24 Apr 2022 15:38:53 +0300 Subject: [PATCH] Use Photo::getVkApiSizes in wall.get Now wall.get will reflect accurate information about image sizes and their dimensions. --- VKAPI/Handlers/Wall.php | 44 ++++------------------------------- Web/Models/Entities/Photo.php | 7 ++++-- 2 files changed, 9 insertions(+), 42 deletions(-) diff --git a/VKAPI/Handlers/Wall.php b/VKAPI/Handlers/Wall.php index 7635342b..6acc9c89 100644 --- a/VKAPI/Handlers/Wall.php +++ b/VKAPI/Handlers/Wall.php @@ -32,47 +32,11 @@ final class Wall extends VKAPIRequestHandler "type" => "photo", "photo" => [ "album_id" => $attachment->getAlbum() ? $attachment->getAlbum()->getId() : null, - "date" => $attachment->getPublicationTime()->timestamp(), - "id" => $attachment->getVirtualId(), + "date" => $attachment->getPublicationTime()->timestamp(), + "id" => $attachment->getVirtualId(), "owner_id" => $attachment->getOwner()->getId(), - "sizes" => array( - [ - "height" => 2560, - "url" => $attachment->getURLBySizeId("normal"), - "type" => "m", - "width" => 2560, - ], - [ - "height" => 130, - "url" => $attachment->getURLBySizeId("tiny"), - "type" => "o", - "width" => 130, - ], - [ - "height" => 604, - "url" => $attachment->getURLBySizeId("normal"), - "type" => "p", - "width" => 604, - ], - [ - "height" => 807, - "url" => $attachment->getURLBySizeId("large"), - "type" => "q", - "width" => 807, - ], - [ - "height" => 1280, - "url" => $attachment->getURLBySizeId("larger"), - "type" => "r", - "width" => 1280, - ], - [ - "height" => 75, // Для временного компросима оставляю статическое число. Если каждый раз обращаться к файлу за количеством пикселов, то наступает пuпuська полная с производительностью, так что пока так - "url" => $attachment->getURLBySizeId("miniscule"), - "type" => "s", - "width" => 75, - ]), - "text" => "", + "sizes" => array_values($attachment->getVkApiSizes()), + "text" => "", "has_tags" => false ] ]; diff --git a/Web/Models/Entities/Photo.php b/Web/Models/Entities/Photo.php index 0f223679..71d5efcb 100644 --- a/Web/Models/Entities/Photo.php +++ b/Web/Models/Entities/Photo.php @@ -165,8 +165,11 @@ class Photo extends Media foreach($manifest->Size as $size) $mappings[(string) $size["id"]] = (string) $size["vkId"]; - foreach($sizes as $id => $meta) - $res[$mappings[$id] ?? $id] = $meta; + foreach($sizes as $id => $meta) { + $type = $mappings[$id] ?? $id; + $meta->type = $type; + $res[$type] = $meta; + } return $res; }