diff --git a/src/conduit/DiagramUploadConduitAPIMethod.php b/src/conduit/DiagramUploadConduitAPIMethod.php index e8cfa86..d2d6f46 100644 --- a/src/conduit/DiagramUploadConduitAPIMethod.php +++ b/src/conduit/DiagramUploadConduitAPIMethod.php @@ -1,127 +1,176 @@ 'required nonempty base64-bytes', 'id' => 'optional id of diagram to be updated', 'viewPolicy' => 'optional valid policy string or ', ); } /** * This method should return a string that describes the type of data that * the method returns. * The return type is used for documentation purposes and is displayed on the * documentation page for the method to help users understand what kind of * data they can expect to receive when calling the method. */ protected function defineReturnType() { return 'nonempty guid'; } /** * The execute method is the core of your Conduit API method and is where * you implement the logic that performs the desired operation. * * The execute method should return the result of the operation in a * format that can be serialized as JSON. * The result will be sent back to the client as the response to the API * request. */ protected function execute(ConduitAPIRequest $request) { $viewer = $request->getUser(); $base64_data = $request->getValue('data_base64'); $diagram_id = $request->getValue('id'); if ($diagram_id) { // check if we are trying to save the same data as the current data $diagram = id(new DiagramVersion())->loadLatestByDiagramID($diagram_id); if ($diagram !== null) { $data = $diagram->getData(); $old_base64_data = base64_encode($data); if (DiagramController::equalPngMetaData($base64_data, $old_base64_data)) { return array( 'result' => $diagram->getPHID(), 'id' => $diagram->getDiagramID(), 'error_code' => null, 'error_info' => null ); } } } // verify if the uploaded data really contains a drawio diagram if (DiagramController::isDrawioPngBase64($base64_data) == false) { return array( 'result' => null, 'id' => null, 'error_code' => -1, 'error_info' => 'invalid base64 data' ); } // Set the options for the new file $options = array( 'name' => 'diagram.png', 'viewPolicy' => PhabricatorPolicies::POLICY_USER, 'mime-type' => 'image/png', 'actor' => $this->getViewer(), 'diagramID' => $diagram_id ); try { // Create the new file object $diagram = DiagramVersion::newFromFileData($base64_data, $options); $diagram->publishNewVersion($request, $diagram->getDiagramID()); return array( 'result' => $diagram->getPHID(), 'id' => $diagram->getDiagramID(), 'error_code' => null, 'error_info' => null ); } catch (Exception $e) { // error occurred during saving return array( 'result' => null, 'id' => null, 'error_code' => $e->getCode(), 'error_info' => $e->getMessage() ); } } /** * Descriptive text what this Conduit API method does * This method should return a string that describes what the method does. * The method description is used for documentation purposes and is * displayed on the documentation page for the method to help users * understand what the method does and how to use it. */ public function getMethodDescription() { - return pht('Upload a diagram to the server.'); + return pht("Upload a diagram to the server."); + } + + /** + * Generates custom documentation pages for this Conduit API method. + * This method should return an array of PhabricatorDocumentationBoxPage + * objects representing the custom documentation pages you want to add for + * the method. + * Each PhabricatorDocumentationBoxPage object represents a single + * documentation page and includes a title and content. + */ + public function newDocumentationPages(PhabricatorUser $viewer) { + $pages = array(); + + // create different chapters + $pages[] = $this->getDocumentationUsage($viewer); + + return $pages; + } + + /** + * Creates the documentation chapter about Usage + */ + public function getDocumentationUsage(PhabricatorUser $viewer) { + // set title and content of 'Usage' documentation box + $title = pht('Usage'); + $content = pht(<<newRemarkupDocumentationView($content); + + // create documentation box + $page = $this->newDocumentationBoxPage( + $viewer, + $title, + $content + ); + + // set icon and anchor of documentation box for navigation menu on the left + $page->setAnchor('usage'); + $page->setIconIcon('fa-warning'); + + return $page; } }