Added opt-in thumbnail proxying in upload

Rationale: some services thought that images linked from /posts/upload
are hotlinked. This is because they were receiving referrer set to a
host that is unknown for them. By using proxying, referrer is blank,
which increases thumbnail coverage at the expense of increased
server-side traffic.
This commit is contained in:
Marcin Kurczewski 2014-06-20 18:03:13 +02:00
parent da9765c352
commit 3b5839031e
4 changed files with 31 additions and 1 deletions

View file

@ -19,6 +19,7 @@ title = "szurubooru"
[misc]
featuredPostMaxDays=7
proxyThumbsInUpload=0
debugQueries=0
githubLink = http://github.com/rr-/szurubooru

View file

@ -189,7 +189,7 @@ $(function()
{
$(img)
.css('background-image', 'none')
.attr('src', url)
.attr('src', '/posts/upload/thumb/' + btoa(url))
.data('custom-thumb', true);
}

View file

@ -143,6 +143,34 @@ class PostController extends AbstractController
$this->redirectToPostList();
}
public function uploadThumbnailView($url)
{
$url = base64_decode($url);
if (!Core::getConfig()->misc->proxyThumbsInUpload)
{
$this->redirect($url);
return;
}
$tmpPath = tempnam(sys_get_temp_dir(), 'thumb4upload');
try
{
TransferHelper::download($url, $tmpPath);
$context = Core::getContext();
$context->transport->lastModified = time();
$context->transport->mimeType = mime_content_type($tmpPath);
$context->transport->cacheDaysToLive = 0.5;
$context->transport->fileHash = md5($url);
$context->transport->fileContent = file_get_contents($tmpPath);
$this->renderFile();
}
finally
{
TransferHelper::remove($tmpPath);
}
}
public function editView($identifier)
{
$jobArgs = [];

View file

@ -56,6 +56,7 @@ class Router extends \Chibi\Routing\Router
$this->register(['PostController', 'editAction'], 'POST', '/post/{identifier}/edit', $postValidation);
$this->register(['PostController', 'deleteAction'], null, '/post/{identifier}/delete', $postValidation);
$this->register(['PostController', 'uploadThumbnailView'], 'GET', '/posts/upload/thumb/{url}', ['url' => '.*']);
$this->register(['PostController', 'listView'], 'GET', '/{source}', $postValidation);
$this->register(['PostController', 'listView'], 'GET', '/{source}/{page}', $postValidation);
$this->register(['PostController', 'listView'], 'GET', '/{source}/{query}/{page}', $postValidation);