You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
1.8 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
  4. use Illuminate\Foundation\Bus\DispatchesJobs;
  5. use Illuminate\Foundation\Validation\ValidatesRequests;
  6. use Illuminate\Routing\Controller as BaseController;
  7. use App\Models\Bucket;
  8. class BucketController extends BaseController
  9. {
  10. use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
  11. private function formatBytes($size, $precision = 1)
  12. {
  13. if ($size === 0) {
  14. return '0 bytes';
  15. }
  16. $base = log($size, 1024);
  17. $suffixes = array('bytes', 'kB', 'MB', 'G', 'T');
  18. return round(pow(1024, $base - floor($base)), $precision).' '.$suffixes[floor($base)];
  19. }
  20. /**
  21. *
  22. *
  23. * @return
  24. *
  25. */
  26. public function single($id)
  27. {
  28. // create bucket
  29. $bucket = Bucket::find($id);
  30. // getting files
  31. $files = FileManager::find($bucket->path);
  32. return view('bucket.single', [
  33. 'bucket' => $bucket,
  34. 'files' => $results
  35. ]);
  36. }
  37. /**
  38. *
  39. *
  40. * @return [type] [description]
  41. *
  42. */
  43. public function create()
  44. {
  45. return view('bucket.create');
  46. }
  47. /**
  48. *
  49. *
  50. */
  51. public function store()
  52. {
  53. $validated = request()->validate([
  54. 'name' => 'required|max:255',
  55. 'description' => 'max:255',
  56. 'path' => 'present',
  57. 'is_public' => 'boolean',
  58. ]);
  59. if ($validated) {
  60. // create bucket
  61. $bucket = Bucket::create($validated);
  62. return redirect()
  63. ->route('bucket.single', [ 'id' => $bucket->id ]);
  64. } else {
  65. return back()
  66. ->withInput();
  67. }
  68. }
  69. }