Fixed NetworkingService not using MimeHelper

This commit is contained in:
Marcin Kurczewski 2014-10-25 21:30:01 +02:00
parent 6ebd1e56ee
commit 5124733ee6
2 changed files with 8 additions and 16 deletions

View file

@ -40,13 +40,12 @@ final class PostContentController extends AbstractController
{
$post = $this->postService->getByName($postName);
$options = new \StdClass;
$options->customFileName = sprintf('%s_%s.%s',
$customFileName = sprintf('%s_%s.%s',
$this->config->basic->serviceName,
$post->getName(),
strtolower(MimeHelper::getExtension($post->getContentMimeType())));
$this->networkingService->serveFile($this->fileDao->getFullPath($post->getContentPath()), $options);
$this->networkingService->serveFile($this->fileDao->getFullPath($post->getContentPath()), $customFileName);
}
public function getPostThumbnail($postName, $size)

View file

@ -1,5 +1,6 @@
<?php
namespace Szurubooru\Services;
use Szurubooru\Helpers\MimeHelper;
use Szurubooru\Helpers\HttpHelper;
class NetworkingService
@ -11,12 +12,9 @@ class NetworkingService
$this->httpHelper = $httpHelper;
}
public function serveFile($fullPath, $options = [])
public function serveFile($fullPath, $customFileName = null)
{
$daysToLive = isset($options->daysToLive)
? $options->daysToLive
: 7;
$daysToLive = 7;
$secondsToLive = $daysToLive * 24 * 60 * 60;
$lastModified = filemtime($fullPath);
$eTag = md5($fullPath . $lastModified);
@ -34,15 +32,10 @@ class NetworkingService
$this->httpHelper->setHeader('Pragma', 'public');
$this->httpHelper->setHeader('Cache-Control', 'public, max-age=' . $secondsToLive);
$this->httpHelper->setHeader('Expires', gmdate('D, d M Y H:i:s \G\M\T', time() + $secondsToLive));
$this->httpHelper->setHeader( 'Content-Type', MimeHelper::getMimeTypeFromFile($fullPath));
if (isset($options->customFileName))
$this->httpHelper->setHeader('Content-Disposition', 'inline; filename="' . $options->customFileName . '"');
$this->httpHelper->setHeader(
'Content-Type',
isset($options->mimeType)
? $options->mimeType
: mime_content_type($fullPath));
if ($customFileName)
$this->httpHelper->setHeader('Content-Disposition', 'inline; filename="' . $customFileName . '"');
if (strtotime($ifModifiedSince) === $lastModified or $eTagHeader === $eTag)
{