1
0
mirror of https://github.com/RSS-Bridge/rss-bridge.git synced 2025-08-05 08:07:33 +02:00

[FurAffinityBridge] Option for instance host to add custom cookie (#3638)

* added custom cookie config

* appease phpunit
This commit is contained in:
mruac
2023-08-30 00:35:37 +09:30
committed by GitHub
parent 9e33a15b93
commit f0ec797f4b

View File

@@ -6,7 +6,18 @@ class FurAffinityBridge extends BridgeAbstract
const URI = 'https://www.furaffinity.net'; const URI = 'https://www.furaffinity.net';
const CACHE_TIMEOUT = 300; // 5min const CACHE_TIMEOUT = 300; // 5min
const DESCRIPTION = 'Returns posts from various sections of FurAffinity'; const DESCRIPTION = 'Returns posts from various sections of FurAffinity';
const MAINTAINER = 'Roliga'; const MAINTAINER = 'Roliga, mruac';
const CONFIGURATION = [
'aCookie' => [
'required' => false,
'defaultValue' => 'ca6e4566-9d81-4263-9444-653b142e35f8'
],
'bCookie' => [
'required' => false,
'defaultValue' => '4ce65691-b50f-4742-a990-bf28d6de16ee'
]
];
const PARAMETERS = [ const PARAMETERS = [
'Search' => [ 'Search' => [
'q' => [ 'q' => [
@@ -594,7 +605,7 @@ class FurAffinityBridge extends BridgeAbstract
* This was aquired by creating a new user on FA then * This was aquired by creating a new user on FA then
* extracting the cookie from the browsers dev console. * extracting the cookie from the browsers dev console.
*/ */
const FA_AUTH_COOKIE = 'b=4ce65691-b50f-4742-a990-bf28d6de16ee; a=ca6e4566-9d81-4263-9444-653b142e35f8'; private $FA_AUTH_COOKIE;
public function detectParameters($url) public function detectParameters($url)
{ {
@@ -662,7 +673,14 @@ class FurAffinityBridge extends BridgeAbstract
. '\'s Folder ' . '\'s Folder '
. $this->getInput('folder-id'); . $this->getInput('folder-id');
default: default:
return parent::getName(); $name = parent::getName();
if ($this->getOption('aCookie') !== null) {
$username = $this->loadCacheValue('username');
if ($username !== null) {
$name = $username . '\'s ' . parent::getName();
}
}
return $name;
} }
} }
@@ -741,6 +759,7 @@ class FurAffinityBridge extends BridgeAbstract
public function collectData() public function collectData()
{ {
$this->FA_AUTH_COOKIE = 'b=' . $this->getOption('bCookie') . '; a=' . $this->getOption('aCookie');
switch ($this->queriedContext) { switch ($this->queriedContext) {
case 'Search': case 'Search':
$data = [ $data = [
@@ -806,19 +825,19 @@ class FurAffinityBridge extends BridgeAbstract
$header = [ $header = [
'Host: ' . parse_url(self::URI, PHP_URL_HOST), 'Host: ' . parse_url(self::URI, PHP_URL_HOST),
'Content-Type: application/x-www-form-urlencoded', 'Content-Type: application/x-www-form-urlencoded',
'Cookie: ' . self::FA_AUTH_COOKIE 'Cookie: ' . $this->FA_AUTH_COOKIE
]; ];
$html = getSimpleHTMLDOM($this->getURI(), $header, $opts); $html = getSimpleHTMLDOM($this->getURI(), $header, $opts);
$html = defaultLinkTo($html, $this->getURI()); $html = defaultLinkTo($html, $this->getURI());
$this->saveLoggedInUser($html);
return $html; return $html;
} }
private function getFASimpleHTMLDOM($url, $cache = false) private function getFASimpleHTMLDOM($url, $cache = false)
{ {
$header = [ $header = [
'Cookie: ' . self::FA_AUTH_COOKIE 'Cookie: ' . $this->FA_AUTH_COOKIE
]; ];
if ($cache) { if ($cache) {
@@ -826,12 +845,24 @@ class FurAffinityBridge extends BridgeAbstract
} else { } else {
$html = getSimpleHTMLDOM($url, $header); $html = getSimpleHTMLDOM($url, $header);
} }
$this->saveLoggedInUser($html);
$html = defaultLinkTo($html, $url); $html = defaultLinkTo($html, $url);
return $html; return $html;
} }
private function saveLoggedInUser($html)
{
$current_user = $html->find('#my-username', 0);
if ($current_user !== null) {
preg_match('/^(?:My FA \( |~)(.*?)(?: \)|)$/', trim($current_user->plaintext), $matches);
$current_user = $current_user ? $matches[1] : null;
if ($current_user !== null) {
$this->saveCacheValue('username', $current_user);
}
}
}
private function itemsFromJournalList($html, $limit) private function itemsFromJournalList($html, $limit)
{ {
foreach ($html->find('table[id^=jid:]') as $journal) { foreach ($html->find('table[id^=jid:]') as $journal) {