fix: mastodon, cache tweaks, docs (#3661)

* cache tweaks

* docs

* fix(mastodon): type bug
This commit is contained in:
Dag 2023-09-10 23:35:40 +02:00 committed by GitHub
parent 4b9f6f7e53
commit 3178deb5a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 5 deletions

View File

@ -664,7 +664,7 @@ class ItakuBridge extends BridgeAbstract
// Debug::log($url); // Debug::log($url);
if ($getJSON) { //get JSON object if ($getJSON) { //get JSON object
if ($cache) { if ($cache) {
$data = $this->loadCacheValue($url, 86400); // 24 hours $data = $this->loadCacheValue($url);
if (is_null($data)) { if (is_null($data)) {
$data = getContents($url, $httpHeaders, $curlOptions) or returnServerError("Could not load $url"); $data = getContents($url, $httpHeaders, $curlOptions) or returnServerError("Could not load $url");
$this->saveCacheValue($url, $data); $this->saveCacheValue($url, $data);

View File

@ -100,6 +100,10 @@ class MastodonBridge extends BridgeAbstract
// We fetch the boosted content. // We fetch the boosted content.
try { try {
$rtContent = $this->fetchAP($content['object']); $rtContent = $this->fetchAP($content['object']);
if (!$rtContent) {
// Sometimes fetchAP returns null. Someone should figure out why. json_decode failure?
break;
}
$rtUser = $this->loadCacheValue($rtContent['attributedTo']); $rtUser = $this->loadCacheValue($rtContent['attributedTo']);
if (!isset($rtUser)) { if (!isset($rtUser)) {
// We fetch the author, since we cannot always assume the format of the URL. // We fetch the author, since we cannot always assume the format of the URL.
@ -277,6 +281,10 @@ class MastodonBridge extends BridgeAbstract
array_push($headers, $sig); array_push($headers, $sig);
} }
} }
return json_decode(getContents($url, $headers), true); try {
return Json::decode(getContents($url, $headers));
} catch (\JsonException $e) {
return null;
}
} }
} }

View File

@ -353,10 +353,12 @@ class PixivBridge extends BridgeAbstract
private function getCookie() private function getCookie()
{ {
// checks if cookie is set, if not initialise it with the cookie from the config // checks if cookie is set, if not initialise it with the cookie from the config
$value = $this->loadCacheValue('cookie', 2678400 /* 30 days + 1 day to let cookie chance to renew */); $value = $this->loadCacheValue('cookie');
if (!isset($value)) { if (!isset($value)) {
$value = $this->getOption('cookie'); $value = $this->getOption('cookie');
$this->saveCacheValue('cookie', $this->getOption('cookie'));
// 30 days + 1 day to let cookie chance to renew
$this->saveCacheValue('cookie', $this->getOption('cookie'), 2678400);
} }
return $value; return $value;
} }
@ -370,7 +372,7 @@ class PixivBridge extends BridgeAbstract
} }
if ($cache) { if ($cache) {
$data = $this->loadCacheValue($url, 86400); // 24 hours $data = $this->loadCacheValue($url);
if (!$data) { if (!$data) {
$data = getContents($url, $httpHeaders, $curlOptions, true) or returnServerError("Could not load $url"); $data = getContents($url, $httpHeaders, $curlOptions, true) or returnServerError("Could not load $url");
$this->saveCacheValue($url, $data); $this->saveCacheValue($url, $data);

View File

@ -2,6 +2,10 @@
declare(strict_types=1); declare(strict_types=1);
/**
* The storage table has a column `updated` which is incorrectly named.
* It should have been named `expiration` and the code treats it as an expiration date (in unix timestamp)
*/
class SQLiteCache implements CacheInterface class SQLiteCache implements CacheInterface
{ {
private \SQLite3 $db; private \SQLite3 $db;