Completed
Push — master ( 188ffb...31684b )
by Maxime
02:48
created

AssetController::getIndex()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 29
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 29
rs 8.5806
cc 4
eloc 16
nc 4
nop 1
1
<?php namespace Distilleries\Expendable\Http\Controllers\Frontend;
2
3
use Distilleries\Expendable\Http\Controllers\Frontend\Base\BaseController;
4
5
class AssetController extends BaseController {
6
7
    public function getIndex($path = '')
8
    {
9
10
        $directory   = explode('/', $path);
11
        $directory   = reset($directory);
12
        $white_liste = config('expendable.folder_whitelist');
13
        if (in_array($directory, $white_liste))
14
        {
15
            $path = storage_path($path);
16
            $filesystem = app('files');
17
            if ($filesystem->isFile($path))
18
            {
19
                $mimetype = mime_content_type($path);
20
                if (@is_array(getimagesize($path)))
21
                {
22
                    return response()->make($filesystem->get($path), 200, array('content-type' => $mimetype));
23
                } else
24
                {
25
                    $name = explode('/', $path);
26
                    $name = end($name);
27
28
                    return response()->download($path, $name, array('content-type' => $mimetype));
29
                }
30
            }
31
        }
32
33
34
        return abort(404);
35
    }
36
}