|
|
|
|
@ -31,6 +31,7 @@ use OC\AppFramework\Utility\TimeFactory; |
|
|
|
|
use OCP\AppFramework\Controller; |
|
|
|
|
use OCP\AppFramework\Http; |
|
|
|
|
use OCP\AppFramework\Http\DataDisplayResponse; |
|
|
|
|
use OCP\AppFramework\Http\FileDisplayResponse; |
|
|
|
|
use OCP\AppFramework\Http\JSONResponse; |
|
|
|
|
use OCP\Files\File; |
|
|
|
|
use OCP\Files\IRootFolder; |
|
|
|
|
@ -118,7 +119,7 @@ class AvatarController extends Controller { |
|
|
|
|
* |
|
|
|
|
* @param string $userId |
|
|
|
|
* @param int $size |
|
|
|
|
* @return JSONResponse|DataDisplayResponse |
|
|
|
|
* @return JSONResponse|FileDisplayResponse |
|
|
|
|
*/ |
|
|
|
|
public function getAvatar($userId, $size) { |
|
|
|
|
if ($size > 2048) { |
|
|
|
|
@ -129,25 +130,19 @@ class AvatarController extends Controller { |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
$avatar = $this->avatarManager->getAvatar($userId)->getFile($size); |
|
|
|
|
$resp = new DataDisplayResponse($avatar->getContent(), |
|
|
|
|
$resp = new FileDisplayResponse($avatar, |
|
|
|
|
Http::STATUS_OK, |
|
|
|
|
['Content-Type' => $avatar->getMimeType()]); |
|
|
|
|
$resp->setETag($avatar->getEtag()); |
|
|
|
|
|
|
|
|
|
// Let cache this! |
|
|
|
|
$resp->addHeader('Pragma', 'public'); |
|
|
|
|
// Cache for 15 minutes |
|
|
|
|
$resp->cacheFor(900); |
|
|
|
|
// Set last modified |
|
|
|
|
$lastModified = new \DateTime(); |
|
|
|
|
$lastModified->setTimestamp($avatar->getMTime()); |
|
|
|
|
$resp->setLastModified($lastModified); |
|
|
|
|
|
|
|
|
|
$expires = new \DateTime(); |
|
|
|
|
$expires->setTimestamp($this->timeFactory->getTime()); |
|
|
|
|
$expires->add(new \DateInterval('PT15M')); |
|
|
|
|
$resp->addHeader('Expires', $expires->format(\DateTime::RFC2822)); |
|
|
|
|
|
|
|
|
|
} catch (NotFoundException $e) { |
|
|
|
|
$user = $this->userManager->get($userId); |
|
|
|
|
$resp = new JSONResponse([ |
|
|
|
|
|