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); $post = $this->postService->getByName($postName);
$options = new \StdClass; $customFileName = sprintf('%s_%s.%s',
$options->customFileName = sprintf('%s_%s.%s',
$this->config->basic->serviceName, $this->config->basic->serviceName,
$post->getName(), $post->getName(),
strtolower(MimeHelper::getExtension($post->getContentMimeType()))); 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) public function getPostThumbnail($postName, $size)

View file

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