[TwitterBridge] Continue using existing guesttoken from cache, when requesting a new one failed (#2396)

This commit is contained in:
arnd-s 2022-01-06 06:59:37 +01:00 committed by GitHub
parent 8530aa54f2
commit 12ff697ab0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -546,8 +546,16 @@ EOD;
if($guestTokenUses === null || !is_array($guestTokenUses) || count($guestTokenUses) != 2 if($guestTokenUses === null || !is_array($guestTokenUses) || count($guestTokenUses) != 2
|| $guestTokenUses[0] <= 0 || (time() - $refresh) > self::GUEST_TOKEN_EXPIRY) { || $guestTokenUses[0] <= 0 || (time() - $refresh) > self::GUEST_TOKEN_EXPIRY) {
$guestToken = $this->getGuestToken(); $guestToken = $this->getGuestToken();
$gt_cache->saveData(array(self::GUEST_TOKEN_USES, $guestToken)); if ($guestToken === null) {
$r_cache->saveData(time()); if($guestTokenUses === null) {
returnServerError('Could not parse guest token');
} else {
$guestToken = $guestTokenUses[1];
}
} else {
$gt_cache->saveData(array(self::GUEST_TOKEN_USES, $guestToken));
$r_cache->saveData(time());
}
} else { } else {
$guestTokenUses[0] -= 1; $guestTokenUses[0] -= 1;
$gt_cache->saveData($guestTokenUses); $gt_cache->saveData($guestTokenUses);
@ -567,7 +575,7 @@ EOD;
preg_match_all($guestTokenRegex, $pageContent['header'], $guestTokenMatches, PREG_SET_ORDER, 0); preg_match_all($guestTokenRegex, $pageContent['header'], $guestTokenMatches, PREG_SET_ORDER, 0);
if (!$guestTokenMatches) if (!$guestTokenMatches)
preg_match_all($guestTokenRegex, $pageContent['content'], $guestTokenMatches, PREG_SET_ORDER, 0); preg_match_all($guestTokenRegex, $pageContent['content'], $guestTokenMatches, PREG_SET_ORDER, 0);
if (!$guestTokenMatches) returnServerError('Could not parse guest token'); if (!$guestTokenMatches) return null;
$guestToken = $guestTokenMatches[0][1]; $guestToken = $guestTokenMatches[0][1];
return $guestToken; return $guestToken;
} }