v1.4.2 update

This commit is contained in:
carodej
2020-05-06 07:41:36 +02:00
parent b8b56584bd
commit edd0b5195d
18 changed files with 543 additions and 60 deletions

View File

@@ -6,6 +6,7 @@ APP_URL=http://localhost
LOG_CHANNEL=stack
SCOUT_DRIVER=tntsearch
FILESYSTEM_DRIVER=s3
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
@@ -38,6 +39,12 @@ AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
DO_SPACES_KEY=
DO_SPACES_SECRET=
DO_SPACES_ENDPOINT=
DO_SPACES_REGION=
DO_SPACES_BUCKET=
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=

BIN
.rnd

Binary file not shown.

View File

@@ -0,0 +1,117 @@
<?php
namespace App\Console\Commands;
use App\User;
use Illuminate\Console\Command;
class SetupDevEnvironment extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'setup:dev';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Setting production environment';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->info('Setting up production environment');
$this->migrateDatabase();
$this->generateKey();
$this->createPassportKeys();
$this->createPassportClientPassword();
$this->createPassportClientPersonal();
$this->createDefaultUser();
$this->info('Everything is done, congratulations! 🥳🥳🥳');
}
/**
* Migrate database
*/
public function generateKey()
{
$this->call('key:generate');
}
/**
* Migrate database
*/
public function migrateDatabase()
{
$this->call('migrate:fresh');
}
/**
* Create Passport Encryption keys
*/
public function createPassportKeys()
{
$this->call('passport:keys', [
'--force' => true
]);
}
/**
* Create Password grant client
*/
public function createPassportClientPassword()
{
$this->call('passport:client', [
'--password' => true,
'--name' => 'vuefilemanager',
]);
$this->alert('Please copy these first password grant Client ID & Client secret above to your /.env file.');
}
/**
* Create Personal access client
*/
public function createPassportClientPersonal()
{
$this->call('passport:client', [
'--personal' => true,
'--name' => 'shared',
]);
}
/**
* Create Default User
*/
public function createDefaultUser()
{
$user = User::create([
'name' => 'Jane Doe',
'email' => 'howdy@hi5ve.digital',
'password' => \Hash::make('secret'),
]);
$this->info('Test user created. Email: ' . $user->email . ' Password: secret');
}
}

View File

@@ -2,6 +2,7 @@
namespace App\Console;
use App\Console\Commands\SetupDevEnvironment;
use App\Console\Commands\SetupProductionEnvironment;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
@@ -15,6 +16,7 @@ class Kernel extends ConsoleKernel
*/
protected $commands = [
SetupProductionEnvironment::class,
SetupDevEnvironment::class,
];
/**

View File

@@ -4,6 +4,7 @@ namespace App;
use ByteUnits\Metric;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Laravel\Scout\Searchable;
use TeamTNT\TNTSearch\Indexer\TNTIndexer;
@@ -52,7 +53,6 @@ use \Illuminate\Database\Eloquent\SoftDeletes;
* @method static \Illuminate\Database\Query\Builder|\App\FileManagerFile withoutTrashed()
* @mixin \Eloquent
*/
class FileManagerFile extends Model
{
use Searchable, SoftDeletes;
@@ -72,7 +72,8 @@ class FileManagerFile extends Model
*
* @param $token
*/
public function setPublicUrl($token) {
public function setPublicUrl($token)
{
$this->public_access = $token;
}
@@ -93,7 +94,7 @@ class FileManagerFile extends Model
*/
public function getDeletedAtAttribute()
{
if (! $this->attributes['deleted_at']) return null;
if (!$this->attributes['deleted_at']) return null;
return format_date($this->attributes['deleted_at'], __('vuefilemanager.time'));
}
@@ -115,7 +116,14 @@ class FileManagerFile extends Model
*/
public function getThumbnailAttribute()
{
if ($this->attributes['thumbnail']) {
// Get thumbnail from s3
if ($this->attributes['thumbnail'] && is_storage_driver(['s3', 'spaces'])) {
return Storage::temporaryUrl('file-manager/' . $this->attributes['thumbnail'], now()->addDay());
}
// Get thumbnail from local storage
if ($this->attributes['thumbnail'] && is_storage_driver('local')) {
// Thumbnail route
$route = route('thumbnail', ['name' => $this->attributes['thumbnail']]);
@@ -137,13 +145,31 @@ class FileManagerFile extends Model
*/
public function getFileUrlAttribute()
{
$route = route('file', ['name' => $this->attributes['basename']]);
// Get file from s3
if (is_storage_driver(['s3', 'spaces'])) {
if ($this->public_access) {
return $route . '/public/' . $this->public_access;
$header = [
"ResponseAcceptRanges" => "bytes",
"ResponseContentType" => $this->attributes['mimetype'],
"ResponseContentLength" => $this->attributes['filesize'],
"ResponseContentRange" => "bytes 0-600/" . $this->attributes['filesize'],
'ResponseContentDisposition' => 'attachment; filename=' . $this->attributes['name'] . '.' . $this->attributes['mimetype'],
];
return Storage::temporaryUrl('file-manager/' . $this->attributes['basename'], now()->addDay(), $header);
}
return $route;
// Get thumbnail from local storage
if (is_storage_driver('local')) {
$route = route('file', ['name' => $this->attributes['basename']]);
if ($this->public_access) {
return $route . '/public/' . $this->public_access;
}
return $route;
}
}
/**

View File

@@ -11,6 +11,7 @@ use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File;
use Illuminate\Http\Request;
use App\FileManagerFile;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Response;
@@ -26,19 +27,13 @@ class FileAccessController extends Controller
public function get_avatar($basename)
{
// Get file path
$path = storage_path() . '/app/avatars/' . $basename;
$path = '/avatars/' . $basename;
// Check if file exist
if (!File::exists($path)) abort(404);
if (!Storage::exists($path)) abort(404);
$file = File::get($path);
$type = File::mimeType($path);
// Create response
$response = Response::make($file, 200);
$response->header("Content-Type", $type);
return $response;
// Return avatar
return Storage::download($path, $basename);
}
/**
@@ -61,7 +56,7 @@ class FileAccessController extends Controller
->firstOrFail();
// Check user permission
if ( ! $request->user()->tokenCan('master') ) {
if (!$request->user()->tokenCan('master')) {
// Get shared token
$shared = get_shared($request->cookie('shared_token'));
@@ -119,7 +114,7 @@ class FileAccessController extends Controller
->firstOrFail();
// Check user permission
if ( ! $request->user()->tokenCan('master') ) {
if (!$request->user()->tokenCan('master')) {
$this->check_file_access($request, $file);
}
@@ -187,24 +182,20 @@ class FileAccessController extends Controller
$file_pretty_name = $file->name . '.' . $file->mimetype;
// Get file path
$path = storage_path() . '/app/file-manager/' . $file->basename;
$path = '/file-manager/' . $file->basename;
// Check if file exist
if (!File::exists($path)) abort(404);
if (!Storage::exists($path)) abort(404);
$file = File::get($path);
$type = File::mimeType($path);
$size = File::size($path);
$header = [
"Content-Type" => Storage::mimeType($path),
"Content-Length" => Storage::size($path),
"Accept-Ranges" => "bytes",
"Content-Range" => "bytes 0-600/" . Storage::size($path),
];
// Create response
$response = Response::make($file, 200);
$response->header("Content-Type", $type);
$response->header("Content-Disposition", 'attachment; filename=' . $file_pretty_name);
$response->header("Content-Length", $size);
$response->header("Accept-Ranges", "bytes");
$response->header("Content-Range", "bytes 0-" . $size . "/" . $size);
return $response;
// Get file
return Storage::download($path, $file_pretty_name, $header);
}
/**
@@ -215,18 +206,12 @@ class FileAccessController extends Controller
private function thumbnail_file($file)
{
// Get file path
$path = storage_path() . '/app/file-manager/' . $file->getOriginal('thumbnail');
$path = '/file-manager/' . $file->getOriginal('thumbnail');
// Check if file exist
if (!File::exists($path)) abort(404);
if (!Storage::exists($path)) abort(404);
$file = File::get($path);
$type = File::mimeType($path);
// Create response
$response = Response::make($file, 200);
$response->header("Content-Type", $type);
return $response;
// Return image thumbnail
return Storage::download($path, $file->getOriginal('thumbnail'));
}
}

View File

@@ -39,10 +39,10 @@ class TrashController extends Controller
foreach ($files as $file) {
// Delete file
Storage::disk('local')->delete('/file-manager/' . $file->basename);
Storage::delete('/file-manager/' . $file->basename);
// Delete thumbnail if exist
if ($file->thumbnail) Storage::disk('local')->delete('/file-manager/' . $file->getOriginal('thumbnail'));
if ($file->thumbnail) Storage::delete('/file-manager/' . $file->getOriginal('thumbnail'));
// Delete file permanently
$file->forceDelete();

View File

@@ -121,10 +121,10 @@ class Editor
foreach ($files as $file) {
// Delete file
Storage::disk('local')->delete('/file-manager/' . $file->basename);
Storage::delete('/file-manager/' . $file->basename);
// Delete thumbnail if exist
if (!is_null($file->thumbnail)) Storage::disk('local')->delete('/file-manager/' . $file->getOriginal('thumbnail'));
if (!is_null($file->thumbnail)) Storage::delete('/file-manager/' . $file->getOriginal('thumbnail'));
// Delete file permanently
$file->forceDelete();
@@ -169,10 +169,10 @@ class Editor
if ($request->force_delete) {
// Delete file
Storage::disk('local')->delete('/file-manager/' . $file->basename);
Storage::delete('/file-manager/' . $file->basename);
// Delete thumbnail if exist
if ($file->thumbnail) Storage::disk('local')->delete('/file-manager/' . $file->getOriginal('thumbnail'));
if ($file->thumbnail) Storage::delete('/file-manager/' . $file->getOriginal('thumbnail'));
// Delete file permanently
$file->forceDelete();
@@ -213,12 +213,12 @@ class Editor
$thumbnail = null;
// create directory if not exist
if (!Storage::disk('local')->exists($directory)) {
Storage::disk('local')->makeDirectory($directory);
if (!Storage::exists($directory)) {
Storage::makeDirectory($directory);
}
// Store to disk
Storage::disk('local')->putFileAs($directory, $file, $filename, 'public');
Storage::putFileAs($directory, $file, $filename, 'private');
// Create image thumbnail
if ($filetype == 'image') {
@@ -235,7 +235,7 @@ class Editor
})->stream();
// Store thumbnail to disk
Storage::disk('local')->put($directory . '/' . $thumbnail, $image);
Storage::put($directory . '/' . $thumbnail, $image);
}
// Store file

View File

@@ -11,6 +11,29 @@ use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Intervention\Image\ImageManagerStatic as Image;
/**
* Get app version from config
*
* @return \Illuminate\Config\Repository|mixed
*/
function get_storage() {
return env('FILESYSTEM_DRIVER');
}
/**
* Check if is running AWS s3 as storage
*
* @return bool
*/
function is_storage_driver($driver) {
if (is_array($driver)) {
return in_array(env('FILESYSTEM_DRIVER'), $driver);
}
return env('FILESYSTEM_DRIVER') === $driver;
}
/**
* Get app version from config
*
@@ -111,16 +134,19 @@ function store_avatar($image, $path)
$path = check_directory($path);
// Store avatar
$image_path = $path . '/' . Str::random(8) . '-' . $image->getClientOriginalName();
$image_path = Str::random(8) . '-' . $image->getClientOriginalName();
// Create intervention image
$img = Image::make($image->getRealPath());
// Generate thumbnail
$img->fit('150', '150')->save(storage_path() . "/app/" . $image_path, 90);
$img->fit('150', '150')->stream();
// Store thumbnail to disk
Storage::put($path . '/' . $image_path, $img);
// Return path to image
return $image_path;
return $path . '/' . $image_path;
}
/**

View File

@@ -18,6 +18,8 @@
"laravel/passport": "^8.4",
"laravel/scout": "^7.2",
"laravel/tinker": "^2.0",
"league/flysystem-aws-s3-v3": "^1.0",
"league/flysystem-cached-adapter": "^1.0",
"teamtnt/laravel-scout-tntsearch-driver": "^7.2"
},
"require-dev": {

283
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "3e3a0dfbec5dd01d1b88b57db1c18bbf",
"content-hash": "dd291c7d30131e81dbca3d2127e2fc0d",
"packages": [
{
"name": "asm89/stack-cors",
@@ -58,6 +58,90 @@
],
"time": "2019-12-24T22:41:47+00:00"
},
{
"name": "aws/aws-sdk-php",
"version": "3.137.2",
"source": {
"type": "git",
"url": "https://github.com/aws/aws-sdk-php.git",
"reference": "af91c2fc467a326e5bcb5665e4e2ad3d84d28be2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/af91c2fc467a326e5bcb5665e4e2ad3d84d28be2",
"reference": "af91c2fc467a326e5bcb5665e4e2ad3d84d28be2",
"shasum": ""
},
"require": {
"ext-json": "*",
"ext-pcre": "*",
"ext-simplexml": "*",
"guzzlehttp/guzzle": "^5.3.3|^6.2.1|^7.0",
"guzzlehttp/promises": "^1.0",
"guzzlehttp/psr7": "^1.4.1",
"mtdowling/jmespath.php": "^2.5",
"php": ">=5.5"
},
"require-dev": {
"andrewsville/php-token-reflection": "^1.4",
"aws/aws-php-sns-message-validator": "~1.0",
"behat/behat": "~3.0",
"doctrine/cache": "~1.4",
"ext-dom": "*",
"ext-openssl": "*",
"ext-pcntl": "*",
"ext-sockets": "*",
"nette/neon": "^2.3",
"phpunit/phpunit": "^4.8.35|^5.4.3",
"psr/cache": "^1.0",
"psr/simple-cache": "^1.0",
"sebastian/comparator": "^1.2.3"
},
"suggest": {
"aws/aws-php-sns-message-validator": "To validate incoming SNS notifications",
"doctrine/cache": "To use the DoctrineCacheAdapter",
"ext-curl": "To send requests using cURL",
"ext-openssl": "Allows working with CloudFront private distributions and verifying received SNS messages",
"ext-sockets": "To use client-side monitoring"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.0-dev"
}
},
"autoload": {
"psr-4": {
"Aws\\": "src/"
},
"files": [
"src/functions.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "Amazon Web Services",
"homepage": "http://aws.amazon.com"
}
],
"description": "AWS SDK for PHP - Use Amazon Web Services in your PHP project",
"homepage": "http://aws.amazon.com/sdkforphp",
"keywords": [
"amazon",
"aws",
"cloud",
"dynamodb",
"ec2",
"glacier",
"s3",
"sdk"
],
"time": "2020-05-04T18:13:52+00:00"
},
{
"name": "defuse/php-encryption",
"version": "v2.2.1",
@@ -1880,6 +1964,100 @@
],
"time": "2020-04-16T13:21:26+00:00"
},
{
"name": "league/flysystem-aws-s3-v3",
"version": "1.0.24",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/flysystem-aws-s3-v3.git",
"reference": "4382036bde5dc926f9b8b337e5bdb15e5ec7b570"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/flysystem-aws-s3-v3/zipball/4382036bde5dc926f9b8b337e5bdb15e5ec7b570",
"reference": "4382036bde5dc926f9b8b337e5bdb15e5ec7b570",
"shasum": ""
},
"require": {
"aws/aws-sdk-php": "^3.0.0",
"league/flysystem": "^1.0.40",
"php": ">=5.5.0"
},
"require-dev": {
"henrikbjorn/phpspec-code-coverage": "~1.0.1",
"phpspec/phpspec": "^2.0.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"autoload": {
"psr-4": {
"League\\Flysystem\\AwsS3v3\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Frank de Jonge",
"email": "info@frenky.net"
}
],
"description": "Flysystem adapter for the AWS S3 SDK v3.x",
"time": "2020-02-23T13:31:58+00:00"
},
{
"name": "league/flysystem-cached-adapter",
"version": "1.0.9",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/flysystem-cached-adapter.git",
"reference": "08ef74e9be88100807a3b92cc9048a312bf01d6f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/flysystem-cached-adapter/zipball/08ef74e9be88100807a3b92cc9048a312bf01d6f",
"reference": "08ef74e9be88100807a3b92cc9048a312bf01d6f",
"shasum": ""
},
"require": {
"league/flysystem": "~1.0",
"psr/cache": "^1.0.0"
},
"require-dev": {
"mockery/mockery": "~0.9",
"phpspec/phpspec": "^3.4",
"phpunit/phpunit": "^5.7",
"predis/predis": "~1.0",
"tedivm/stash": "~0.12"
},
"suggest": {
"ext-phpredis": "Pure C implemented extension for PHP"
},
"type": "library",
"autoload": {
"psr-4": {
"League\\Flysystem\\Cached\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "frankdejonge",
"email": "info@frenky.net"
}
],
"description": "An adapter decorator to enable meta-data caching.",
"time": "2018-07-09T20:51:04+00:00"
},
{
"name": "league/oauth2-server",
"version": "8.1.0",
@@ -2038,6 +2216,63 @@
],
"time": "2019-12-20T14:22:59+00:00"
},
{
"name": "mtdowling/jmespath.php",
"version": "2.5.0",
"source": {
"type": "git",
"url": "https://github.com/jmespath/jmespath.php.git",
"reference": "52168cb9472de06979613d365c7f1ab8798be895"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/jmespath/jmespath.php/zipball/52168cb9472de06979613d365c7f1ab8798be895",
"reference": "52168cb9472de06979613d365c7f1ab8798be895",
"shasum": ""
},
"require": {
"php": ">=5.4.0",
"symfony/polyfill-mbstring": "^1.4"
},
"require-dev": {
"composer/xdebug-handler": "^1.2",
"phpunit/phpunit": "^4.8.36|^7.5.15"
},
"bin": [
"bin/jp.php"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.5-dev"
}
},
"autoload": {
"psr-4": {
"JmesPath\\": "src/"
},
"files": [
"src/JmesPath.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Declaratively specify how to extract elements from a JSON document",
"keywords": [
"json",
"jsonpath"
],
"time": "2019-12-30T18:03:34+00:00"
},
{
"name": "nesbot/carbon",
"version": "2.33.0",
@@ -2527,6 +2762,52 @@
],
"time": "2020-04-04T23:17:33+00:00"
},
{
"name": "psr/cache",
"version": "1.0.1",
"source": {
"type": "git",
"url": "https://github.com/php-fig/cache.git",
"reference": "d11b50ad223250cf17b86e38383413f5a6764bf8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/cache/zipball/d11b50ad223250cf17b86e38383413f5a6764bf8",
"reference": "d11b50ad223250cf17b86e38383413f5a6764bf8",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Cache\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for caching libraries",
"keywords": [
"cache",
"psr",
"psr-6"
],
"time": "2016-08-06T20:24:11+00:00"
},
{
"name": "psr/container",
"version": "1.0.0",

View File

@@ -64,6 +64,15 @@ return [
'url' => env('AWS_URL'),
],
'spaces' => [
'driver' => 's3',
'key' => env('DO_SPACES_KEY'),
'secret' => env('DO_SPACES_SECRET'),
'endpoint' => env('DO_SPACES_ENDPOINT'),
'region' => env('DO_SPACES_REGION'),
'bucket' => env('DO_SPACES_BUCKET'),
],
],
];

View File

@@ -2,7 +2,7 @@
return [
'version' => '1.4.1',
'version' => '1.4.2',
// Your app name
'app_name' => 'VueFileManager',

2
public/js/main.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -114,6 +114,14 @@ const Helpers = {
message: this.$t('popup_exceed_limit.message')
})
} else if (error.response.status === 413) {
events.$emit('alert:open', {
emoji: '😟',
title: this.$t('popup_paylod_error.title'),
message: this.$t('popup_paylod_error.message')
})
} else {
// Show error message
@@ -189,6 +197,14 @@ const Helpers = {
message: this.$t('popup_exceed_limit.message')
})
} else if (error.response.status === 413) {
events.$emit('alert:open', {
emoji: '😟',
title: this.$t('popup_paylod_error.title'),
message: this.$t('popup_paylod_error.message')
})
} else {
// Show error message

View File

@@ -221,5 +221,9 @@
"popup_signup_error": {
"title": "Server Error",
"message": "Please check your database connection if everything works correctly."
},
"popup_paylod_error": {
"title": "File is too large",
"message": "Sorry, your file is too large and can't be uploaded"
}
}

View File

@@ -221,5 +221,9 @@
"popup_signup_error": {
"title": "Server Error",
"message": "Please check your database connection if everything works correctly."
},
"popup_paylod_error": {
"title": "File is too large",
"message": "Sorry, your file is too large and can't be uploaded"
}
}

View File

@@ -221,5 +221,9 @@
"popup_signup_error": {
"title": "Chyba serveru",
"message": "Prosím skontrolujte databázove spojenie, či všetko funguje správne."
},
"popup_paylod_error": {
"title": "Súbor je príliš veľký",
"message": "Prepáčte, súbor je príliš veľký a nemôže byť nahraný."
}
}