mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-27 18:40:39 +00:00
Merge remote-tracking branch 'origin/exif_metadata'
# Conflicts: # public/mix-manifest.json # resources/js/App.vue # resources/js/components/FilesView/ImageMetaData.vue # resources/js/components/FilesView/InfoSidebar.vue # resources/js/components/FilesView/SearchBar.vue # resources/js/components/Spotlight/Spotlight.vue # resources/js/views/Shared.vue # src/Domain/Files/Resources/FileResource.php
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Domain\Files\Actions;
|
||||
|
||||
class StoreFileExifMetadataAction
|
||||
{
|
||||
public function __invoke($item, $file)
|
||||
{
|
||||
// Get exif metadata
|
||||
$exif_data = get_image_meta_data($file);
|
||||
|
||||
if($exif_data) {
|
||||
|
||||
// Conver array to collection
|
||||
$data = json_decode(json_encode($exif_data)) ;
|
||||
|
||||
$item->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
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ use Domain\Files\Models\File as UserFile;
|
||||
use Domain\Traffic\Actions\RecordUploadAction;
|
||||
use App\Users\Exceptions\InvalidUserActionException;
|
||||
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
||||
use Domain\Files\Actions\StoreFileExifMetadataAction;
|
||||
|
||||
class UploadFileAction
|
||||
{
|
||||
@@ -19,6 +20,7 @@ class UploadFileAction
|
||||
public ProcessImageThumbnailAction $createImageThumbnail,
|
||||
public GetFileParentId $getFileParentId,
|
||||
public MoveFileToExternalStorageAction $moveFileToExternalStorage,
|
||||
public StoreFileExifMetadataAction $storeExifMetadata,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -57,8 +59,6 @@ class UploadFileAction
|
||||
|
||||
// If last then process file
|
||||
if ($request->boolean('is_last')) {
|
||||
$metadata = get_image_meta_data($file);
|
||||
|
||||
$disk_local = Storage::disk('local');
|
||||
|
||||
// Get user data
|
||||
@@ -90,18 +90,23 @@ class UploadFileAction
|
||||
// Store user upload size
|
||||
($this->recordUpload)($fileSize, $user->id);
|
||||
|
||||
// Return new file
|
||||
return UserFile::create([
|
||||
// Create new file
|
||||
$item = UserFile::create([
|
||||
'mimetype' => get_file_type_from_mimetype($file_mimetype),
|
||||
'type' => get_file_type($file_mimetype),
|
||||
'parent_id' => ($this->getFileParentId)($request, $user->id),
|
||||
'metadata' => $metadata,
|
||||
'name' => $request->input('filename'),
|
||||
'basename' => $fileName,
|
||||
'author' => $userId ? 'visitor' : 'user',
|
||||
'filesize' => $fileSize,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
// Store exif metadata for files
|
||||
($this->storeExifMetadata)($item, $file);
|
||||
|
||||
// Return new file
|
||||
return $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Domain\Files\Models;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
|
||||
class Exif extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
public $incrementing = false;
|
||||
|
||||
protected $keyType = 'string';
|
||||
|
||||
protected $casts = [
|
||||
'longitude' => 'array',
|
||||
'latitude' => 'array',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get parent
|
||||
*/
|
||||
public function file(): HasOne
|
||||
{
|
||||
return $this->HasOne(File::class, 'id', 'file_id');
|
||||
}
|
||||
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($model) {
|
||||
$model->id = (string) Str::uuid();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,6 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
* @property string thumbnail
|
||||
* @property string filesize
|
||||
* @property string type
|
||||
* @property array metadata
|
||||
* @property string basename
|
||||
* @property string name
|
||||
* @property string mimetype
|
||||
@@ -55,10 +54,6 @@ class File extends Model
|
||||
'file_url',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'metadata' => 'array',
|
||||
];
|
||||
|
||||
public array $sortable = [
|
||||
'name',
|
||||
'created_at',
|
||||
@@ -201,6 +196,11 @@ class File extends Model
|
||||
return $this->hasOne(User::class, 'id', 'user_id');
|
||||
}
|
||||
|
||||
public function exif(): HasOne
|
||||
{
|
||||
return $this->hasOne(Exif::class);
|
||||
}
|
||||
|
||||
public function toSearchableArray(): array
|
||||
{
|
||||
$name = mb_convert_encoding(
|
||||
@@ -225,5 +225,11 @@ class File extends Model
|
||||
static::creating(function ($file) {
|
||||
$file->id = (string) Str::uuid();
|
||||
});
|
||||
|
||||
static::deleting(function($file) {
|
||||
if($file->isForceDeleting()) {
|
||||
$file->exif()->forceDelete();
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ class FileResource extends JsonResource
|
||||
'mimetype' => $this->mimetype,
|
||||
'file_url' => $this->file_url,
|
||||
'thumbnail' => $this->thumbnail,
|
||||
'metadata' => $this->metadata,
|
||||
'parent_id' => $this->parent_id,
|
||||
'created_at' => set_time_by_user_timezone($this->owner, $this->created_at),
|
||||
'updated_at' => set_time_by_user_timezone($this->owner, $this->updated_at),
|
||||
@@ -64,6 +63,33 @@ class FileResource extends JsonResource
|
||||
],
|
||||
],
|
||||
]),
|
||||
$this->mergeWhen($this->exif, fn() => [
|
||||
'exif' => [
|
||||
'data' => [
|
||||
'type' => 'exif',
|
||||
'id' => $this->exif->id,
|
||||
'attributes' => [
|
||||
'date_time_original' => format_date($this->exif->date_time_original),
|
||||
'artist' => $this->exif->artist,
|
||||
'height' => $this->exif->height,
|
||||
'width' => $this->exif->width,
|
||||
'x_resolution' => substr($this->exif->x_resolution, 0, strrpos($this->exif->x_resolution, '/')),
|
||||
'y_resolution' => substr($this->exif->y_resolution, 0, strrpos($this->exif->y_resolution, '/')),
|
||||
'color_space' => $this->exif->color_space,
|
||||
'camera' => $this->exif->camera,
|
||||
'model' => $this->exif->model,
|
||||
'aperture_value' => intval($this->exif->aperture_value) / 100,
|
||||
'exposure_time' => $this->exif->exposure_time,
|
||||
'focal_length' => $this->exif->focal_length,
|
||||
'iso' => $this->exif->iso,
|
||||
'aperture_f_number' => $this->exif->aperture_f_number,
|
||||
'ccd_width' => $this->exif->ccd_width,
|
||||
'longitude' => format_gps_coordinates($this->exif->longitude, $this->exif->longitude_ref),
|
||||
'latitude' => format_gps_coordinates($this->exif->latitude, $this->exif->latitude_ref),
|
||||
],
|
||||
],
|
||||
]
|
||||
])
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user