mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-28 11:00:39 +00:00
moved move_to_external_storage into HelperService.php
This commit is contained in:
@@ -419,7 +419,7 @@ class FileManagerService
|
|||||||
$this->helper->check_user_storage_capacity($user_id, $file_size, $temp_filename);
|
$this->helper->check_user_storage_capacity($user_id, $file_size, $temp_filename);
|
||||||
|
|
||||||
// Create thumbnail
|
// Create thumbnail
|
||||||
$thumbnail = self::get_image_thumbnail('chunks/' . $temp_filename, $disk_file_name, $user_id);
|
$thumbnail = $this->helper->get_image_thumbnail('chunks/' . $temp_filename, $disk_file_name, $user_id);
|
||||||
|
|
||||||
// Move finished file from chunk to file-manager directory
|
// Move finished file from chunk to file-manager directory
|
||||||
$disk_local->move('chunks/' . $temp_filename, "files/$user_id/$disk_file_name");
|
$disk_local->move('chunks/' . $temp_filename, "files/$user_id/$disk_file_name");
|
||||||
@@ -486,44 +486,4 @@ class FileManagerService
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Create thumbnail for images
|
|
||||||
*
|
|
||||||
* @param string $file_path
|
|
||||||
* @param string $filename
|
|
||||||
* @param string $user_id
|
|
||||||
* @param $file
|
|
||||||
* @return string|null
|
|
||||||
*/
|
|
||||||
private function get_image_thumbnail(string $file_path, string $filename, string $user_id)
|
|
||||||
{
|
|
||||||
$local_disk = Storage::disk('local');
|
|
||||||
|
|
||||||
// Create thumbnail from image
|
|
||||||
if (in_array($local_disk->mimeType($file_path), ['image/gif', 'image/jpeg', 'image/jpg', 'image/png', 'image/webp'])) {
|
|
||||||
|
|
||||||
// Get thumbnail name
|
|
||||||
$thumbnail = 'thumbnail-' . $filename;
|
|
||||||
|
|
||||||
// Create intervention image
|
|
||||||
$image = Image::make($local_disk->path($file_path))->orientate();
|
|
||||||
|
|
||||||
// Resize image
|
|
||||||
$image->resize(512, null, function ($constraint) {
|
|
||||||
$constraint->aspectRatio();
|
|
||||||
})->stream();
|
|
||||||
|
|
||||||
// Store thumbnail to disk
|
|
||||||
$local_disk->put("files/$user_id/$thumbnail", $image);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return thumbnail as svg file
|
|
||||||
if ($local_disk->mimeType($file_path) === 'image/svg+xml') {
|
|
||||||
|
|
||||||
$thumbnail = $filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $thumbnail ?? null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,7 @@ use DB;
|
|||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Intervention\Image\ImageManagerStatic as Image;
|
||||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||||
|
|
||||||
class HelperService
|
class HelperService
|
||||||
@@ -99,7 +100,7 @@ class HelperService
|
|||||||
* @param string $filename
|
* @param string $filename
|
||||||
* @param string|null $thumbnail
|
* @param string|null $thumbnail
|
||||||
*/
|
*/
|
||||||
function move_to_external_storage(string $filename, ?string $thumbnail): void
|
function move_to_external_storage($filename, $thumbnail = null): void
|
||||||
{
|
{
|
||||||
$disk_local = Storage::disk('local');
|
$disk_local = Storage::disk('local');
|
||||||
|
|
||||||
@@ -157,4 +158,44 @@ class HelperService
|
|||||||
$disk_local->delete('files/' . $file);
|
$disk_local->delete('files/' . $file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create image thumbnail from gif, jpeg, jpg, png, webp or svg
|
||||||
|
*
|
||||||
|
* @param string $file_path
|
||||||
|
* @param string $filename
|
||||||
|
* @param string $user_id
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
function get_image_thumbnail($file_path, $filename, $user_id)
|
||||||
|
{
|
||||||
|
$local_disk = Storage::disk('local');
|
||||||
|
|
||||||
|
// Create thumbnail from image
|
||||||
|
if (in_array($local_disk->mimeType($file_path), ['image/gif', 'image/jpeg', 'image/jpg', 'image/png', 'image/webp'])) {
|
||||||
|
|
||||||
|
// Get thumbnail name
|
||||||
|
$thumbnail = "thumbnail-$filename";
|
||||||
|
|
||||||
|
// Create intervention image
|
||||||
|
$image = Image::make($local_disk->path($file_path))
|
||||||
|
->orientate();
|
||||||
|
|
||||||
|
// Resize image
|
||||||
|
$image->resize(512, null, function ($constraint) {
|
||||||
|
$constraint->aspectRatio();
|
||||||
|
})->stream();
|
||||||
|
|
||||||
|
// Store thumbnail to disk
|
||||||
|
$local_disk->put("files/$user_id/$thumbnail", $image);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return thumbnail as svg file
|
||||||
|
if ($local_disk->mimeType($file_path) === 'image/svg+xml') {
|
||||||
|
|
||||||
|
$thumbnail = $filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $thumbnail ?? null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user