Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/985/head
Maxence Lange 2020-09-21 09:53:54 -01:00
rodzic 638838cd50
commit f5bd9ca6f0
7 zmienionych plików z 38 dodań i 126 usunięć

Wyświetl plik

@ -34,7 +34,7 @@ use daita\MySmallPhpTools\Traits\Nextcloud\TNCDataResponse;
use Exception;
use OCA\Social\AppInfo\Application;
use OCA\Social\Exceptions\AccountDoesNotExistException;
use OCA\Social\Exceptions\ClientDoesNotExistException;
use OCA\Social\Exceptions\ClientNotFoundException;
use OCA\Social\Exceptions\InstanceDoesNotExistException;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Actor\Person;
@ -172,9 +172,8 @@ class ApiController extends Controller {
], Http::STATUS_OK
);
}
} catch (Exception $e) {
return $this->fail($e, [], Http::STATUS_UNAUTHORIZED);
return $this->error($e->getMessage());
}
}
@ -192,8 +191,7 @@ class ApiController extends Controller {
return new DataResponse($this->viewer, Http::STATUS_OK);
} catch (Exception $e) {
return $this->fail($e, [], Http::STATUS_UNAUTHORIZED);
return $this->error($e->getMessage());
}
}
@ -221,7 +219,7 @@ class ApiController extends Controller {
return new DataResponse([], Http::STATUS_OK);
} catch (Exception $e) {
return $this->fail($e, [], Http::STATUS_UNAUTHORIZED);
return $this->error($e->getMessage());
}
}
@ -238,7 +236,7 @@ class ApiController extends Controller {
return new DataResponse([], Http::STATUS_OK);
} catch (Exception $e) {
return $this->fail($e, [], Http::STATUS_UNAUTHORIZED);
return $this->error($e->getMessage());
}
}
@ -270,6 +268,7 @@ class ApiController extends Controller {
$options = new TimelineOptions($this->request);
$options->setFormat(Stream::FORMAT_LOCAL);
$options->setTimeline($timeline);
$options->setLimit($limit);
try {
$this->initViewer(true);
@ -277,11 +276,7 @@ class ApiController extends Controller {
return new DataResponse($posts, Http::STATUS_OK);
} catch (Exception $e) {
return new DataResponse(
[
'error' => 'The access token was revoked'
], Http::STATUS_UNAUTHORIZED
);
return $this->error($e->getMessage());
}
}
@ -291,7 +286,7 @@ class ApiController extends Controller {
* @param bool $exception
*
* @return bool
* @throws Exception
* @throws ClientNotFoundException
*/
private function initViewer(bool $exception = false): bool {
try {
@ -312,7 +307,7 @@ class ApiController extends Controller {
return true;
} catch (Exception $e) {
if ($exception) {
throw $e;
throw new ClientNotFoundException('the access_token was revoked');
}
}
@ -323,7 +318,7 @@ class ApiController extends Controller {
/**
* @return string
* @throws AccountDoesNotExistException
* @throws ClientDoesNotExistException
* @throws ClientNotFoundException
*/
private function currentSession(): string {
$user = $this->userSession->getUser();
@ -340,6 +335,16 @@ class ApiController extends Controller {
throw new AccountDoesNotExistException('userId not defined');
}
/**
* @param string $error
*
* @return DataResponse
*/
private function error(string $error): DataResponse {
return new DataResponse(['error' => $error], Http::STATUS_UNAUTHORIZED);
}
}

Wyświetl plik

@ -34,6 +34,7 @@ use daita\MySmallPhpTools\Traits\Nextcloud\TNCDataResponse;
use Exception;
use OCA\Social\AppInfo\Application;
use OCA\Social\Exceptions\ClientException;
use OCA\Social\Exceptions\ClientNotFoundException;
use OCA\Social\Exceptions\InstanceDoesNotExistException;
use OCA\Social\Model\Client\SocialClient;
use OCA\Social\Service\AccountService;
@ -266,7 +267,6 @@ class OAuthController extends Controller {
// "created_at" => 1573979017
], Http::STATUS_OK
);
} catch (Exception $e) {
return new DataResponse(['error' => $e->getMessage()], Http::STATUS_UNAUTHORIZED);
}
@ -331,6 +331,8 @@ class OAuthController extends Controller {
"created_at" => $client->getCreation()
], Http::STATUS_OK
);
} catch (ClientNotFoundException $e) {
return new DataResponse(['error' => 'unknown client_id'], Http::STATUS_UNAUTHORIZED);
} catch (Exception $e) {
return new DataResponse(['error' => $e->getMessage()], Http::STATUS_UNAUTHORIZED);
}
@ -338,4 +340,3 @@ class OAuthController extends Controller {
}

Wyświetl plik

@ -34,7 +34,7 @@ namespace OCA\Social\Db;
use daita\MySmallPhpTools\Traits\TArrayTools;
use DateTime;
use Exception;
use OCA\Social\Exceptions\ClientDoesNotExistException;
use OCA\Social\Exceptions\ClientNotFoundException;
use OCA\Social\Model\Client\SocialClient;
use OCA\Social\Service\ClientService;
use OCP\DB\QueryBuilder\IQueryBuilder;
@ -68,10 +68,9 @@ class ClientRequest extends ClientRequestBuilder {
->setValue('app_scopes', $qb->createNamedParameter(json_encode($client->getAppScopes())));
try {
$qb->setValue(
'creation',
$qb->createNamedParameter(new DateTime('now'), IQueryBuilder::PARAM_DATE)
);
$dt = new DateTime('now');
$qb->setValue('last_update', $qb->createNamedParameter($dt, IQueryBuilder::PARAM_DATE));
$qb->setValue('creation', $qb->createNamedParameter($dt, IQueryBuilder::PARAM_DATE));
} catch (Exception $e) {
}
@ -131,7 +130,7 @@ class ClientRequest extends ClientRequestBuilder {
* @param string $clientId
*
* @return SocialClient
* @throws ClientDoesNotExistException
* @throws ClientNotFoundException
*/
public function getFromClientId(string $clientId): SocialClient {
$qb = $this->getClientSelectSql();
@ -145,7 +144,7 @@ class ClientRequest extends ClientRequestBuilder {
* @param string $token
*
* @return SocialClient
* @throws ClientDoesNotExistException
* @throws ClientNotFoundException
*/
public function getFromToken(string $token): SocialClient {
$qb = $this->getClientSelectSql();

Wyświetl plik

@ -34,7 +34,7 @@ namespace OCA\Social\Db;
use daita\MySmallPhpTools\Exceptions\RowNotFoundException;
use daita\MySmallPhpTools\Traits\TArrayTools;
use Exception;
use OCA\Social\Exceptions\ClientDoesNotExistException;
use OCA\Social\Exceptions\ClientNotFoundException;
use OCA\Social\Model\Client\SocialClient;
@ -115,14 +115,14 @@ class ClientRequestBuilder extends CoreRequestBuilder {
* @param SocialQueryBuilder $qb
*
* @return SocialClient
* @throws ClientDoesNotExistException
* @throws ClientNotFoundException
*/
public function getClientFromRequest(SocialQueryBuilder $qb): SocialClient {
/** @var SocialClient $result */
try {
$result = $qb->getRow([$this, 'parseClientSelectSql']);
} catch (RowNotFoundException $e) {
throw new ClientDoesNotExistException($e->getMessage());
throw new ClientNotFoundException($e->getMessage());
}
return $result;

Wyświetl plik

@ -33,7 +33,7 @@ namespace OCA\Social\Exceptions;
use Exception;
class ClientDoesNotExistException extends Exception {
class ClientNotFoundException extends Exception {
}

Wyświetl plik

@ -33,8 +33,8 @@ namespace OCA\Social\Service;
use daita\MySmallPhpTools\Traits\TStringTools;
use Exception;
use OCA\Social\Db\ClientRequest;
use OCA\Social\Exceptions\ClientDoesNotExistException;
use OCA\Social\Exceptions\ClientException;
use OCA\Social\Exceptions\ClientNotFoundException;
use OCA\Social\Model\Client\SocialClient;
@ -122,7 +122,7 @@ class ClientService {
* @param string $clientId
*
* @return SocialClient
* @throws ClientDoesNotExistException
* @throws ClientNotFoundException
*/
public function getFromClientId(string $clientId): SocialClient {
return $this->clientRequest->getFromClientId($clientId);
@ -131,12 +131,11 @@ class ClientService {
/**
* @param string $token
* @param bool $refresh
*
* @return SocialClient
* @throws ClientDoesNotExistException
* @throws ClientNotFoundException
*/
public function getFromToken(string $token, bool $refresh = true): SocialClient {
public function getFromToken(string $token): SocialClient {
$client = $this->clientRequest->getFromToken($token);
if ($client->getLastUpdate() + self::TIME_TOKEN_TTL < time()) {
@ -145,11 +144,10 @@ class ClientService {
} catch (Exception $e) {
}
throw new ClientDoesNotExistException();
throw new ClientNotFoundException();
}
if ($client->getLastUpdate() + self::TIME_TOKEN_REFRESH > time()) {
$this->miscService->log('__updating ' . $client->getLastUpdate());
$this->clientRequest->updateTime($client);
}

Wyświetl plik

@ -1,91 +0,0 @@
{
"id": "104790603799482162",
"created_at": "2020-09-01T16:28:39.000Z",
"in_reply_to_id": null,
"in_reply_to_account_id": null,
"sensitive": false,
"spoiler_text": "",
"visibility": "unlisted",
"language": "en",
"uri": "https://mastodon.xyz/users/nextcloud/statuses/104790603813976407",
"url": "https://mastodon.xyz/@nextcloud/104790603813976407",
"replies_count": 0,
"reblogs_count": 2,
"favourites_count": 0,
"favourited": false,
"reblogged": false,
"muted": false,
"bookmarked": false,
"content": "\u003cp\u003eDid you know there's an experimental \u003ca href=\"https://mastodon.xyz/tags/Nextcloud\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"\u003e#\u003cspan\u003eNextcloud\u003c/span\u003e\u003c/a\u003e app that lets you block logins from specific countries or geographic regions? Check out Geoblocker if that is something you could use!\u003cbr\u003e\u003ca href=\"https://apps.nextcloud.com/apps/geoblocker\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"\u003e\u003cspan class=\"invisible\"\u003ehttps://\u003c/span\u003e\u003cspan class=\"ellipsis\"\u003eapps.nextcloud.com/apps/geoblo\u003c/span\u003e\u003cspan class=\"invisible\"\u003ecker\u003c/span\u003e\u003c/a\u003e\u003c/p\u003e",
"reblog": null,
"account": {
"id": "126222",
"username": "nextcloud",
"acct": "nextcloud@mastodon.xyz",
"display_name": "Nextcloud 📱☁️💻",
"locked": false,
"bot": false,
"discoverable": false,
"group": false,
"created_at": "2017-05-02T09:56:41.951Z",
"note": "\u003cp\u003eA safe home for all your data, community-driven \u0026amp; open source!\u003cbr\u003e\u003ca href=\"https://nextcloud.com\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"\u003e\u003cspan class=\"invisible\"\u003ehttps://\u003c/span\u003e\u003cspan class=\"\"\u003enextcloud.com\u003c/span\u003e\u003cspan class=\"invisible\"\u003e\u003c/span\u003e\u003c/a\u003e\u003cbr\u003eJoin us at \u003ca href=\"https://help.nextcloud.com\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"\u003e\u003cspan class=\"invisible\"\u003ehttps://\u003c/span\u003e\u003cspan class=\"\"\u003ehelp.nextcloud.com\u003c/span\u003e\u003cspan class=\"invisible\"\u003e\u003c/span\u003e\u003c/a\u003e and \u003ca href=\"https://github.com/nextcloud\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"\u003e\u003cspan class=\"invisible\"\u003ehttps://\u003c/span\u003e\u003cspan class=\"\"\u003egithub.com/nextcloud\u003c/span\u003e\u003cspan class=\"invisible\"\u003e\u003c/span\u003e\u003c/a\u003e 😊\u003c/p\u003e",
"url": "https://mastodon.xyz/@nextcloud",
"avatar": "https://files.mastodon.social/accounts/avatars/000/126/222/original/50785214e44d10cc.jpeg",
"avatar_static": "https://files.mastodon.social/accounts/avatars/000/126/222/original/50785214e44d10cc.jpeg",
"header": "https://files.mastodon.social/accounts/headers/000/126/222/original/6d7b41fdd92cfd6f.jpeg",
"header_static": "https://files.mastodon.social/accounts/headers/000/126/222/original/6d7b41fdd92cfd6f.jpeg",
"followers_count": 9525,
"following_count": 131,
"statuses_count": 3036,
"last_status_at": "2020-09-01",
"emojis": [],
"fields": [
{
"name": "💻 Website",
"value": "\u003ca href=\"https://nextcloud.com\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"\u003e\u003cspan class=\"invisible\"\u003ehttps://\u003c/span\u003e\u003cspan class=\"\"\u003enextcloud.com\u003c/span\u003e\u003cspan class=\"invisible\"\u003e\u003c/span\u003e\u003c/a\u003e",
"verified_at": null
},
{
"name": "😍 Contribute",
"value": "\u003ca href=\"https://nextcloud.com/contribute\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"\u003e\u003cspan class=\"invisible\"\u003ehttps://\u003c/span\u003e\u003cspan class=\"\"\u003enextcloud.com/contribute\u003c/span\u003e\u003cspan class=\"invisible\"\u003e\u003c/span\u003e\u003c/a\u003e",
"verified_at": null
},
{
"name": "🌈 Include initiative",
"value": "\u003ca href=\"https://nextcloud.com/include\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"\u003e\u003cspan class=\"invisible\"\u003ehttps://\u003c/span\u003e\u003cspan class=\"\"\u003enextcloud.com/include\u003c/span\u003e\u003cspan class=\"invisible\"\u003e\u003c/span\u003e\u003c/a\u003e",
"verified_at": null
},
{
"name": "💬 Forum",
"value": "\u003ca href=\"https://help.nextcloud.com\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"\u003e\u003cspan class=\"invisible\"\u003ehttps://\u003c/span\u003e\u003cspan class=\"\"\u003ehelp.nextcloud.com\u003c/span\u003e\u003cspan class=\"invisible\"\u003e\u003c/span\u003e\u003c/a\u003e",
"verified_at": null
}
]
},
"media_attachments": [],
"mentions": [],
"tags": [
{
"name": "nextcloud",
"url": "https://mastodon.social/tags/nextcloud"
}
],
"emojis": [],
"card": {
"url": "https://apps.nextcloud.com/apps/geoblocker",
"title": "GeoBlocker - Apps - App Store - Nextcloud",
"description": "The Nextcloud App Store - Upload your apps and install new apps onto your Nextcloud",
"type": "link",
"author_name": "",
"author_url": "",
"provider_name": "",
"provider_url": "",
"html": "",
"width": 0,
"height": 0,
"image": null,
"embed_url": "",
"blurhash": null
},
"poll": null
}