diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 818cd14df6..9741be3d59 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -106,6 +106,7 @@ phutil_register_library_map(array( 'ConduitAPI_diffusion_getrecentcommitsbypath_Method' => 'applications/conduit/method/diffusion/getrecentcommitsbypath', 'ConduitAPI_feed_publish_Method' => 'applications/conduit/method/feed/publish', 'ConduitAPI_file_download_Method' => 'applications/conduit/method/file/download', + 'ConduitAPI_file_info_Method' => 'applications/conduit/method/file/info', 'ConduitAPI_file_upload_Method' => 'applications/conduit/method/file/upload', 'ConduitAPI_maniphest_info_Method' => 'applications/conduit/method/maniphest/info', 'ConduitAPI_paste_info_Method' => 'applications/conduit/method/paste/info', @@ -724,6 +725,7 @@ phutil_register_library_map(array( 'ConduitAPI_diffusion_getrecentcommitsbypath_Method' => 'ConduitAPIMethod', 'ConduitAPI_feed_publish_Method' => 'ConduitAPIMethod', 'ConduitAPI_file_download_Method' => 'ConduitAPIMethod', + 'ConduitAPI_file_info_Method' => 'ConduitAPIMethod', 'ConduitAPI_file_upload_Method' => 'ConduitAPIMethod', 'ConduitAPI_maniphest_info_Method' => 'ConduitAPIMethod', 'ConduitAPI_paste_info_Method' => 'ConduitAPIMethod', diff --git a/src/applications/conduit/method/file/info/ConduitAPI_file_info_Method.php b/src/applications/conduit/method/file/info/ConduitAPI_file_info_Method.php new file mode 100644 index 0000000000..bcf613fcf6 --- /dev/null +++ b/src/applications/conduit/method/file/info/ConduitAPI_file_info_Method.php @@ -0,0 +1,77 @@ + 'optional phid', + 'id' => 'optional id', + ); + } + + public function defineReturnType() { + return 'nonempty dict'; + } + + public function defineErrorTypes() { + return array( + 'ERR-NOT-FOUND' => 'No such file exists.', + ); + } + + protected function execute(ConduitAPIRequest $request) { + $phid = $request->getValue('phid'); + $id = $request->getValue('id'); + + if ($id) { + $file = id(new PhabricatorFile())->load($id); + } else { + $file = id(new PhabricatorFile())->loadOneWhere( + 'phid = %s', + $phid); + } + + if (!$file) { + throw new ConduitException('ERR-NOT-FOUND'); + } + + $uri = $file->getBestURI(); + + return array( + 'id' => $file->getID(), + 'phid' => $file->getPHID(), + 'objectName' => 'F'.$file->getID(), + 'name' => $file->getName(), + 'mimeType' => $file->getMimeType(), + 'byteSize' => $file->getByteSize(), + 'authorPHID' => $file->getAuthorPHID(), + 'dateCreated' => $file->getDateCreated(), + 'dateModified' => $file->getDateModified(), + 'uri' => PhabricatorEnv::getProductionURI($uri), + ); + } + +} diff --git a/src/applications/conduit/method/file/info/__init__.php b/src/applications/conduit/method/file/info/__init__.php new file mode 100644 index 0000000000..2d9d86ac56 --- /dev/null +++ b/src/applications/conduit/method/file/info/__init__.php @@ -0,0 +1,17 @@ +getPHID()); } + public function getInfoURI() { + return '/file/info/'.$this->getPHID().'/'; + } + + public function getBestURI() { + if ($this->isViewableInBrowser()) { + return $this->getViewURI(); + } else { + return $this->getInfoURI(); + } + } + public function getThumb60x45URI() { return '/file/xform/thumb-60x45/'.$this->getPHID().'/'; }