Au cas ou

This commit is contained in:
Lagacé Mathieu
2020-03-05 08:59:10 -05:00
parent baef9a1df0
commit 8189bbce9a
1843 changed files with 143778 additions and 90 deletions

View File

@@ -4,9 +4,11 @@ namespace App\Http\Controllers;
use App\Config;
use Illuminate\Http\Request;
use phpDocumentor\Reflection\Types\Boolean;
class ConfigController extends Controller
{
/**
* Display a listing of the resource.
*
@@ -132,7 +134,8 @@ class ConfigController extends Controller
public function showfilesConfig()
{
return view('admin.configs.file',['configs' => Config::all()]);
$error = [];
return view('admin.configs.file',['configs' => Config::all(),'error' => $error]);
}
public function editfilesConfig()

View File

@@ -4,6 +4,8 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Psy\Util\Str;
use Symfony\Component\Console\Input\Input;
class GoogleDriveController extends Controller
{
@@ -14,21 +16,32 @@ class GoogleDriveController extends Controller
* @param bool $recursive
* @return \Illuminate\Http\Response
*/
public function index($dir = '/',$recursive = true)
public function index($folder = '')
{
$contents = collect(Storage::cloud()->listContents($dir, $recursive));
return $contents->where('type', '=', 'file'); // files
return view('admin.files.Google Drive.index',['folder' => $folder]);
}
/**
* Show the form for creating a new resource.
* Show the form for creating a new file.
*
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\RedirectResponse
*/
public function create()
public function createFile()
{
//
Storage::cloud()->put(\request('currentDir'.'/'.\request('name')), '');
return back()->with('success','Fichier créer avec succès');
}
public function createFolder()
{
Storage::cloud()->makeDirectory(\request('currentDir').'/'.\request('name'));
return back()->with('success','Dossier créer avec succès');
}
public function uploadFile()
{
Storage::cloud()->putFileAs(\request('currentDir'),\request()->file('fichier'),\request()->file('fichier')->getClientOriginalName());
return back()->with('success','Fichier téléversé avec succès');
}
/**
@@ -53,7 +66,6 @@ class GoogleDriveController extends Controller
public function show()
{
$filename = \request('file');
$recursive = false; // Get subdirectories also?
$contents = collect(Storage::cloud()->listContents('/1nEe35-GvLX598RketTI-UoaOxIMNxfka', true));
$file = $contents
@@ -71,6 +83,23 @@ class GoogleDriveController extends Controller
->header('Content-Disposition', "attachment; filename='$filename'");
}
public function showMetadata($dir,$file)
{
if ($dir == 'root')
{
$dir = '/';
}
$contents = collect(Storage::cloud()->listContents($dir, true));
$file = $contents
->where('type', '=', 'file')
->where('filename', '=', pathinfo($file, PATHINFO_FILENAME))
->where('extension', '=', pathinfo($file, PATHINFO_EXTENSION))
->first(); // there can be duplicate file names!
return $file;
}
/**
* Show the form for editing the specified resource.
*
@@ -105,13 +134,199 @@ class GoogleDriveController extends Controller
//
}
public function list()
public function getPathArray()
{
$contents = collect(Storage::cloud()->listContents('/', true));
return json_encode($contents->where('type', '=', 'dir'));
}
public function getPath($folder)
{
$contents = collect(Storage::cloud()->listContents('/', true));
$dir = collect($contents->where('type', '=', 'dir'));
foreach ($dir as $d)
{
if($d['basename'] == $folder)
{
return $d['dirname'];
}
}
}
public function getFile()
{
if(\request('f'))
{
$dir = '/';
if (\request('d') && urldecode(\request('d')) != '')
{
$dir = \request('d');
}
$filename = urldecode(\request('f'));
$recursive = false; // Get subdirectories also?
$contents = collect(Storage::cloud()->listContents($dir, $recursive));
$file = $contents
->where('type', '=', 'file')
->where('filename', '=', pathinfo($filename, PATHINFO_FILENAME))
->first(); // there can be duplicate file names!
$rawData = Storage::cloud()->get($file['path']);
$filename = urlencode($filename);
return response($rawData, 200)
->header('Content-Type', $file['mimetype'])
->header('Content-Disposition', "attachment; filename=$filename");
}
else
{
abort(404);
}
}
public function deleteFile()
{
if(\request('f'))
{
$dir = '/';
if (\request('d') && urldecode(\request('d')) != '')
{
$dir = \request('d');
}
$filename = urldecode(\request('f'));
$recursive = false; // Get subdirectories also?
$contents = collect(Storage::cloud()->listContents($dir, $recursive));
$file = $contents
->where('type', '=', 'file')
->where('filename', '=', pathinfo($filename, PATHINFO_FILENAME))
->where('extension', '=', pathinfo($filename, PATHINFO_EXTENSION))
->first(); // there can be duplicate file names!
Storage::cloud()->delete($file['path']);
return back()->with('success','Fichier supprimé avec succès');
}
else
{
abort(404);
}
}
public function deleteDir()
{
$directoryID = \request('d');
// Now find that directory and use its ID (path) to delete it
$dir = '/';
$recursive = false; // Get subdirectories also?
$contents = collect(Storage::cloud()->listContents($dir, $recursive));
return view('admin.files.Google Drive.index',['directories' => $contents->where('type', '=', 'dir'), 'files' => $contents->where('type', '=', 'file')]);
//return $contents->where('type', '=', 'file'); // files
$directory = $contents
->where('type', '=', 'dir')
->where('basename', '=', $directoryID)
->first();
Storage::cloud()->deleteDirectory($directory['path']);
return back()->with('success','Dossier supprimé avec succès');
}
public function list($folder = 'root')
{
$recursive = false; // Get subdirectories also?
if ($folder == 'root')
{
$contents = collect(Storage::cloud()->listContents('/', $recursive));
}
else
{
$contents = collect(Storage::cloud()->listContents($folder, $recursive));
}
//dd($contents);
//$meta = collect(Storage::cloud()->listContents($folder, true));
//dd($meta);
return view('admin.files.Google Drive.explorer',['directories' => $contents->where('type', '=', 'dir')->sortByDesc('name'), 'files' => $contents->where('type', '=', 'file'), 'currentDir' => $folder]);
}
public function checkFileSystem()
{
$error = [];
if(\App\Config::getData('is_Google_Drive_enabled'))
{
$structure = $this->getFileStructure();
$this->checkStructure($structure,'/','/',$error);
}
return $error;
}
public function checkStructure($structure,$parent,$id,&$error)
{
$mydir = $this->listLockDirectory($id);
foreach ($structure as $key => $value)
{
$found = false;
$newDirID = null;
$p = null;
foreach ($mydir as $dir)
{
$p = $dir['basename'];
if ($dir['extension'] == $key)
{
$found = true;
$newDirID = $dir['basename'];
break;
}
}
if (!$found)
{
array_push($error,'Dossier 🔒.'.$key.' manquant... Le dossier a été créer');
\Storage::cloud()->createDir($parent.'/🔒.'.$key);
$tempdir = $this->listLockDirectory($parent);
$p = $tempdir->where('extension','=',$key)->first()['basename'];
}
if ($value != [])
{
$this->checkStructure($value,$p,$newDirID,$error);
}
}
}
public function getFileStructure()
{
return collect([
'Privé' => [
'Cadet' => [],
'ETAMAS' => [],
'Officier' => [],
'Staff' => [
'Guide' => []
]
],
'Publique' => [
'Fichier' => [],
'Image' => []
],
'Système' => [
'Fichier' => [],
'Image' => [
'Nouvelle' => [],
'Profil' => []
]
]
]);
}
public function listLockDirectory($d)
{
$contents = collect(\Storage::cloud()->listContents($d, false));
$dir = $contents->where('type', '=', 'dir');
$dir = $dir->where('filename','=','🔒');
return $dir;
}
}

View File

@@ -72,4 +72,36 @@ function clog(string $type,string $result,string $event,$user_id = null,$obj_typ
function clogNav($event)
{
clog('navigate','success',$event);
}
}
function GetSizeName($octet)
{
// Array contenant les differents unités
$unite = array('octet','ko','mo','go');
if ($octet < 1000) // octet
{
return $octet.' '.$unite[0];
}
else
{
if ($octet < 1000000) // ko
{
$ko = round($octet/1024,2);
return $ko.' '.$unite[1];
}
else // Mo ou Go
{
if ($octet < 1000000000) // Mo
{
$mo = round($octet/(1024*1024),2);
return $mo.' '.$unite[2];
}
else // Go
{
$go = round($octet/(1024*1024*1024),2);
return $go.' '.$unite[3];
}
}
}
}

View File

@@ -43,7 +43,11 @@ class AppServiceProvider extends ServiceProvider
});
Blade::directive('loaderDot', function () {
return '<div class="text-center"><div class="lds-ellipsis"><div></div><div></div><div></div><div></div></div></div>';
return '<div class="text-center"><div class="lds-ellipsis"><div></div><div></div><div></div><div></div></div></div>';
});
Blade::directive('loaderRipple', function () {
return '<div class="lds-ripple"><div></div><div></div></div>';
});
}