mirror of
https://gitlab.com/TheGamecraft/c-cms.git
synced 2026-04-21 02:39:10 -04:00
118 lines
3.0 KiB
PHP
118 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class GoogleDriveController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @param string $dir
|
|
* @param bool $recursive
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index($dir = '/',$recursive = true)
|
|
{
|
|
$contents = collect(Storage::cloud()->listContents($dir, $recursive));
|
|
|
|
return $contents->where('type', '=', 'file'); // files
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return bool
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$path = Storage::cloud()->makeDirectory('Test Dir');
|
|
dd($path);
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param $filename
|
|
* @return \Illuminate\Http\Response
|
|
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
|
|
*/
|
|
public function show()
|
|
{
|
|
$filename = \request('file');
|
|
$recursive = false; // Get subdirectories also?
|
|
$contents = collect(Storage::cloud()->listContents('/1nEe35-GvLX598RketTI-UoaOxIMNxfka', true));
|
|
|
|
$file = $contents
|
|
->where('type', '=', 'file')
|
|
->where('filename', '=', pathinfo($filename, PATHINFO_FILENAME))
|
|
->where('extension', '=', pathinfo($filename, PATHINFO_EXTENSION))
|
|
->first(); // there can be duplicate file names!
|
|
|
|
//return $file; // array with file info
|
|
|
|
$rawData = Storage::cloud()->get($file['path']);
|
|
|
|
return response($rawData, 200)
|
|
->header('ContentType', $file['mimetype'])
|
|
->header('Content-Disposition', "attachment; filename='$filename'");
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Request $request, $id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
//
|
|
}
|
|
|
|
public function list()
|
|
{
|
|
$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
|
|
}
|
|
}
|