mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2026-07-17 16:39:40 +00:00
When YOURLS replies with statusCode 200 but no "shorturl" field, YourlsProxy::_extractShortUrl() returned int 0 for its ?string return type. Under the file's declare(strict_types=1) this raises an uncaught TypeError, aborting paste creation instead of surfacing the intended "Error parsing proxy response" message. Fall back to null (matching ShlinkProxy) so the existing graceful error path is taken. Co-Authored-By: Claude <noreply@anthropic.com>
73 lines
1.9 KiB
PHP
73 lines
1.9 KiB
PHP
<?php declare(strict_types=1);
|
|
/**
|
|
* PrivateBin
|
|
*
|
|
* a zero-knowledge paste bin
|
|
*
|
|
* @link https://github.com/PrivateBin/PrivateBin
|
|
* @copyright 2012 Sébastien SAUVAGE (sebsauvage.net)
|
|
* @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
|
|
*/
|
|
|
|
namespace PrivateBin\Proxy;
|
|
|
|
use PrivateBin\Configuration;
|
|
|
|
/**
|
|
* YourlsProxy
|
|
*
|
|
* Forwards a URL for shortening to YOURLS (your own URL shortener) and stores
|
|
* the result.
|
|
*/
|
|
class YourlsProxy extends AbstractProxy
|
|
{
|
|
/**
|
|
* Overrides the abstract parent function to get the proxy URL.
|
|
*
|
|
* @param Configuration $conf
|
|
* @return string
|
|
*/
|
|
protected function _getProxyUrl(Configuration $conf): string
|
|
{
|
|
return $conf->getKey('apiurl', 'yourls');
|
|
}
|
|
|
|
/**
|
|
* Overrides the abstract parent function to get contents from YOURLS API.
|
|
*
|
|
* @access protected
|
|
* @param Configuration $conf
|
|
* @param string $link
|
|
* @return array
|
|
*/
|
|
protected function _getProxyPayload(Configuration $conf, string $link): array
|
|
{
|
|
return array(
|
|
'method' => 'POST',
|
|
'header' => "Content-Type: application/x-www-form-urlencoded\r\n",
|
|
'content' => http_build_query(
|
|
array(
|
|
'signature' => $conf->getKey('signature', 'yourls'),
|
|
'format' => 'json',
|
|
'action' => 'shorturl',
|
|
'url' => $link,
|
|
)
|
|
),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Extracts the short URL from the YOURLS API response.
|
|
*
|
|
* @access protected
|
|
* @param array $data
|
|
* @return ?string
|
|
*/
|
|
protected function _extractShortUrl(array $data): ?string
|
|
{
|
|
if ((int) ($data['statusCode'] ?? 0) === 200) {
|
|
return $data['shorturl'] ?? null;
|
|
}
|
|
return null;
|
|
}
|
|
}
|