mirror of
https://gitlab.com/TheGamecraft/c-cms.git
synced 2026-04-21 02:39:10 -04:00
Au cas ou
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user