Recent changes
This commit is contained in:
parent
06d1e0ad3f
commit
96aa01b9c6
|
@ -7,6 +7,10 @@ APP_LOGO="https://www.raspberrypi.org/app/uploads/2020/05/Raspberry-Pi-OS-downlo
|
|||
APP_SITEHOMEPAGE=""
|
||||
# This can be your main homepage, other than this site itself
|
||||
|
||||
# Forces ssl connections even if the environment is set to "local".
|
||||
# Void if env is production.
|
||||
NONPROD_FORCE_SECURE=false
|
||||
|
||||
LOG_CHANNEL=stack
|
||||
|
||||
DB_CONNECTION=mysql
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace App\Facades;
|
||||
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
class DigitalStorageHelper extends Facade
|
||||
{
|
||||
|
||||
protected static function getFacadeAccessor()
|
||||
{
|
||||
return 'digitalStorageHelperFacadeRoot';
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
/**
|
||||
* Class DigitalStorageHelper
|
||||
*
|
||||
* The digital storage helper class helps you convert bytes into several other units.
|
||||
* It should be used whenever you need to display a file's size in a human readable way.
|
||||
*
|
||||
* It's framework agnostic, meaning you can take it out of context and it'll still work; However, you'll have to instantiate it first.
|
||||
* @package App\Helpers
|
||||
*/
|
||||
class DigitalStorageHelper
|
||||
{
|
||||
|
||||
/**
|
||||
* The digital storage value to be manipulated.
|
||||
* @var $value
|
||||
*/
|
||||
protected $value;
|
||||
|
||||
|
||||
/**
|
||||
* Sets the digital storage value for manipulation.
|
||||
*
|
||||
* @param int $value The digital storage value in bytes
|
||||
* @return $this The current instance
|
||||
*/
|
||||
public function setValue(int $value): DigitalStorageHelper
|
||||
{
|
||||
$this->value = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Converts the digital storage value to kilobytes.
|
||||
*
|
||||
* @return float|int
|
||||
*/
|
||||
public function toKilobytes(): float
|
||||
{
|
||||
return $this->value / 1000;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Converts the digital storage value to megabytes.
|
||||
*
|
||||
* @return float|int
|
||||
*/
|
||||
public function toMegabytes(): float
|
||||
{
|
||||
return $this->value / (1 * pow(10, 6)); // 1 times 10 to the power of 6
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert the digital storage value to gigabytes. Might be an approximation
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function toGigabytes(): float
|
||||
{
|
||||
return $this->value / (1 * pow(10, 9));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert the digital storage value to terabytes.
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function toTerabytes(): float
|
||||
{
|
||||
return $this->value / (1 * pow(10, 12));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Format the digital storage value to one of the units: b, kb, mb, gb and tb.
|
||||
* The method has been adapted to use both MiB and MB values.
|
||||
*
|
||||
* @param int $precision The rounding precision
|
||||
* @param bool $si Use international system units. Defaults to false
|
||||
* @return string The human readable digital storage value, in either, for instance, MB or MiB
|
||||
* @see https://stackoverflow.com/a/2510459/11540218 StackOverflow question regarding unit conversion
|
||||
* @since 7.3.23
|
||||
*/
|
||||
public function formatBytes($precision = 2, $si = false): string
|
||||
{
|
||||
$units = ['B', 'KiB', 'MiB', 'GiB', 'TiB'];
|
||||
if ($si)
|
||||
$units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||
|
||||
$bytes = max($this->value, 0);
|
||||
$pow = floor(($bytes ? log($bytes) : 0) / log(($si) ? 1000 : 1024));
|
||||
$pow = min($pow, count($units) - 1);
|
||||
|
||||
$bytes /= pow(($si) ? 1000 : 1024, $pow);
|
||||
|
||||
return round($bytes, $precision) . ' ' . $units[$pow];
|
||||
}
|
||||
|
||||
}
|
|
@ -2,11 +2,25 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
// Most of these namespaces have no effect on the code, however, they're used by IDEs so they can resolve return types and for PHPDocumentor as well
|
||||
|
||||
|
||||
use App\TeamFile;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Requests\UploadFileRequest;
|
||||
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use League\Flysystem\FileNotFoundException;
|
||||
// Documentation-purpose namespaces
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contts\View\Factory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
|
||||
|
||||
class TeamFileController extends Controller
|
||||
{
|
||||
|
@ -14,7 +28,7 @@ class TeamFileController extends Controller
|
|||
* Display a listing of the resource.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Http\Response
|
||||
* @return Application|Factory|View|Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
|
@ -25,28 +39,45 @@ class TeamFileController extends Controller
|
|||
}
|
||||
|
||||
return view('dashboard.teams.team-files')
|
||||
->with('files', TeamFile::with('team', 'uploader')->paginate(20));
|
||||
->with('files', TeamFile::with('team', 'uploader')->paginate(6));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 \Illuminate\Http\Response
|
||||
* @param UploadFileRequest $request
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
public function store(UploadFileRequest $request)
|
||||
{
|
||||
//
|
||||
$upload = $request->file('file');
|
||||
|
||||
$file = $upload->store('uploads');
|
||||
$originalFileName = $upload->getClientOriginalName();
|
||||
$originalFileExtension = $upload->extension();
|
||||
$originalFileSize = $upload->getSize();
|
||||
|
||||
$fileEntry = TeamFile::create([
|
||||
'uploaded_by' => Auth::user()->id,
|
||||
'team_id' => Auth::user()->currentTeam->id,
|
||||
'name' => $originalFileName,
|
||||
'caption' => $request->caption,
|
||||
'description' => $request->description,
|
||||
'fs_location' => $file,
|
||||
'extension' => $originalFileExtension,
|
||||
'size' => $originalFileSize
|
||||
]);
|
||||
|
||||
if ($fileEntry && !is_bool($file))
|
||||
{
|
||||
$request->session()->flash('success', 'File uploaded successfully!');
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
$request->session()->flash('error', 'There was an unknown error whilst trying to upload your file.');
|
||||
return redirect()->back();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -54,7 +85,7 @@ class TeamFileController extends Controller
|
|||
{
|
||||
try
|
||||
{
|
||||
return Storage::download('uploads/' . $teamFile->name);
|
||||
return Storage::download($teamFile->fs_location, $teamFile->name);
|
||||
}
|
||||
catch (FileNotFoundException $ex)
|
||||
{
|
||||
|
@ -64,22 +95,11 @@ class TeamFileController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\TeamFile $teamFile
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(TeamFile $teamFile)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\TeamFile $teamFile
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return Response
|
||||
*/
|
||||
public function edit(TeamFile $teamFile)
|
||||
{
|
||||
|
@ -91,7 +111,7 @@ class TeamFileController extends Controller
|
|||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\TeamFile $teamFile
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return Response
|
||||
*/
|
||||
public function update(Request $request, TeamFile $teamFile)
|
||||
{
|
||||
|
@ -101,11 +121,25 @@ class TeamFileController extends Controller
|
|||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param \App\TeamFile $teamFile
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function destroy(TeamFile $teamFile)
|
||||
public function destroy(Request $request, TeamFile $teamFile)
|
||||
{
|
||||
//
|
||||
|
||||
try
|
||||
{
|
||||
Storage::delete($teamFile->fs_location);
|
||||
$teamFile->delete();
|
||||
|
||||
$request->session()->flash('success', 'File deleted successfully.');
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
{
|
||||
$request->session()->flash('error', 'There was an error deleting the file: ' . $ex->getMessage());
|
||||
}
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue