mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2025-10-05 18:34:20 +02:00
refactor: added AbstractProxy base class for shortener proxies
This commit is contained in:
parent
714e455479
commit
4a39a2ad0f
12 changed files with 221 additions and 216 deletions
|
@ -149,10 +149,10 @@ class Controller
|
|||
$this->_jsonld($this->_request->getParam('jsonld'));
|
||||
return;
|
||||
case 'yourlsproxy':
|
||||
$this->_yourlsproxy($this->_request->getParam('link'));
|
||||
$this->_shortenerproxy($this->_request->getParam('link'), YourlsProxy::class);
|
||||
break;
|
||||
case 'shlinkproxy':
|
||||
$this->_shlinkproxy($this->_request->getParam('link'));
|
||||
$this->_shortenerproxy($this->_request->getParam('link'), ShlinkProxy::class);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -454,12 +454,12 @@ class Controller
|
|||
$page->assign('NAME', $this->_conf->getKey('name'));
|
||||
if ($this->_request->getOperation() === 'yourlsproxy') {
|
||||
$page->assign('SHORTURL', $this->_status);
|
||||
$page->draw('yourlsproxy');
|
||||
$page->draw('shortenerproxy');
|
||||
return;
|
||||
}
|
||||
if ($this->_request->getOperation() === 'shlinkproxy') {
|
||||
$page->assign('SHORTURL', $this->_status);
|
||||
$page->draw('shlinkproxy');
|
||||
$page->draw('shortenerproxy');
|
||||
return;
|
||||
}
|
||||
$page->assign('BASEPATH', I18n::_($this->_conf->getKey('basepath')));
|
||||
|
@ -536,34 +536,23 @@ class Controller
|
|||
}
|
||||
|
||||
/**
|
||||
* proxies link to YOURLS, updates status or error with response
|
||||
* Proxies a link using the specified proxy class, and updates the status or error with the response.
|
||||
*
|
||||
* @access private
|
||||
* @param string $link
|
||||
* @param string $link The link to be proxied.
|
||||
* @param string $proxyClass The fully qualified class name of the proxy to use.
|
||||
*/
|
||||
private function _yourlsproxy($link)
|
||||
private function _shortenerproxy($link, $proxyClass)
|
||||
{
|
||||
$yourls = new YourlsProxy($this->_conf, $link);
|
||||
if ($yourls->isError()) {
|
||||
$this->_error = $yourls->getError();
|
||||
} else {
|
||||
$this->_status = $yourls->getUrl();
|
||||
if (!is_subclass_of($proxyClass, AbstractProxy::class)) {
|
||||
$this->_error = 'Invalid proxy class.';
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* proxies link to SHLINK, updates status or error with response
|
||||
*
|
||||
* @access private
|
||||
* @param string $link
|
||||
*/
|
||||
private function _shlinkproxy($link)
|
||||
{
|
||||
$shlink = new ShlinkProxy($this->_conf, $link);
|
||||
if ($shlink->isError()) {
|
||||
$this->_error = $shlink->getError();
|
||||
$proxy = new $proxyClass($this->_conf, $link);
|
||||
if ($proxy->isError()) {
|
||||
$this->_error = $proxy->getError();
|
||||
} else {
|
||||
$this->_status = $shlink->getUrl();
|
||||
$this->_status = $proxy->getUrl();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue