Skip to content

Commit

Permalink
Merge pull request #4 from toneflix/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
3m1n3nc3 authored Jun 26, 2024
2 parents b30f18a + 8846024 commit 10e2b83
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 123 deletions.
4 changes: 2 additions & 2 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@
'lg-square' => '720x720',
'xl-square' => '1080x1080',
],
'file_route_secure_middleware' => 'window_auth',
'file_route_secure_middleware' => 'web',
'responsive_image_route' => 'images/responsive/{file}/{size}',
'file_route_secure' => 'secure/files/{file}',
'file_route_open' => 'open/files/{file}',
'symlinks' => [
public_path('avatars') => storage_path('app/public/avatars'),
public_path('media') => storage_path('app/public/media'),
],
];
];
34 changes: 34 additions & 0 deletions src/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,42 @@ public function resizeResponse(string $fileName, string $size): \Illuminate\Http
return abort(404);
}

/**
* Returns the attributes of a bound media file.
* @param string $type
* @param string $file_name
*/
public function mediaInfo(string $type, string $src)
{
$prefix = !str($type)->contains('private.') ? 'public/' : '/';
$file_path = $prefix . $this->getMedia($type, $src, true);

$mime = str(Storage::exists($file_path) ? Storage::mimeType($file_path) : 'unknown/unknown');
$isImage = $mime->contains('image');
$mediaType = $mime->beforeLast('/')->exactly('application')
? $mime->afterLast('/')
: $mime->beforeLast('/')->toString();

$file_url = $this->getMedia($type, $src) ?: (new Media())->getDefaultMedia($type);
$dynamicLink = route('fileable.open.file', Initiator::base64urlEncode($file_path));
$secureLink = route('fileable.secure.file', Initiator::base64urlEncode($file_path));

return [
'isImage' => $isImage,
'path' => $file_path,
'url' => $file_url,
'type' => $mediaType,
'mime' => $mime->toString(),
'size' => $mime->isNotEmpty() && Storage::exists($file_path) ? Storage::size($file_path) : 0,
'dynamicLink' => $dynamicLink,
'secureLink' => $secureLink,
];
}

/**
* Delete a file from the storage
* @param string $type
* @param ?string $file_name
*/
public function delete(string $type, string $src = null): ?string
{
Expand Down
Loading

0 comments on commit 10e2b83

Please sign in to comment.