Skip to content

Commit

Permalink
Merge pull request #27436 from nextcloud/techdebt/noid/all-apps-to-ge…
Browse files Browse the repository at this point in the history
…t-photos-from-vobjects-too

Allow apps to get photos of VObjects
  • Loading branch information
skjnldsv authored Jun 9, 2021
2 parents c613c8c + b1031f3 commit 97e427f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions apps/dav/lib/CardDAV/PhotoCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use OCP\Files\SimpleFS\ISimpleFolder;
use OCP\ILogger;
use Sabre\CardDAV\Card;
use Sabre\VObject\Document;
use Sabre\VObject\Parameter;
use Sabre\VObject\Property\Binary;
use Sabre\VObject\Reader;
Expand Down Expand Up @@ -206,9 +207,28 @@ private function getExtension(ISimpleFolder $folder): string {
throw new NotFoundException('Avatar not found');
}

/**
* @param Card $node
* @return bool|array{body: string, Content-Type: string}
*/
private function getPhoto(Card $node) {
try {
$vObject = $this->readCard($node->get());
return $this->getPhotoFromVObject($vObject);
} catch (\Exception $e) {
$this->logger->logException($e, [
'message' => 'Exception during vcard photo parsing'
]);
}
return false;
}

/**
* @param Document $vObject
* @return bool|array{body: string, Content-Type: string}
*/
public function getPhotoFromVObject(Document $vObject) {
try {
if (!$vObject->PHOTO) {
return false;
}
Expand Down

0 comments on commit 97e427f

Please sign in to comment.