1
0

LivePhotosService.php 817 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Files\Service;
  8. use OCP\FilesMetadata\Exceptions\FilesMetadataNotFoundException;
  9. use OCP\FilesMetadata\IFilesMetadataManager;
  10. class LivePhotosService {
  11. public function __construct(
  12. private IFilesMetadataManager $filesMetadataManager,
  13. ) {
  14. }
  15. /**
  16. * Get the associated live photo for a given file id
  17. */
  18. public function getLivePhotoPeerId(int $fileId): ?int {
  19. try {
  20. $metadata = $this->filesMetadataManager->getMetadata($fileId);
  21. } catch (FilesMetadataNotFoundException $ex) {
  22. return null;
  23. }
  24. if (!$metadata->hasKey('files-live-photo')) {
  25. return null;
  26. }
  27. return (int)$metadata->getString('files-live-photo');
  28. }
  29. }