From 1efc66a0dde07cdc456b57a803f6d86d113cbe7b Mon Sep 17 00:00:00 2001 From: epriestley Date: Sat, 21 May 2011 09:53:50 -0700 Subject: [PATCH] Add file.download to Conduit Summary: This is required to make "arc patch" and "arc export" support binary changes. Test Plan: Called from web console and "arc". Reviewed By: aran Reviewers: tuomaspelkonen, jungejason, aran CC: aran, epriestley Differential Revision: 326 --- src/__phutil_library_map__.php | 2 + .../ConduitAPI_file_download_Method.php | 54 +++++++++++++++++++ .../conduit/method/file/download/__init__.php | 16 ++++++ 3 files changed, 72 insertions(+) create mode 100644 src/applications/conduit/method/file/download/ConduitAPI_file_download_Method.php create mode 100644 src/applications/conduit/method/file/download/__init__.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index d6ed7a22b5..5f1a31bca8 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -96,6 +96,7 @@ phutil_register_library_map(array( 'ConduitAPI_differential_updatetaskrevisionassoc_Method' => 'applications/conduit/method/differential/updatetaskrevisionassoc', 'ConduitAPI_diffusion_getcommits_Method' => 'applications/conduit/method/diffusion/getcommits', 'ConduitAPI_diffusion_getrecentcommitsbypath_Method' => 'applications/conduit/method/diffusion/getrecentcommitsbypath', + 'ConduitAPI_file_download_Method' => 'applications/conduit/method/file/download', 'ConduitAPI_file_upload_Method' => 'applications/conduit/method/file/upload', 'ConduitAPI_path_getowners_Method' => 'applications/conduit/method/path/getowners', 'ConduitAPI_user_find_Method' => 'applications/conduit/method/user/find', @@ -593,6 +594,7 @@ phutil_register_library_map(array( 'ConduitAPI_differential_updatetaskrevisionassoc_Method' => 'ConduitAPIMethod', 'ConduitAPI_diffusion_getcommits_Method' => 'ConduitAPIMethod', 'ConduitAPI_diffusion_getrecentcommitsbypath_Method' => 'ConduitAPIMethod', + 'ConduitAPI_file_download_Method' => 'ConduitAPIMethod', 'ConduitAPI_file_upload_Method' => 'ConduitAPIMethod', 'ConduitAPI_path_getowners_Method' => 'ConduitAPIMethod', 'ConduitAPI_user_find_Method' => 'ConduitAPIMethod', diff --git a/src/applications/conduit/method/file/download/ConduitAPI_file_download_Method.php b/src/applications/conduit/method/file/download/ConduitAPI_file_download_Method.php new file mode 100644 index 0000000000..989b26c941 --- /dev/null +++ b/src/applications/conduit/method/file/download/ConduitAPI_file_download_Method.php @@ -0,0 +1,54 @@ + 'required phid', + ); + } + + public function defineReturnType() { + return 'nonempty base64-bytes'; + } + + public function defineErrorTypes() { + return array( + 'ERR-BAD-PHID' => 'No such file exists.', + ); + } + + protected function execute(ConduitAPIRequest $request) { + $phid = $request->getValue('phid'); + + $file = id(new PhabricatorFile())->loadOneWhere( + 'phid = %s', + $phid); + if (!$file) { + throw new ConduitException('ERR-BAD-PHID'); + } + + return base64_encode($file->loadFileData()); + } + +} diff --git a/src/applications/conduit/method/file/download/__init__.php b/src/applications/conduit/method/file/download/__init__.php new file mode 100644 index 0000000000..e073903b6d --- /dev/null +++ b/src/applications/conduit/method/file/download/__init__.php @@ -0,0 +1,16 @@ +