diff --git a/lib/Helper/ExifDataException.php b/lib/Helper/ExifDataInvalidException.php similarity index 85% rename from lib/Helper/ExifDataException.php rename to lib/Helper/ExifDataInvalidException.php index 74ff2bc03..3a92b05e7 100644 --- a/lib/Helper/ExifDataException.php +++ b/lib/Helper/ExifDataInvalidException.php @@ -14,6 +14,6 @@ /** * Class GeoPhotoException */ -class ExifDataException extends \Exception +class ExifDataInvalidException extends \Exception { } diff --git a/lib/Helper/ExifDataNoLocationException.php b/lib/Helper/ExifDataNoLocationException.php new file mode 100644 index 000000000..80ceed8fa --- /dev/null +++ b/lib/Helper/ExifDataNoLocationException.php @@ -0,0 +1,19 @@ + $pelDateTimeOriginal->getValue(PelEntryTime::EXIF_STRING) // for old pel 0.9.6 and above - self::TIMESTAMP => $pelDateTimeOriginal->getValue() // for new pel >= 0.9.11 + self::TIMESTAMP => (int) $pelDateTimeOriginal->getValue() // for new pel >= 0.9.11 ]; $pelIfdGPS = $pelIfd0->getSubIfd(PelIfd::GPS); if (!is_null($pelIfdGPS) && !is_null($pelIfdGPS->getEntry(PelTag::GPS_LATITUDE )) && !is_null( $pelIfdGPS->getEntry(PelTag::GPS_LONGITUDE))) { @@ -206,17 +206,17 @@ private final function __construct(array $exif_data) public function validate( $invalidate_zero_iland = false ) { if (!$this->exif_data) { - throw new ExifDataException('No exif_data found', 1); + throw new ExifDataInvalidException('No exif_data found', 1); } if (!is_array($this->exif_data)) { - throw new ExifDataException('exif_data is not an array', 2); + throw new ExifDataInvalidException('exif_data is not an array', 2); } if (!isset($this->exif_data[self::LATITUDE]) || !isset($this->exif_data[self::LONGITUDE])) { - throw new ExifDataException('Latitude and/or Longitude are missing from exif data', 3); + throw new ExifDataNoLocationException('Latitude and/or Longitude are missing from exif data', 1); } if( $invalidate_zero_iland && $this->isZeroIsland() ){ - throw new ExifDataException('Zero island is not valid', 4); + throw new ExifDataNoLocationException('Zero island is not valid', 2); } } @@ -229,7 +229,7 @@ public function isValid(): bool try { $this->validate(); $this->is_valid = true; - } catch (\Throwable $e) { + } catch (\Throwable $e) { $this->is_valid = false; } } @@ -241,7 +241,7 @@ public function isValid(): bool */ private function parse() { - if ($this->isValid() && null === $this->latitude && null === $this->longitude && null === $this->timestamp) { + if ($this->isValid() && (null === $this->latitude || null === $this->longitude)) { $this->longitude = $this->geo2float($this->exif_data[self::LONGITUDE]); if( isset($this->exif_data[self::LONGITUDE_REF]) && 'W' === $this->exif_data[self::LONGITUDE_REF] ){ $this->longitude*=-1; @@ -250,11 +250,12 @@ private function parse() if( isset($this->exif_data[self::LATITUDE_REF]) && 'S' === $this->exif_data[self::LATITUDE_REF] ){ $this->latitude*=-1; } - // optional - if (isset($this->exif_data[self::TIMESTAMP])) { - $this->timestamp = $this->string2time($this->exif_data[self::TIMESTAMP]); - } } + // optional + if (isset($this->exif_data[self::TIMESTAMP])) { + $t = $this->exif_data[self::TIMESTAMP]; + $this->timestamp = is_string($t) ? $this->string2time($t) : is_int($t) ? $t : null; + } } /** diff --git a/lib/Service/GeophotoService.php b/lib/Service/GeophotoService.php index 1fc4ae2df..9fc19aadd 100644 --- a/lib/Service/GeophotoService.php +++ b/lib/Service/GeophotoService.php @@ -131,21 +131,34 @@ public function getNonLocalizedFromDB ($userId) { continue; } $file = array_shift($files); - if ($file === null) { - continue; - } - $path = preg_replace('/^\/'.$userId.'\//', '', $file->getPath()); + if ($file === null) { + continue; + } + $path = $userFolder->getRelativePath( $file->getPath()); + $isRoot = $file === $userFolder; $date = $photoEntity->getDateTaken() ?? \time(); $locations = $this->getLocationGuesses($date); foreach ($locations as $location) { $file_object = new \stdClass(); $file_object->fileId = $photoEntity->getFileId(); + $file_object->fileid = $file_object->fileId; $file_object->path = $this->normalizePath($path); $file_object->hasPreview = in_array($cacheEntry->getMimeType(), $previewEnableMimetypes); $file_object->lat = $location[0]; $file_object->lng = $location[1]; $file_object->dateTaken = $date; + $file_object->basename = $isRoot ? '' : $file->getName(); + $file_object->filename = $this->normalizePath($path); + $file_object->etag = $cacheEntry->getEtag(); +//Not working for NC21 as Viewer requires String representation of permissions +// $file_object->permissions = $file->getPermissions(); + $file_object->type = $file->getType(); + $file_object->mime = $file->getMimetype(); + $file_object->lastmod = $file->getMTime(); + $file_object->size = $file->getSize(); + $file_object->path = $path; + $file_object->hasPreview = in_array($cacheEntry->getMimeType(), $previewEnableMimetypes); $filesById[] = $file_object; } @@ -169,9 +182,6 @@ private function getLocationGuesses($dateTaken) { $locations[] = $location; } } - if (count($locations) === 0) { - $locations[] = [null, null]; - } return $locations; } diff --git a/lib/Service/PhotofilesService.php b/lib/Service/PhotofilesService.php index 3f47a9ec7..eddaf9513 100644 --- a/lib/Service/PhotofilesService.php +++ b/lib/Service/PhotofilesService.php @@ -13,7 +13,8 @@ namespace OCA\Maps\Service; use lsolesen\pel\PelEntryTime; -use OCA\Maps\Helper\ExifDataException; +use OCA\Maps\Helper\ExifDataInvalidException; +use OCA\Maps\Helper\ExifDataNoLocationException; use OCA\Maps\Helper\ExifGeoData; use OCP\Files\FileInfo; use OCP\IL10N; @@ -187,7 +188,7 @@ public function deleteByFolderIdUserId($folderId, $userId) { } public function setPhotosFilesCoords($userId, $paths, $lats, $lngs, $directory) { - if ($directory === 'true') { + if ($directory) { return $this->setDirectoriesCoords($userId, $paths, $lats, $lngs); } else { @@ -365,10 +366,12 @@ private function getExif($file) : ?ExifGeoData { try{ $exif_geo_data = ExifGeoData::get($path); $exif_geo_data->validate(true); - }catch(ExifDataException $e){ + }catch(ExifDataInvalidException $e){ $exif_geo_data = null; $this->logger->notice($e->getMessage(), ['code'=>$e->getCode(),'path'=>$path]); - }catch(\Throwable $f){ + }catch(ExifDataNoLocationException $e){ + $this->logger->notice($e->getMessage(), ['code'=>$e->getCode(),'path'=>$path]); + }catch(\Throwable $f){ $exif_geo_data = null; $this->logger->error($f->getMessage(), ['code'=>$f->getCode(),'path'=>$path]); }