Created
November 9, 2016 17:56
-
-
Save gnarula/85641f3747a93582f6ba871fb23ba455 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @NoAdminRequired | |
* @NoCSRFRequired | |
*/ | |
public function cover() { | |
$albumId = $this->getIdFromSlug($this->params('albumIdOrSlug')); | |
$album = $this->albumBusinessLayer->find($albumId, $this->userId); | |
// try to extract the first picture from the first track on the album | |
$tracks = $this->trackBusinessLayer->findAllByAlbum($albumId, $this->userId); | |
$filePath = $this->userFolder->getById($tracks[0]->getFileId())[0]->getPath(); | |
$filePath = str_replace($this->userFolder->getPath(), '/files', $filePath); | |
if ($this->preview->isAvailable($this->userFolder->getById($tracks[0]->getFileId())[0])) { | |
$image = $this->preview->createPreview($filePath, 190, 190, true); | |
return new DataDisplayResponse($image->data(), Http::STATUS_OK, ['Content-Type' => $image->mimeType()]); | |
} | |
$r = new Response(); | |
$r->setStatus(Http::STATUS_NOT_FOUND); | |
return $r; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment