From 76aee9985afc0c8f62e5b60b161539489ba90bd9 Mon Sep 17 00:00:00 2001 From: kwadwo Date: Mon, 11 Feb 2013 06:30:02 -0800 Subject: [PATCH] Conduit file upload method that takes in the files content hash and name. Returns the file phid if successful. Updates to phutil library map. Summary: Conduit method to upload a a new file using a hash Test Plan: Try uploading a file using its content hash Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D4899 --- src/__phutil_library_map__.php | 2 + .../ConduitAPI_file_uploadhash_Method.php | 45 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/applications/files/conduit/ConduitAPI_file_uploadhash_Method.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 150397ea64..cd03c30d9a 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -146,6 +146,7 @@ phutil_register_library_map(array( 'ConduitAPI_file_download_Method' => 'applications/files/conduit/ConduitAPI_file_download_Method.php', 'ConduitAPI_file_info_Method' => 'applications/files/conduit/ConduitAPI_file_info_Method.php', 'ConduitAPI_file_upload_Method' => 'applications/files/conduit/ConduitAPI_file_upload_Method.php', + 'ConduitAPI_file_uploadhash_Method' => 'applications/files/conduit/ConduitAPI_file_uploadhash_Method.php', 'ConduitAPI_flag_Method' => 'applications/flag/conduit/ConduitAPI_flag_Method.php', 'ConduitAPI_flag_delete_Method' => 'applications/flag/conduit/ConduitAPI_flag_delete_Method.php', 'ConduitAPI_flag_edit_Method' => 'applications/flag/conduit/ConduitAPI_flag_edit_Method.php', @@ -1641,6 +1642,7 @@ phutil_register_library_map(array( 'ConduitAPI_file_download_Method' => 'ConduitAPIMethod', 'ConduitAPI_file_info_Method' => 'ConduitAPIMethod', 'ConduitAPI_file_upload_Method' => 'ConduitAPIMethod', + 'ConduitAPI_file_uploadhash_Method' => 'ConduitAPIMethod', 'ConduitAPI_flag_Method' => 'ConduitAPIMethod', 'ConduitAPI_flag_delete_Method' => 'ConduitAPI_flag_Method', 'ConduitAPI_flag_edit_Method' => 'ConduitAPI_flag_Method', diff --git a/src/applications/files/conduit/ConduitAPI_file_uploadhash_Method.php b/src/applications/files/conduit/ConduitAPI_file_uploadhash_Method.php new file mode 100644 index 0000000000..17a66361cb --- /dev/null +++ b/src/applications/files/conduit/ConduitAPI_file_uploadhash_Method.php @@ -0,0 +1,45 @@ + 'required nonempty string', + 'name' => 'required nonempty string', + ); + } + + public function defineReturnType() { + return 'phid or null'; + } + + public function defineErrorTypes() { + return array( + ); + } + + protected function execute(ConduitAPIRequest $request) { + $hash = $request->getValue('hash'); + $name = $request->getValue('name'); + $user = $request->getUser(); + + $file = PhabricatorFile::newFileFromContentHash( + $hash, + array( + 'name' => $name, + 'authorPHID' => $user->getPHID(), + )); + + if ($file) { + return $file->getPHID(); + } + return $file; + } +}