mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-18 00:02:15 +00:00
ftp implementation
This commit is contained in:
@@ -42,7 +42,7 @@ class UserSetting extends Model
|
||||
$link = [];
|
||||
|
||||
// Get avatar from external storage
|
||||
if ($this->attributes['avatar'] && ! isStorageDriver('local')) {
|
||||
if ($this->attributes['avatar'] && isStorageDriver('s3')) {
|
||||
foreach (config('vuefilemanager.avatar_sizes') as $item) {
|
||||
$filePath = "avatars/{$item['name']}-{$this->attributes['avatar']}";
|
||||
|
||||
|
||||
22
src/Domain/Files/Actions/MoveFileToFTPStorageAction.php
Normal file
22
src/Domain/Files/Actions/MoveFileToFTPStorageAction.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace Domain\Files\Actions;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class MoveFileToFTPStorageAction
|
||||
{
|
||||
/**
|
||||
* Move file to external storage if is set
|
||||
*/
|
||||
public function __invoke(
|
||||
string $file,
|
||||
string $userId
|
||||
): void {
|
||||
|
||||
// Stream file object to ftp
|
||||
Storage::putFileAs("files/$userId", config('filesystems.disks.local.root') . "/files/$userId/$file", $file, 'private');
|
||||
|
||||
// Delete file after upload
|
||||
Storage::disk('local')->delete("files/$userId/$file");
|
||||
}
|
||||
}
|
||||
@@ -15,10 +15,11 @@ class UploadFileAction
|
||||
{
|
||||
public function __construct(
|
||||
public RecordUploadAction $recordUpload,
|
||||
public ProcessImageThumbnailAction $createImageThumbnail,
|
||||
public GetFileParentId $getFileParentId,
|
||||
public MoveFileToExternalStorageAction $moveFileToExternalStorage,
|
||||
public StoreFileExifMetadataAction $storeExifMetadata,
|
||||
public MoveFileToFTPStorageAction $moveFileToFTPStorage,
|
||||
public ProcessImageThumbnailAction $createImageThumbnail,
|
||||
public MoveFileToExternalStorageAction $moveFileToExternalStorage,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -82,9 +83,10 @@ class UploadFileAction
|
||||
($this->createImageThumbnail)($fileName, $file, $user->id);
|
||||
|
||||
// Move files to external storage
|
||||
if (! isStorageDriver('local')) {
|
||||
($this->moveFileToExternalStorage)($fileName, $user->id);
|
||||
}
|
||||
match (config('filesystems.default')) {
|
||||
's3' => ($this->moveFileToExternalStorage)($fileName, $user->id),
|
||||
'ftp' => ($this->moveFileToFTPStorage)($fileName, $user->id),
|
||||
};
|
||||
|
||||
// Create new file
|
||||
$item = UserFile::create([
|
||||
|
||||
@@ -101,7 +101,7 @@ class File extends Model
|
||||
->all();
|
||||
|
||||
// Generate thumbnail link for external storage service
|
||||
if ($this->type === 'image' && ! isStorageDriver('local')) {
|
||||
if ($this->type === 'image' && isStorageDriver('s3')) {
|
||||
foreach ($thumbnail_sizes as $item) {
|
||||
$filePath = "files/{$this->user_id}/{$item['name']}-{$this->basename}";
|
||||
|
||||
|
||||
@@ -48,6 +48,11 @@ class ZipAction
|
||||
|
||||
$zip->add("s3://$bucketName/$filePath", $file->name);
|
||||
}
|
||||
|
||||
// ftp client
|
||||
if (isStorageDriver('ftp')) {
|
||||
$zip->addRaw(Storage::get($filePath), $file->name);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -79,12 +84,15 @@ class ZipAction
|
||||
$zip->add(Storage::path($filePath), $zipDestination);
|
||||
}
|
||||
|
||||
// s3 client
|
||||
if (isStorageDriver('s3')) {
|
||||
$bucketName = config('filesystems.disks.s3.bucket');
|
||||
|
||||
$zip->add("s3://$bucketName/$filePath", $zipDestination);
|
||||
}
|
||||
|
||||
if (isStorageDriver('ftp')) {
|
||||
$zip->addRaw(Storage::get($filePath), $zipDestination);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -272,10 +272,8 @@ if (! function_exists('get_storage')) {
|
||||
if (! function_exists('isStorageDriver')) {
|
||||
/**
|
||||
* Check if is running AWS s3 as storage
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function isStorageDriver($driver)
|
||||
function isStorageDriver(string|array $driver): bool
|
||||
{
|
||||
if (is_array($driver)) {
|
||||
return in_array(config('filesystems.default'), $driver);
|
||||
|
||||
Reference in New Issue
Block a user