<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
|
use Illuminate\Foundation\Bus\DispatchesJobs;
|
|
use Illuminate\Foundation\Validation\ValidatesRequests;
|
|
use Illuminate\Routing\Controller as BaseController;
|
|
|
|
use App\Models\Bucket;
|
|
|
|
class BucketController extends BaseController
|
|
{
|
|
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
|
|
|
private function formatBytes($size, $precision = 1)
|
|
{
|
|
if ($size === 0) {
|
|
return '0 bytes';
|
|
}
|
|
|
|
$base = log($size, 1024);
|
|
$suffixes = array('bytes', 'kB', 'MB', 'G', 'T');
|
|
|
|
return round(pow(1024, $base - floor($base)), $precision).' '.$suffixes[floor($base)];
|
|
}
|
|
|
|
/**
|
|
*
|
|
*
|
|
* @return
|
|
*
|
|
*/
|
|
public function single($id)
|
|
{
|
|
// create bucket
|
|
$bucket = Bucket::find($id);
|
|
|
|
// getting files
|
|
$files = FileManager::find($bucket->path);
|
|
|
|
return view('bucket.single', [
|
|
'bucket' => $bucket,
|
|
'files' => $results
|
|
]);
|
|
}
|
|
|
|
/**
|
|
*
|
|
*
|
|
* @return [type] [description]
|
|
*
|
|
*/
|
|
public function create()
|
|
{
|
|
return view('bucket.create');
|
|
}
|
|
|
|
/**
|
|
*
|
|
*
|
|
*/
|
|
public function store()
|
|
{
|
|
$validated = request()->validate([
|
|
'name' => 'required|max:255',
|
|
'description' => 'max:255',
|
|
'path' => 'present',
|
|
'is_public' => 'boolean',
|
|
]);
|
|
|
|
if ($validated) {
|
|
|
|
// create bucket
|
|
$bucket = Bucket::create($validated);
|
|
|
|
return redirect()
|
|
->route('bucket.single', [ 'id' => $bucket->id ]);
|
|
} else {
|
|
return back()
|
|
->withInput();
|
|
}
|
|
}
|
|
}
|