From f9de495d0bc3a3f58f367f7f3dcfa482b16cc9f3 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 15 Aug 2014 11:08:11 -0700 Subject: [PATCH] Use `file.download` to retrieve macro images in the IRC macro bot Summary: Fixes T5884. Macro images are no longer public on most installs. We could generate tokens for them, but this (using Conduit to pull the file data) is easier and more correct. Test Plan: Logged a bot into IRC and had it spam part of a macro before being killed for flooding. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T5884 Differential Revision: https://secure.phabricator.com/D10274 --- .../macro/conduit/MacroQueryConduitAPIMethod.php | 3 ++- .../bot/handler/PhabricatorBotMacroHandler.php | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/applications/macro/conduit/MacroQueryConduitAPIMethod.php b/src/applications/macro/conduit/MacroQueryConduitAPIMethod.php index 0b2ff99ba1..7f680ebdbd 100644 --- a/src/applications/macro/conduit/MacroQueryConduitAPIMethod.php +++ b/src/applications/macro/conduit/MacroQueryConduitAPIMethod.php @@ -72,7 +72,8 @@ final class MacroQueryConduitAPIMethod extends MacroConduitAPIMethod { 'uri' => $file->getBestURI(), 'phid' => $macro->getPHID(), 'authorPHID' => $file->getAuthorPHID(), - 'dateCreated' => $file->getDateCreated(), + 'dateCreated' => $file->getDateCreated(), + 'filePHID' => $file->getPHID(), ); } diff --git a/src/infrastructure/daemon/bot/handler/PhabricatorBotMacroHandler.php b/src/infrastructure/daemon/bot/handler/PhabricatorBotMacroHandler.php index bc60d9d9f3..9e7a051a8d 100644 --- a/src/infrastructure/daemon/bot/handler/PhabricatorBotMacroHandler.php +++ b/src/infrastructure/daemon/bot/handler/PhabricatorBotMacroHandler.php @@ -82,7 +82,17 @@ final class PhabricatorBotMacroHandler extends PhabricatorBotHandler { } public function rasterize($macro, $size, $aspect) { - $image = HTTPSFuture::loadContent($macro['uri']); + try { + $image = $this->getConduit()->callMethodSynchronous( + 'file.download', + array( + 'phid' => $macro['filePHID'], + )); + $image = base64_decode($image); + } catch (Exception $ex) { + return false; + } + if (!$image) { return false; }