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
@@ -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');
}
}
+2
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,
];
/**
+34 -8
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;
}
}
/**
+21 -36
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'));
}
}
@@ -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();
+8 -8
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
+29 -3
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;
}
/**