send header on documentGet

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/626/head
Maxence Lange 2019-07-20 17:19:59 -01:00
rodzic eadc04fc61
commit 2f54495805
4 zmienionych plików z 23 dodań i 14 usunięć

Wyświetl plik

@ -701,9 +701,10 @@ class LocalController extends Controller {
$actor = $this->cacheActorService->getFromId($id); $actor = $this->cacheActorService->getFromId($id);
if ($actor->gotIcon()) { if ($actor->gotIcon()) {
$avatar = $actor->getIcon(); $avatar = $actor->getIcon();
$document = $this->documentService->getFromCache($avatar->getId()); $document = $this->documentService->getFromCache($avatar->getId(), $mime);
$response = new FileDisplayResponse($document); $response =
new FileDisplayResponse($document, Http::STATUS_OK, ['Content-Type' => $mime]);
$response->cacheFor(86400); $response->cacheFor(86400);
return $response; return $response;

Wyświetl plik

@ -291,9 +291,11 @@ class NavigationController extends Controller {
*/ */
public function documentGet(string $id): Response { public function documentGet(string $id): Response {
try { try {
$file = $this->documentService->getFromCache($id); $mime = '';
$file = $this->documentService->getFromCache($id, $mime);
return new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => $mime]);
return new FileDisplayResponse($file, Http::STATUS_OK);
} catch (Exception $e) { } catch (Exception $e) {
return $this->fail($e); return $this->fail($e);
} }
@ -311,9 +313,10 @@ class NavigationController extends Controller {
public function documentGetPublic(string $id): Response { public function documentGetPublic(string $id): Response {
try { try {
$file = $this->documentService->getFromCache($id, true); $mime = '';
$file = $this->documentService->getFromCache($id, $mime, true);
return new FileDisplayResponse($file); return new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => $mime]);
} catch (Exception $e) { } catch (Exception $e) {
return $this->fail($e); return $this->fail($e);
} }
@ -331,9 +334,10 @@ class NavigationController extends Controller {
public function resizedGet(string $id): Response { public function resizedGet(string $id): Response {
try { try {
$file = $this->documentService->getResizedFromCache($id); $mime = '';
$file = $this->documentService->getResizedFromCache($id, $mime);
return new FileDisplayResponse($file); return new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => $mime]);
} catch (Exception $e) { } catch (Exception $e) {
return $this->fail($e); return $this->fail($e);
} }
@ -351,12 +355,14 @@ class NavigationController extends Controller {
public function resizedGetPublic(string $id): Response { public function resizedGetPublic(string $id): Response {
try { try {
$file = $this->documentService->getResizedFromCache($id, true); $mime = '';
$file = $this->documentService->getResizedFromCache($id, $mime, true);
return new FileDisplayResponse($file); return new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => $mime]);
} catch (Exception $e) { } catch (Exception $e) {
return $this->fail($e); return $this->fail($e);
} }
} }
} }

Wyświetl plik

@ -61,8 +61,8 @@ class CacheDocumentService {
use TStringTools; use TStringTools;
const RESIZED_HEIGHT = 250; const RESIZED_WIDTH = 280;
const RESIZED_WIDTH = 350; const RESIZED_HEIGHT = 180;
/** @var IAppData */ /** @var IAppData */
private $appData; private $appData;

Wyświetl plik

@ -190,6 +190,7 @@ class DocumentService {
/** /**
* @param string $id * @param string $id
* @param string $mime
* @param bool $public * @param bool $public
* *
* @return ISimpleFile * @return ISimpleFile
@ -199,8 +200,9 @@ class DocumentService {
* @throws RequestResultNotJsonException * @throws RequestResultNotJsonException
* @throws SocialAppConfigException * @throws SocialAppConfigException
*/ */
public function getResizedFromCache(string $id, bool $public = false) { public function getResizedFromCache(string $id, string &$mime = '', bool $public = false) {
$document = $this->cacheRemoteDocument($id, $public); $document = $this->cacheRemoteDocument($id, $public);
$mime = $document->getMimeType();
return $this->cacheService->getContentFromCache($document->getResizedCopy()); return $this->cacheService->getContentFromCache($document->getResizedCopy());
} }
@ -218,7 +220,7 @@ class DocumentService {
* @throws RequestResultNotJsonException * @throws RequestResultNotJsonException
* @throws SocialAppConfigException * @throws SocialAppConfigException
*/ */
public function getFromCache(string $id, bool $public = false, string &$mimeType = '') { public function getFromCache(string $id, string &$mimeType = '', bool $public = false) {
$document = $this->cacheRemoteDocument($id, $public); $document = $this->cacheRemoteDocument($id, $public);
$mimeType = $document->getMimeType(); $mimeType = $document->getMimeType();