Skip to content

Commit 97e427f

Browse files
authored
Merge pull request #27436 from nextcloud/techdebt/noid/all-apps-to-get-photos-from-vobjects-too
Allow apps to get photos of VObjects
2 parents c613c8c + b1031f3 commit 97e427f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

apps/dav/lib/CardDAV/PhotoCache.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use OCP\Files\SimpleFS\ISimpleFolder;
3737
use OCP\ILogger;
3838
use Sabre\CardDAV\Card;
39+
use Sabre\VObject\Document;
3940
use Sabre\VObject\Parameter;
4041
use Sabre\VObject\Property\Binary;
4142
use Sabre\VObject\Reader;
@@ -206,9 +207,28 @@ private function getExtension(ISimpleFolder $folder): string {
206207
throw new NotFoundException('Avatar not found');
207208
}
208209

210+
/**
211+
* @param Card $node
212+
* @return bool|array{body: string, Content-Type: string}
213+
*/
209214
private function getPhoto(Card $node) {
210215
try {
211216
$vObject = $this->readCard($node->get());
217+
return $this->getPhotoFromVObject($vObject);
218+
} catch (\Exception $e) {
219+
$this->logger->logException($e, [
220+
'message' => 'Exception during vcard photo parsing'
221+
]);
222+
}
223+
return false;
224+
}
225+
226+
/**
227+
* @param Document $vObject
228+
* @return bool|array{body: string, Content-Type: string}
229+
*/
230+
public function getPhotoFromVObject(Document $vObject) {
231+
try {
212232
if (!$vObject->PHOTO) {
213233
return false;
214234
}

0 commit comments

Comments
 (0)