]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Api/Mastodon/Accounts.php
Move jsonError out of Factory\Api\Mastodon\Error->UnprocessableEntity
[friendica.git] / src / Module / Api / Mastodon / Accounts.php
index 0d48744a40afd258a65a8f4488ba762df94ff3f9..6b88b84ef3fac571fc365743abdfbd1e8888cda8 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -24,6 +24,7 @@ namespace Friendica\Module\Api\Mastodon;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\DI;
+use Friendica\Model\Contact;
 use Friendica\Module\BaseApi;
 
 /**
@@ -32,21 +33,31 @@ use Friendica\Module\BaseApi;
 class Accounts extends BaseApi
 {
        /**
-        * @param array $parameters
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function rawContent(array $parameters = [])
+       protected function rawContent(array $request = [])
        {
-               if (empty($parameters['id'])) {
-                       DI::mstdnError()->RecordNotFound();
+               $uid = self::getCurrentUserID();
+
+               if (empty($this->parameters['id']) && empty($this->parameters['name'])) {
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
-               $id = $parameters['id'];
-               if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
-                       DI::mstdnError()->RecordNotFound();
+               if (!empty($this->parameters['id'])) {
+                       $id = $this->parameters['id'];
+                       if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
+                               $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+                       }
+               } else {
+                       $contact = Contact::selectFirst(['id'], ['nick' => $this->parameters['name'], 'uid' => 0]);
+                       if (!empty($contact['id'])) {
+                               $id = $contact['id'];
+                       } elseif (!($id = Contact::getIdForURL($this->parameters['name'], 0, false))) {
+                               $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+                       }
                }
 
-               $account = DI::mstdnAccount()->createFromContactId($id, self::getCurrentUserID());
-               System::jsonExit($account);
+               $account = DI::mstdnAccount()->createFromContactId($id, $uid);
+               $this->jsonExit($account);
        }
 }