diff --git a/.env.testing b/.env.testing index 34f42875..09adae02 100644 --- a/.env.testing +++ b/.env.testing @@ -1,6 +1,6 @@ APP_NAME=Laravel APP_ENV=local -APP_KEY=base64:/yb14wOXR+PqqMWnzqE2YZxcvqwSYYKDHtrF0BpT5fM= +APP_KEY=base64:fzZomRn3E8Rb6UDR8oqFiNo8Y4L5RyX4oVVli3KiWQA= APP_DEBUG=true APP_URL=http://localhost APP_DEMO=false diff --git a/config/vuefilemanager.php b/config/vuefilemanager.php index 8b6503c4..86759419 100644 --- a/config/vuefilemanager.php +++ b/config/vuefilemanager.php @@ -67,5 +67,6 @@ return [ '2_0_13', '2_0_14', '2_0_16', + '2_1_1', ], ]; diff --git a/database/migrations/2022_04_26_161750_update_tables_to_v2.1.1_table.php b/database/migrations/2022_04_26_161750_update_tables_to_v2.1.1_table.php new file mode 100644 index 00000000..aa78e1f8 --- /dev/null +++ b/database/migrations/2022_04_26_161750_update_tables_to_v2.1.1_table.php @@ -0,0 +1,30 @@ +uuid('file_id')->nullable()->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + + } +}; diff --git a/src/Domain/Files/Actions/ProcessFileAction.php b/src/Domain/Files/Actions/ProcessFileAction.php index 74418399..1b6efdf9 100644 --- a/src/Domain/Files/Actions/ProcessFileAction.php +++ b/src/Domain/Files/Actions/ProcessFileAction.php @@ -13,7 +13,7 @@ class ProcessFileAction public function __construct( public RecordUploadAction $recordUpload, public GetFileParentId $getFileParentId, - public StoreFileExifMetadataAction $storeExifMetadata, + public StoreExifDataAction $storeExifData, public MoveFileToFTPStorageAction $moveFileToFTPStorage, public ProcessImageThumbnailAction $createImageThumbnail, public MoveFileToExternalStorageAction $moveFileToExternalStorage, @@ -65,6 +65,9 @@ class ProcessFileAction // Create multiple image thumbnails ($this->createImageThumbnail)($name, $user->id); + // Store exif data if exists + $exif = ($this->storeExifData)("files/$user->id/$name"); + // Move file to external storage match (config('filesystems.default')) { 's3' => ($this->moveFileToExternalStorage)($name, $user->id), @@ -84,8 +87,8 @@ class ProcessFileAction 'creator_id' => auth()->check() ? auth()->id() : $user->id, ]); - // Store file exif data - ($this->storeExifMetadata)($file); + // Attach file into the exif data + $exif?->update(['file_id' => $file->id]); // Return new file return $file; diff --git a/src/Domain/Files/Actions/StoreExifDataAction.php b/src/Domain/Files/Actions/StoreExifDataAction.php new file mode 100644 index 00000000..068fa3d4 --- /dev/null +++ b/src/Domain/Files/Actions/StoreExifDataAction.php @@ -0,0 +1,61 @@ +exif(), + 'UTF8', + 'UTF8' + ); + + // Convert to object + $exif = json_decode(json_encode($exifRaw)); + + return Exif::create([ + 'file_id' => Str::uuid(), // TODO: temporary store to prevent crash before app will be successfully upgraded + 'date_time_original' => $exif->DateTimeOriginal ?? null, + 'artist' => $exif->OwnerName ?? null, + 'width' => $exif->COMPUTED->Width ?? null, + 'height' => $exif->COMPUTED->Height ?? null, + 'x_resolution' => $exif->XResolution ?? null, + 'y_resolution' => $exif->YResolution ?? null, + 'color_space' => $exif->ColorSpace ?? null, + 'camera' => $exif->Make ?? null, + 'model' => $exif->Model ?? null, + 'aperture_value' => $exif->ApertureValue ?? null, + 'exposure_time' => $exif->ExposureTime ?? null, + 'focal_length' => $exif->FocalLength ?? null, + 'iso' => $exif->ISOSpeedRatings ?? null, + 'aperture_f_number' => $exif->COMPUTED->ApertureFNumber ?? null, + 'ccd_width' => $exif->COMPUTED->CCDWidth ?? null, + 'longitude' => $exif->GPSLongitude ?? null, + 'latitude' => $exif->GPSLatitude ?? null, + 'longitude_ref' => $exif->GPSLongitudeRef ?? null, + 'latitude_ref' => $exif->GPSLatitudeRef ?? null, + ]); + } catch (Exception $error) { + Log::error('Unable to get exif data'); + + return null; + } + } +} diff --git a/src/Domain/Files/Actions/StoreFileExifMetadataAction.php b/src/Domain/Files/Actions/StoreFileExifMetadataAction.php deleted file mode 100644 index 979bad8b..00000000 --- a/src/Domain/Files/Actions/StoreFileExifMetadataAction.php +++ /dev/null @@ -1,41 +0,0 @@ -user_id/$file->basename"); - - if (is_null($data)) { - return; - } - - $file - ->exif() - ->create([ - 'date_time_original' => $data->DateTimeOriginal ?? null, - 'artist' => $data->OwnerName ?? null, - 'width' => $data->COMPUTED->Width ?? null, - 'height' => $data->COMPUTED->Height ?? null, - 'x_resolution' => $data->XResolution ?? null, - 'y_resolution' => $data->YResolution ?? null, - 'color_space' => $data->ColorSpace ?? null, - 'camera' => $data->Make ?? null, - 'model' => $data->Model ?? null, - 'aperture_value' => $data->ApertureValue ?? null, - 'exposure_time' => $data->ExposureTime ?? null, - 'focal_length' => $data->FocalLength ?? null, - 'iso' => $data->ISOSpeedRatings ?? null, - 'aperture_f_number' => $data->COMPUTED->ApertureFNumber ?? null, - 'ccd_width' => $data->COMPUTED->CCDWidth ?? null, - 'longitude' => $data->GPSLongitude ?? null, - 'latitude' => $data->GPSLatitude ?? null, - 'longitude_ref' => $data->GPSLongitudeRef ?? null, - 'latitude_ref' => $data->GPSLatitudeRef ?? null, - ]); - } -} diff --git a/src/Domain/RemoteUpload/Actions/GetContentFromExternalSource.php b/src/Domain/RemoteUpload/Actions/GetContentFromExternalSource.php index cb8b26c1..24673c5c 100644 --- a/src/Domain/RemoteUpload/Actions/GetContentFromExternalSource.php +++ b/src/Domain/RemoteUpload/Actions/GetContentFromExternalSource.php @@ -12,9 +12,9 @@ use Illuminate\Support\Facades\Storage; use Domain\Files\Resources\FileResource; use Domain\Files\Actions\ProcessFileAction; use Spatie\QueueableAction\QueueableAction; +use Domain\Files\Actions\StoreExifDataAction; use Domain\Files\Actions\MoveFileToFTPStorageAction; use Domain\Files\Actions\ProcessImageThumbnailAction; -use Domain\Files\Actions\StoreFileExifMetadataAction; use Domain\RemoteUpload\Events\RemoteFileCreatedEvent; use Domain\Files\Actions\MoveFileToExternalStorageAction; @@ -24,7 +24,7 @@ class GetContentFromExternalSource public function __construct( public ProcessFileAction $processFile, - public StoreFileExifMetadataAction $storeExifMetadata, + public StoreExifDataAction $storeExifData, public MoveFileToFTPStorageAction $moveFileToFTPStorage, public ProcessImageThumbnailAction $createImageThumbnail, public MoveFileToExternalStorageAction $moveFileToExternalStorage, @@ -70,6 +70,9 @@ class GetContentFromExternalSource // Create multiple image thumbnails ($this->createImageThumbnail)($basename, $user->id); + // Store file exif information + $exif = ($this->storeExifData)($path); + // Create new file $file = File::create([ 'mimetype' => $extension, @@ -82,8 +85,8 @@ class GetContentFromExternalSource 'creator_id' => auth()->id(), ]); - // Store file exif information - ($this->storeExifMetadata)($file); + // Attach file into the exif data + $exif?->update(['file_id' => $file->id]); // Move file to external storage match (config('filesystems.default')) { diff --git a/src/Support/Upgrading/Controllers/UpgradingVersionsController.php b/src/Support/Upgrading/Controllers/UpgradingVersionsController.php index 86d60024..536d1e0c 100644 --- a/src/Support/Upgrading/Controllers/UpgradingVersionsController.php +++ b/src/Support/Upgrading/Controllers/UpgradingVersionsController.php @@ -22,6 +22,11 @@ class UpgradingVersionsController ) { } + public function upgrade_to_2_1_1(): void + { + ($this->upgradeDatabase)(); + } + public function upgrade_to_2_0_10(): void { ($this->upgradeDatabase)(); diff --git a/src/Support/helpers.php b/src/Support/helpers.php index 7ec6e7f8..20b8a5d6 100644 --- a/src/Support/helpers.php +++ b/src/Support/helpers.php @@ -723,19 +723,6 @@ if (! function_exists('map_language_translations')) { } } -if (! function_exists('get_file_type_from_mimetype')) { - /** - * Get file type from mimetype - * - * @param $mimetype - * @return mixed - */ - function get_file_type_from_mimetype($mimetype) - { - return explode('/', $mimetype)[1]; - } -} - if (! function_exists('getPrettyName')) { /** * Format pretty name file @@ -756,40 +743,6 @@ if (! function_exists('getPrettyName')) { } } -if (! function_exists('readExifData')) { - /** - * Get exif data from jpeg image - */ - function readExifData(string $file): object|null - { - $mimetype = Storage::mimeType($file); - - if (!$mimetype) { - return null; - } - - $type = get_file_type_from_mimetype( - Storage::mimeType($file) - ); - - if ($type !== 'jpeg') { - return null; - } - - try { - // Try to get the exif data - $data = Image::make(Storage::path($file))->exif(); - - // Encode data - $encodedData = mb_convert_encoding($data, 'UTF8', 'UTF8'); - - return json_decode(json_encode($encodedData)); - } catch (Exception $e) { - return null; - } - } -} - if (! function_exists('get_default_language_translations')) { /** * @return Collection diff --git a/storage/files.index-shm b/storage/files.index-shm new file mode 100644 index 00000000..83327bc3 Binary files /dev/null and b/storage/files.index-shm differ diff --git a/storage/files.index-wal b/storage/files.index-wal new file mode 100644 index 00000000..4e3c4f59 Binary files /dev/null and b/storage/files.index-wal differ