v1.5-alpha.9

This commit is contained in:
carodej
2020-05-18 09:32:34 +02:00
parent 8daa05f710
commit dfe4991177
12 changed files with 102 additions and 19 deletions

View File

@@ -18,6 +18,7 @@ use App\FileManagerFolder;
use App\FileManagerFile;
use App\User;
use App\Share;
use Illuminate\Support\Facades\Storage;
class FileSharingController extends Controller
{
@@ -47,10 +48,51 @@ class FileSharingController extends Controller
Cookie::queue('shared_token', $token, 43200);
}
// Check if shared is image file and then show it
if ($shared->type === 'file' && ! $shared->protected) {
$image = FileManagerFile::where('user_id', $shared->user_id)
->where('type', 'image')
->where('unique_id', $shared->item_id)
->first();
if ($image) {
return $this->show_image($image);
}
}
// Return page index
return view("index");
}
/**
* Get image from storage and show it
*
* @param $file
* @return \Symfony\Component\HttpFoundation\StreamedResponse
*/
private function show_image($file)
{
// Format pretty filename
$file_pretty_name = $file->name . '.' . $file->mimetype;
// Get file path
$path = '/file-manager/' . $file->basename;
// Check if file exist
if (!Storage::exists($path)) abort(404);
$header = [
"Content-Type" => Storage::mimeType($path),
"Content-Length" => Storage::size($path),
"Accept-Ranges" => "bytes",
"Content-Range" => "bytes 0-600/" . Storage::size($path),
];
// Get file
return Storage::response($path, $file_pretty_name, $header);
}
/**
* Check Password for protected item
*

View File

@@ -28,10 +28,10 @@ class AccountController extends Controller
->first();
// Get folder tree
$tree = FileManagerFolder::with('folders:id,parent_id,unique_id,name')
$tree = FileManagerFolder::with(['folders.shared', 'shared:token,id,item_id,permission,protected'])
->where('parent_id', 0)
->where('user_id', $user->id)
->get(['id', 'parent_id', 'unique_id', 'name']);
->get();
return [
'user' => $user->only(['name', 'email', 'avatar']),