takeout: minor fixes

Signed-off-by: Varun Patil <varunpatil@ucla.edu>
pull/504/head
Varun Patil 2023-03-17 01:11:13 -07:00
parent 2441d5f556
commit 17c494e5f9
3 changed files with 26 additions and 16 deletions

View File

@ -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>Error while writing EXIF metadata for {$path}: {$e->getMessage()}</error>");

View File

@ -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);
}

View File

@ -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 = [];