Skip to content

Instantly share code, notes, and snippets.

@gnarula
Created November 9, 2016 17:56
Show Gist options
  • Save gnarula/85641f3747a93582f6ba871fb23ba455 to your computer and use it in GitHub Desktop.
Save gnarula/85641f3747a93582f6ba871fb23ba455 to your computer and use it in GitHub Desktop.
/**
* @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