From 17c494e5f9f7efa52e02a395ec3f69706ebcbca4 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Fri, 17 Mar 2023 01:11:13 -0700 Subject: [PATCH] takeout: minor fixes Signed-off-by: Varun Patil --- lib/Command/MigrateGoogleTakeout.php | 10 +++++++--- lib/Controller/ImageController.php | 13 +------------ lib/Exif.php | 19 ++++++++++++++++++- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/lib/Command/MigrateGoogleTakeout.php b/lib/Command/MigrateGoogleTakeout.php index 500c26b7..11bc9d1b 100644 --- a/lib/Command/MigrateGoogleTakeout.php +++ b/lib/Command/MigrateGoogleTakeout.php @@ -134,6 +134,12 @@ class MigrateGoogleTakeout extends Command protected function migrateFolder(Folder $folder): void { + // Check for .nomedia + if ($folder->nodeExists('.nomedia')) { + return; + } + + // Get all nodes in this folder $nodes = $folder->getDirectoryListing(); $path = $folder->getPath(); $this->output->writeln("Scanning folder {$path}"); @@ -229,9 +235,7 @@ class MigrateGoogleTakeout extends Command // Write EXIF metadata try { - $localPath = $file->getStorage()->getLocalFile($file->getInternalPath()); - Exif::setExif($localPath, $txf); - $file->touch(); + Exif::setFileExif($file, $txf); } catch (\Exception $e) { $this->output->writeln("Error while writing EXIF metadata for {$path}: {$e->getMessage()}"); diff --git a/lib/Controller/ImageController.php b/lib/Controller/ImageController.php index ea34b616..ee279e78 100644 --- a/lib/Controller/ImageController.php +++ b/lib/Controller/ImageController.php @@ -250,23 +250,12 @@ class ImageController extends ApiBase return new JSONResponse(['message' => "Cannot edit file {$name} (blacklisted type {$mime})"], Http::STATUS_PRECONDITION_FAILED); } - // Get original file from body - $path = $file->getStorage()->getLocalFile($file->getInternalPath()); - try { - Exif::setExif($path, $raw); + Exif::setFileExif($file, $raw); } catch (\Exception $e) { return new JSONResponse(['message' => $e->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR); } - // Update remote file if not local - if (!$file->getStorage()->isLocal()) { - $file->putContent(fopen($path, 'r')); // closes the handler - } - - // Touch the file, triggering a reprocess through the hook - $file->touch(); - return new JSONResponse([], Http::STATUS_OK); } diff --git a/lib/Exif.php b/lib/Exif.php index d1581450..e4a5c30d 100644 --- a/lib/Exif.php +++ b/lib/Exif.php @@ -261,7 +261,7 @@ class Exif * * @throws \Exception on failure */ - public static function setExif(string &$path, array &$data) + public static function setExif(string $path, array $data) { $data['SourceFile'] = $path; $raw = json_encode([$data]); @@ -286,6 +286,23 @@ class Exif } } + public static function setFileExif(File $file, array $data) + { + // Get path to local file so we can skip reading + $path = $file->getStorage()->getLocalFile($file->getInternalPath()); + + // Set exif data + self::setExif($path, $data); + + // Update remote file if not local + if (!$file->getStorage()->isLocal()) { + $file->putContent(fopen($path, 'r')); // closes the handler + } + + // Touch the file, triggering a reprocess through the hook + $file->touch(); + } + public static function getBinaryExifProp(string $path, string $prop) { $pipes = [];