mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-01-16 13:50:01 +01:00
fix: small tweaks (#4057)
This commit is contained in:
parent
3cba984d22
commit
001dd47439
@ -64,6 +64,7 @@ TEXT;
|
||||
$this->collectExpandableDatas($feed);
|
||||
} catch (HttpException $e) {
|
||||
$this->logger->warning(sprintf('Exception in FeedMergeBridge: %s', create_sane_exception_message($e)));
|
||||
// This feed item might be spammy. Considering dropping it.
|
||||
$this->items[] = [
|
||||
'title' => 'RSS-Bridge: ' . $e->getMessage(),
|
||||
// Give current time so it sorts to the top
|
||||
@ -71,7 +72,7 @@ TEXT;
|
||||
];
|
||||
continue;
|
||||
} catch (\Exception $e) {
|
||||
if (str_starts_with($e->getMessage(), 'Unable to parse xml')) {
|
||||
if (str_starts_with($e->getMessage(), 'Failed to parse xml')) {
|
||||
// Allow this particular exception from FeedExpander
|
||||
$this->logger->warning(sprintf('Exception in FeedMergeBridge: %s', create_sane_exception_message($e)));
|
||||
continue;
|
||||
@ -83,6 +84,8 @@ TEXT;
|
||||
}
|
||||
}
|
||||
|
||||
// If $this->items is empty we should consider throw exception here
|
||||
|
||||
// Sort by timestamp descending
|
||||
usort($this->items, function ($a, $b) {
|
||||
$t1 = $a['timestamp'] ?? $a['uri'] ?? $a['title'];
|
||||
|
@ -21,6 +21,10 @@ class GatesNotesBridge extends BridgeAbstract
|
||||
|
||||
$rawContent = getContents($apiUrl);
|
||||
$cleanedContent = trim($rawContent, '"');
|
||||
$cleanedContent = str_replace([
|
||||
'<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">',
|
||||
'</string>'
|
||||
], '', $cleanedContent);
|
||||
$cleanedContent = str_replace('\r\n', "\n", $cleanedContent);
|
||||
$cleanedContent = stripslashes($cleanedContent);
|
||||
|
||||
|
@ -160,7 +160,8 @@ class PixivBridge extends BridgeAbstract
|
||||
$json = array_reduce($json, function ($acc, $i) {
|
||||
if ($i['illustType'] === 0) {
|
||||
$acc[] = $i;
|
||||
}return $acc;
|
||||
}
|
||||
return $acc;
|
||||
}, []);
|
||||
break;
|
||||
case 'manga':
|
||||
@ -235,8 +236,10 @@ class PixivBridge extends BridgeAbstract
|
||||
|
||||
$item = [];
|
||||
$item['uid'] = $result['id'];
|
||||
|
||||
$subpath = array_key_exists('illustType', $result) ? 'artworks/' : 'novel/show.php?id=';
|
||||
$item['uri'] = static::URI . $subpath . $result['id'];
|
||||
|
||||
$item['title'] = $result['title'];
|
||||
$item['author'] = $result['userName'];
|
||||
$item['timestamp'] = $result['updateDate'];
|
||||
@ -253,8 +256,6 @@ class PixivBridge extends BridgeAbstract
|
||||
}
|
||||
} else {
|
||||
$img_url = $result['url'];
|
||||
// Temporarily disabling caching of the image
|
||||
//$img_url = $this->cacheImage($result['url'], $result['id'], array_key_exists('illustType', $result));
|
||||
}
|
||||
|
||||
// Currently, this might result in broken image due to their strict referrer check
|
||||
@ -271,46 +272,6 @@ class PixivBridge extends BridgeAbstract
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* todo: remove manual file cache
|
||||
* See bridge specific documentation for alternative option.
|
||||
*/
|
||||
private function cacheImage($url, $illustId, $isImage)
|
||||
{
|
||||
$illustId = preg_replace('/[^0-9]/', '', $illustId);
|
||||
$thumbnailurl = $url;
|
||||
|
||||
$path = PATH_CACHE . 'pixiv_img/';
|
||||
if (!is_dir($path)) {
|
||||
mkdir($path, 0755, true);
|
||||
}
|
||||
|
||||
$path .= $illustId;
|
||||
if ($this->getInput('fullsize')) {
|
||||
$path .= '_fullsize';
|
||||
}
|
||||
$path .= '.jpg';
|
||||
|
||||
if (!is_file($path)) {
|
||||
// Get fullsize URL
|
||||
if ($isImage && $this->getInput('fullsize')) {
|
||||
$ajax_uri = static::URI . 'ajax/illust/' . $illustId;
|
||||
$imagejson = $this->getData($ajax_uri, true, true);
|
||||
$url = $imagejson['body']['urls']['original'];
|
||||
}
|
||||
|
||||
$headers = ['Referer: ' . static::URI];
|
||||
try {
|
||||
$illust = $this->getData($url, true, false, $headers);
|
||||
} catch (Exception $e) {
|
||||
$illust = $this->getData($thumbnailurl, true, false, $headers); // Original thumbnail
|
||||
}
|
||||
file_put_contents($path, $illust);
|
||||
}
|
||||
|
||||
return get_home_page_url() . 'cache/pixiv_img/' . preg_replace('/.*\//', '', $path);
|
||||
}
|
||||
|
||||
private function checkOptions()
|
||||
{
|
||||
$proxy = $this->getOption('proxy_url');
|
||||
|
@ -34,6 +34,7 @@ abstract class FeedExpander extends BridgeAbstract
|
||||
try {
|
||||
$this->feed = $feedParser->parseFeed($xmlString);
|
||||
} catch (\Exception $e) {
|
||||
// FeedMergeBridge relies on this string
|
||||
throw new \Exception(sprintf('Failed to parse xml from %s: %s', $url, create_sane_exception_message($e)));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user