mirror of
https://github.com/friendica/friendica
synced 2024-12-31 23:22:19 +00:00
Merge pull request #14608 from annando/atproto
Unneeded line removed / improved status handling
This commit is contained in:
commit
4728d1919f
4 changed files with 30 additions and 8 deletions
|
@ -129,7 +129,17 @@ final class ATProtocol
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $this->get($pds . '/xrpc/' . $url, [HttpClientOptions::HEADERS => $headers]);
|
$data = $this->get($pds . '/xrpc/' . $url, [HttpClientOptions::HEADERS => $headers]);
|
||||||
$this->pConfig->set($uid, 'bluesky', 'status', is_null($data) ? self::STATUS_API_FAIL : self::STATUS_SUCCESS);
|
if (empty($data) || (!empty($data->code) && ($data->code < 200 || $data->code >= 400))) {
|
||||||
|
$this->pConfig->set($uid, 'bluesky', 'status', self::STATUS_API_FAIL);
|
||||||
|
if (!empty($data->message)) {
|
||||||
|
$this->pConfig->set($uid, 'bluesky', 'status-message', $data->message);
|
||||||
|
} elseif (!empty($data->code)) {
|
||||||
|
$this->pConfig->set($uid, 'bluesky', 'status-message', 'Error Code: ' . $data->code);
|
||||||
|
}
|
||||||
|
} elseif (!empty($data)) {
|
||||||
|
$this->pConfig->set($uid, 'bluesky', 'status', self::STATUS_SUCCESS);
|
||||||
|
$this->pConfig->set($uid, 'bluesky', 'status-message', '');
|
||||||
|
}
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,6 +166,9 @@ final class ATProtocol
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$data->code = $curlResult->getReturnCode();
|
$data->code = $curlResult->getReturnCode();
|
||||||
|
} elseif (($curlResult->getReturnCode() < 200) || ($curlResult->getReturnCode() >= 400)) {
|
||||||
|
$this->logger->notice('Unexpected return code', ['url' => $url, 'code' => $curlResult->getReturnCode(), 'error' => $data ?: $curlResult->getBodyString()]);
|
||||||
|
$data->code = $curlResult->getReturnCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
Item::incrementInbound(Protocol::BLUESKY);
|
Item::incrementInbound(Protocol::BLUESKY);
|
||||||
|
@ -198,6 +211,7 @@ final class ATProtocol
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->logger->notice('Exception on post', ['exception' => $e]);
|
$this->logger->notice('Exception on post', ['exception' => $e]);
|
||||||
$this->pConfig->set($uid, 'bluesky', 'status', self::STATUS_API_FAIL);
|
$this->pConfig->set($uid, 'bluesky', 'status', self::STATUS_API_FAIL);
|
||||||
|
$this->pConfig->set($uid, 'bluesky', 'status-message', $e->getMessage());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,6 +220,11 @@ final class ATProtocol
|
||||||
$this->logger->notice('API Error', ['url' => $url, 'code' => $curlResult->getReturnCode(), 'error' => $data ?: $curlResult->getBodyString()]);
|
$this->logger->notice('API Error', ['url' => $url, 'code' => $curlResult->getReturnCode(), 'error' => $data ?: $curlResult->getBodyString()]);
|
||||||
if (!$data) {
|
if (!$data) {
|
||||||
$this->pConfig->set($uid, 'bluesky', 'status', self::STATUS_API_FAIL);
|
$this->pConfig->set($uid, 'bluesky', 'status', self::STATUS_API_FAIL);
|
||||||
|
if (!empty($data->message)) {
|
||||||
|
$this->pConfig->set($uid, 'bluesky', 'status-message', $data->message);
|
||||||
|
} elseif (!empty($data->code)) {
|
||||||
|
$this->pConfig->set($uid, 'bluesky', 'status-message', 'Error Code: ' . $data->code);
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$data->code = $curlResult->getReturnCode();
|
$data->code = $curlResult->getReturnCode();
|
||||||
|
@ -213,8 +232,14 @@ final class ATProtocol
|
||||||
|
|
||||||
if (!empty($data->code) && ($data->code >= 200) && ($data->code < 400)) {
|
if (!empty($data->code) && ($data->code >= 200) && ($data->code < 400)) {
|
||||||
$this->pConfig->set($uid, 'bluesky', 'status', self::STATUS_SUCCESS);
|
$this->pConfig->set($uid, 'bluesky', 'status', self::STATUS_SUCCESS);
|
||||||
|
$this->pConfig->set($uid, 'bluesky', 'status-message', '');
|
||||||
} else {
|
} else {
|
||||||
$this->pConfig->set($uid, 'bluesky', 'status', self::STATUS_API_FAIL);
|
$this->pConfig->set($uid, 'bluesky', 'status', self::STATUS_API_FAIL);
|
||||||
|
if (!empty($data->message)) {
|
||||||
|
$this->pConfig->set($uid, 'bluesky', 'status-message', $data->message);
|
||||||
|
} elseif (!empty($data->code)) {
|
||||||
|
$this->pConfig->set($uid, 'bluesky', 'status-message', 'Error Code: ' . $data->code);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
@ -502,10 +527,6 @@ final class ATProtocol
|
||||||
$data = $this->post($uid, '/xrpc/com.atproto.server.refreshSession', '', ['Authorization' => ['Bearer ' . $token]]);
|
$data = $this->post($uid, '/xrpc/com.atproto.server.refreshSession', '', ['Authorization' => ['Bearer ' . $token]]);
|
||||||
if (empty($data) || empty($data->accessJwt)) {
|
if (empty($data) || empty($data->accessJwt)) {
|
||||||
$this->logger->debug('Refresh failed', ['return' => $data]);
|
$this->logger->debug('Refresh failed', ['return' => $data]);
|
||||||
$password = $this->pConfig->get($uid, 'bluesky', 'password');
|
|
||||||
if (!empty($password)) {
|
|
||||||
return $this->createUserToken($uid, $password);
|
|
||||||
}
|
|
||||||
$this->pConfig->set($uid, 'bluesky', 'status', self::STATUS_TOKEN_FAIL);
|
$this->pConfig->set($uid, 'bluesky', 'status', self::STATUS_TOKEN_FAIL);
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
@ -542,6 +563,7 @@ final class ATProtocol
|
||||||
$this->pConfig->set($uid, 'bluesky', 'refresh_token', $data->refreshJwt);
|
$this->pConfig->set($uid, 'bluesky', 'refresh_token', $data->refreshJwt);
|
||||||
$this->pConfig->set($uid, 'bluesky', 'token_created', time());
|
$this->pConfig->set($uid, 'bluesky', 'token_created', time());
|
||||||
$this->pConfig->set($uid, 'bluesky', 'status', self::STATUS_TOKEN_OK);
|
$this->pConfig->set($uid, 'bluesky', 'status', self::STATUS_TOKEN_OK);
|
||||||
|
$this->pConfig->set($uid, 'bluesky', 'status-message', '');
|
||||||
return $data->accessJwt;
|
return $data->accessJwt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env php
|
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copyright (C) 2010-2024, the Friendica project
|
* Copyright (C) 2010-2024, the Friendica project
|
||||||
* SPDX-FileCopyrightText: 2010-2024 the Friendica project
|
* SPDX-FileCopyrightText: 2010-2024 the Friendica project
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env php
|
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copyright (C) 2010-2024, the Friendica project
|
* Copyright (C) 2010-2024, the Friendica project
|
||||||
* SPDX-FileCopyrightText: 2010-2024 the Friendica project
|
* SPDX-FileCopyrightText: 2010-2024 the Friendica project
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env php
|
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copyright (C) 2010-2024, the Friendica project
|
* Copyright (C) 2010-2024, the Friendica project
|
||||||
* SPDX-FileCopyrightText: 2010-2024 the Friendica project
|
* SPDX-FileCopyrightText: 2010-2024 the Friendica project
|
||||||
|
|
Loading…
Reference in a new issue