Passed
Branch master (3256e3)
by Georgi
04:17
created
src/FileStorageController.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -7,49 +7,49 @@
 block discarded – undo
7 7
 
8 8
 class FileStorageController extends Controller
9 9
 {
10
-    public function get(Request $request)
11
-    {
12
-    	try {
13
-    		$meta = Database\Models\Meta::get($request->get('id'));
14
-    	} catch (\Exception $e) {
15
-    		abort(404);
16
-    	}
10
+	public function get(Request $request)
11
+	{
12
+		try {
13
+			$meta = Database\Models\Meta::get($request->get('id'));
14
+		} catch (\Exception $e) {
15
+			abort(404);
16
+		}
17 17
     	
18
-    	$useThumbnail = false;
19
-    	$disposition = 'attachment';
20
-    	switch ($request->get('action')) {	
21
-    		case 'preview':
22
-    			$useThumbnail = true;
23
-    		case 'inline':
24
-    			$disposition = 'inline';
25
-    			break;
18
+		$useThumbnail = false;
19
+		$disposition = 'attachment';
20
+		switch ($request->get('action')) {	
21
+			case 'preview':
22
+				$useThumbnail = true;
23
+			case 'inline':
24
+				$disposition = 'inline';
25
+				break;
26 26
     			
27
-    		default:
28
-    			break;
29
-    	}
27
+			default:
28
+				break;
29
+		}
30 30
 
31
-    	if ($useThumbnail && $request->get('thumbnail', 1) && ($thumbnail = $meta->thumbnail)) {
32
-    		$mime = $thumbnail['mime'];
33
-    		$filename = $thumbnail['name'];
34
-    		$contents = $thumbnail['contents'];
35
-    	}
36
-    	else {
37
-    		$mime = $meta->file->type;
38
-    		$filename = $meta->name;
39
-    		$contents = $meta->file->contents;
40
-    	}
31
+		if ($useThumbnail && $request->get('thumbnail', 1) && ($thumbnail = $meta->thumbnail)) {
32
+			$mime = $thumbnail['mime'];
33
+			$filename = $thumbnail['name'];
34
+			$contents = $thumbnail['contents'];
35
+		}
36
+		else {
37
+			$mime = $meta->file->type;
38
+			$filename = $meta->name;
39
+			$contents = $meta->file->contents;
40
+		}
41 41
 
42
-    	$headers = [
43
-    			'Content-Type' => $mime,
44
-    			'Content-Length' => strlen($contents),
45
-    			'Content-Disposition' => "$disposition; filename=\"$filename\"",
46
-    	];
42
+		$headers = [
43
+				'Content-Type' => $mime,
44
+				'Content-Length' => strlen($contents),
45
+				'Content-Disposition' => "$disposition; filename=\"$filename\"",
46
+		];
47 47
 
48
-    	if ($request->get('nocache')) {
49
-    		$headers['Pragma'] = 'no-cache';
50
-    		$headers['Expires'] = '0';
51
-    	}
48
+		if ($request->get('nocache')) {
49
+			$headers['Pragma'] = 'no-cache';
50
+			$headers['Expires'] = '0';
51
+		}
52 52
     	
53
-    	return response($contents, 200, $headers);
54
-    }
53
+		return response($contents, 200, $headers);
54
+	}
55 55
 }
Please login to merge, or discard this patch.
src/FileStorageAccess.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -6,30 +6,30 @@
 block discarded – undo
6 6
 
7 7
 class FileStorageAccess
8 8
 {
9
-    public function handle($request, \Closure $next)
10
-    {
11
-    	foreach (Integration\Joints\FileStorageAccessJoint::collect() as $joint) {
12
-    		if ($joint->accessGranted($request)) {    			
13
-    			$this->logFileAccess($request->get('id'), $request->get('action', 'download'));
9
+	public function handle($request, \Closure $next)
10
+	{
11
+		foreach (Integration\Joints\FileStorageAccessJoint::collect() as $joint) {
12
+			if ($joint->accessGranted($request)) {    			
13
+				$this->logFileAccess($request->get('id'), $request->get('action', 'download'));
14 14
     			
15
-    			return $next($request);
16
-    		}
17
-    	}
15
+				return $next($request);
16
+			}
17
+		}
18 18
     	
19
-    	return response('No access to file', 401);
20
-    }
19
+		return response('No access to file', 401);
20
+	}
21 21
         
22
-    protected function logFileAccess($metaId, $action, $time = null)
23
-    {
24
-    	$ip_address = request()->ip();
22
+	protected function logFileAccess($metaId, $action, $time = null)
23
+	{
24
+		$ip_address = request()->ip();
25 25
 
26
-    	Database\Models\AccessLog::create([
27
-    			'meta_id' => $metaId,
28
-    			'accessed_at' => date('Y-m-d H:i:s', $time ?: time()),
29
-    			'accessed_by' => Auth::id() ?: 0,
30
-    			'action' => $action,
31
-    			'ip_address' => $ip_address,
32
-    			'host_name' => gethostbyaddr($ip_address)
33
-    	]);
34
-    }
26
+		Database\Models\AccessLog::create([
27
+				'meta_id' => $metaId,
28
+				'accessed_at' => date('Y-m-d H:i:s', $time ?: time()),
29
+				'accessed_by' => Auth::id() ?: 0,
30
+				'action' => $action,
31
+				'ip_address' => $ip_address,
32
+				'host_name' => gethostbyaddr($ip_address)
33
+		]);
34
+	}
35 35
 }
Please login to merge, or discard this patch.
src/Database/Models/File.php 1 patch
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -13,111 +13,111 @@
 block discarded – undo
13 13
 	
14 14
 	public $timestamps = false;
15 15
 	
16
-    protected $table = 'filestorage_files';
17
-    protected static $unguarded = true;    
16
+	protected $table = 'filestorage_files';
17
+	protected static $unguarded = true;    
18 18
     
19
-    protected $appends = ['path'];
19
+	protected $appends = ['path'];
20 20
     
21
-    /**
22
-     * One file can have many meta datas
23
-     * The actual content is stored only once based on the content hash
24
-     * 
25
-     * @return \Illuminate\Database\Eloquent\Relations\HasMany
26
-     */
27
-    public function meta()
28
-    {
29
-    	return $this->hasMany(Meta::class, 'file_id');
30
-    }
21
+	/**
22
+	 * One file can have many meta datas
23
+	 * The actual content is stored only once based on the content hash
24
+	 * 
25
+	 * @return \Illuminate\Database\Eloquent\Relations\HasMany
26
+	 */
27
+	public function meta()
28
+	{
29
+		return $this->hasMany(Meta::class, 'file_id');
30
+	}
31 31
     
32
-    /**
33
-     * Accessor method for retrieving of file content path when using the model
34
-     * Having the $appends property in the File model listing the 'path' makes sure the value is also exported to arrays
35
-     * 
36
-     * @return string
37
-     */
38
-    public function getPathAttribute()
39
-    {
40
-    	return self::storage()->path($this->getStoragePath($this->hash));
41
-    }
32
+	/**
33
+	 * Accessor method for retrieving of file content path when using the model
34
+	 * Having the $appends property in the File model listing the 'path' makes sure the value is also exported to arrays
35
+	 * 
36
+	 * @return string
37
+	 */
38
+	public function getPathAttribute()
39
+	{
40
+		return self::storage()->path($this->getStoragePath($this->hash));
41
+	}
42 42
     
43
-    /**
44
-     * Accessor method for retrieving of file contents
45
-     * 
46
-     * @return string
47
-     */
48
-    public function getContentsAttribute()
49
-    {
50
-    	return self::storage()->get($this->storage_path);
51
-    }
43
+	/**
44
+	 * Accessor method for retrieving of file contents
45
+	 * 
46
+	 * @return string
47
+	 */
48
+	public function getContentsAttribute()
49
+	{
50
+		return self::storage()->get($this->storage_path);
51
+	}
52 52
     
53
-    /**
54
-     * Accessor method for file relative storage path
55
-     * 
56
-     * @return string
57
-     */
58
-    public function getStoragePathAttribute()
59
-    {
60
-    	return $this->getStoragePath($this->hash);
61
-    }
53
+	/**
54
+	 * Accessor method for file relative storage path
55
+	 * 
56
+	 * @return string
57
+	 */
58
+	public function getStoragePathAttribute()
59
+	{
60
+		return $this->getStoragePath($this->hash);
61
+	}
62 62
     
63
-    protected static function getStoragePath($hash)
64
-    {
65
-    	return implode(DIRECTORY_SEPARATOR, array_merge(str_split(substr($hash, 0, 5)), [substr($hash, 5)]));
66
-    }
63
+	protected static function getStoragePath($hash)
64
+	{
65
+		return implode(DIRECTORY_SEPARATOR, array_merge(str_split(substr($hash, 0, 5)), [substr($hash, 5)]));
66
+	}
67 67
     
68
-    /**
69
-     * Returns the storage where file contents are saved based on config settings
70
-     * 
71
-     * @return \Illuminate\Contracts\Filesystem\Filesystem
72
-     */
73
-    public static function storage()
74
-    {
75
-    	return Storage::disk(config('epesi.filestorage', 'local'));
76
-    }
68
+	/**
69
+	 * Returns the storage where file contents are saved based on config settings
70
+	 * 
71
+	 * @return \Illuminate\Contracts\Filesystem\Filesystem
72
+	 */
73
+	public static function storage()
74
+	{
75
+		return Storage::disk(config('epesi.filestorage', 'local'));
76
+	}
77 77
         
78
-    /**
79
-     * Add file to the filestorage
80
-     *
81
-     * @param string $file File path to save
82
-     *
83
-     * @return int File id in the database
84
-     */
85
-    public static function putDataFromFile($file)
86
-    {
87
-    	return self::putData(file_get_contents($file));
88
-    }
78
+	/**
79
+	 * Add file to the filestorage
80
+	 *
81
+	 * @param string $file File path to save
82
+	 *
83
+	 * @return int File id in the database
84
+	 */
85
+	public static function putDataFromFile($file)
86
+	{
87
+		return self::putData(file_get_contents($file));
88
+	}
89 89
     
90
-    /**
91
-     * Add content to the filestorage
92
-     *
93
-     * @param string $content Content to save
94
-     *
95
-     * @return int File id in the database
96
-     */
97
-    public static function putData($content)
98
-    {
99
-    	$hash = self::hashContent($content);
90
+	/**
91
+	 * Add content to the filestorage
92
+	 *
93
+	 * @param string $content Content to save
94
+	 *
95
+	 * @return int File id in the database
96
+	 */
97
+	public static function putData($content)
98
+	{
99
+		$hash = self::hashContent($content);
100 100
     	
101
-    	$path = self::getStoragePath($hash);
101
+		$path = self::getStoragePath($hash);
102 102
     	
103
-    	if (! self::storage()->exists($path)) {
104
-    		self::storage()->put($path, $content);
105
-    	}
103
+		if (! self::storage()->exists($path)) {
104
+			self::storage()->put($path, $content);
105
+		}
106 106
     	
107
-    	return self::firstOrCreate(compact('hash'), [
108
-    			'size' => self::storage()->size($path),
109
-    			'type' => self::storage()->mimeType($path)
110
-    	])->id;
111
-    }
107
+		return self::firstOrCreate(compact('hash'), [
108
+				'size' => self::storage()->size($path),
109
+				'type' => self::storage()->mimeType($path)
110
+		])->id;
111
+	}
112 112
     
113
-    /**
114
-     * Get the hash of the content using hash method defined as constant to the class
115
-     * 
116
-     * @param string $content
117
-     * @return string
118
-     */
119
-    public static function hashContent($content)
120
-    {
121
-    	return hash(self::HASH_METHOD, $content);
122
-    }
113
+	/**
114
+	 * Get the hash of the content using hash method defined as constant to the class
115
+	 * 
116
+	 * @param string $content
117
+	 * @return string
118
+	 */
119
+	public static function hashContent($content)
120
+	{
121
+		return hash(self::HASH_METHOD, $content);
122
+	}
123 123
 }
124 124
\ No newline at end of file
Please login to merge, or discard this patch.
src/Database/Models/Meta.php 1 patch
Indentation   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -15,205 +15,205 @@
 block discarded – undo
15 15
 {
16 16
 	use SoftDeletes;
17 17
 	
18
-    protected $table = 'filestorage_meta';
19
-    protected static $unguarded = true;
18
+	protected $table = 'filestorage_meta';
19
+	protected static $unguarded = true;
20 20
     
21
-    public function file()
22
-    {
23
-    	return $this->belongsTo(File::class, 'file_id');
24
-    }
21
+	public function file()
22
+	{
23
+		return $this->belongsTo(File::class, 'file_id');
24
+	}
25 25
     
26
-    /**
27
-     * Retrieve meta info about the file
28
-     *
29
-     * @param int|string $idOrLink Filestorage ID or unique link string
30
-     * @param bool $useCache Use cache or not
31
-     *
32
-     * @return array Metadata about the file.
33
-     *               Keys in array: hash, file, filename, link, backref,
34
-     *               created_at, created_by, deleted, file_id
35
-     * @throws FileNotFound
36
-     * @throws StorageNotFound
37
-     */
38
-    public static function get($idOrLink, $useCache = true)
39
-    {
40
-    	static $cache = [];
26
+	/**
27
+	 * Retrieve meta info about the file
28
+	 *
29
+	 * @param int|string $idOrLink Filestorage ID or unique link string
30
+	 * @param bool $useCache Use cache or not
31
+	 *
32
+	 * @return array Metadata about the file.
33
+	 *               Keys in array: hash, file, filename, link, backref,
34
+	 *               created_at, created_by, deleted, file_id
35
+	 * @throws FileNotFound
36
+	 * @throws StorageNotFound
37
+	 */
38
+	public static function get($idOrLink, $useCache = true)
39
+	{
40
+		static $cache = [];
41 41
 
42
-    	$id = self::getIdByLink($idOrLink, true, true);
42
+		$id = self::getIdByLink($idOrLink, true, true);
43 43
 
44
-    	if ($useCache && isset($cache[$id])) {
45
-    		return $cache[$id];
46
-    	}
44
+		if ($useCache && isset($cache[$id])) {
45
+			return $cache[$id];
46
+		}
47 47
 
48
-    	if (! $meta = self::with('file')->find($id)) {
49
-    		throw new StorageNotFound('Exception - DB storage object not found: ' . $id);
50
-    	}
48
+		if (! $meta = self::with('file')->find($id)) {
49
+			throw new StorageNotFound('Exception - DB storage object not found: ' . $id);
50
+		}
51 51
 
52
-    	if (empty($meta->file['hash'])) {
53
-    		throw new FileNotFound('File object does not have corresponding file hash');
54
-    	}
52
+		if (empty($meta->file['hash'])) {
53
+			throw new FileNotFound('File object does not have corresponding file hash');
54
+		}
55 55
 
56
-    	return $cache[$id] = $meta;
57
-    }
56
+		return $cache[$id] = $meta;
57
+	}
58 58
     
59
-    /**
60
-     * Get Filestorage ID by link
61
-     *
62
-     * @param string $link            Unique link
63
-     * @param bool   $useCache       Use cache or not
64
-     * @param bool   $throwException Throw exception if link is not found
65
-     *
66
-     * @return int Filestorage ID
67
-     * @throws LinkNotFound
68
-     */
69
-    public static function getIdByLink($link, $useCache = true, $throwException = false)
70
-    {
71
-    	static $cache = [];
59
+	/**
60
+	 * Get Filestorage ID by link
61
+	 *
62
+	 * @param string $link            Unique link
63
+	 * @param bool   $useCache       Use cache or not
64
+	 * @param bool   $throwException Throw exception if link is not found
65
+	 *
66
+	 * @return int Filestorage ID
67
+	 * @throws LinkNotFound
68
+	 */
69
+	public static function getIdByLink($link, $useCache = true, $throwException = false)
70
+	{
71
+		static $cache = [];
72 72
     	
73
-    	if (is_numeric($link)) return $link;
73
+		if (is_numeric($link)) return $link;
74 74
     	
75
-    	if (!$useCache || !isset($cache[$link])) {
76
-    		$cache[$link] = self::where('link', $link)->value('id');
75
+		if (!$useCache || !isset($cache[$link])) {
76
+			$cache[$link] = self::where('link', $link)->value('id');
77 77
     		
78
-    		if (!$cache[$link] && $throwException) {
79
-    			throw new LinkNotFound($link);
80
-    		}
81
-    	}
78
+			if (!$cache[$link] && $throwException) {
79
+				throw new LinkNotFound($link);
80
+			}
81
+		}
82 82
     	
83
-    	return $cache[$link];
84
-    }
83
+		return $cache[$link];
84
+	}
85 85
 
86
-    /**
87
-     * Mark file as deleted. Does not remove any content!
88
-     *
89
-     * @param int|string $idOrLink Filestorage ID or unique link
90
-     */
91
-    public static function deleteFile($idOrLink)
92
-    {
86
+	/**
87
+	 * Mark file as deleted. Does not remove any content!
88
+	 *
89
+	 * @param int|string $idOrLink Filestorage ID or unique link
90
+	 */
91
+	public static function deleteFile($idOrLink)
92
+	{
93 93
    		if ($id = self::getIdByLink($idOrLink, false)) {
94 94
    			self::find($id)->delete();
95
-    	}
96
-    }
95
+		}
96
+	}
97 97
     
98
-    /**
99
-     * Check if file exists
100
-     *
101
-     * @param int|static $idOrMeta              Filestorage ID or meta object
102
-     * @param bool      $throwException Throw exception on missing file or return false
103
-     *
104
-     * @return bool True if file exists, false otherwise
105
-     * @throws FileNotFound May be thrown if $throwException set to true
106
-     */
107
-    public static function fileExists($idOrMeta, $throwException = false)
108
-    {
109
-    	try {
110
-    		$meta = is_numeric($idOrMeta) ? self::get($idOrMeta) : $idOrMeta;
98
+	/**
99
+	 * Check if file exists
100
+	 *
101
+	 * @param int|static $idOrMeta              Filestorage ID or meta object
102
+	 * @param bool      $throwException Throw exception on missing file or return false
103
+	 *
104
+	 * @return bool True if file exists, false otherwise
105
+	 * @throws FileNotFound May be thrown if $throwException set to true
106
+	 */
107
+	public static function fileExists($idOrMeta, $throwException = false)
108
+	{
109
+		try {
110
+			$meta = is_numeric($idOrMeta) ? self::get($idOrMeta) : $idOrMeta;
111 111
     		
112
-    		if (! file_exists($meta->file->path)) {
113
-    			throw new FileNotFound('Exception - file not found: ' . $meta->file->path);
114
-    		}
115
-    	} catch (\Exception $exception) {
116
-    		if ($throwException)
117
-    			throw $exception;
118
-    		else
119
-    			return false;
120
-    	}
112
+			if (! file_exists($meta->file->path)) {
113
+				throw new FileNotFound('Exception - file not found: ' . $meta->file->path);
114
+			}
115
+		} catch (\Exception $exception) {
116
+			if ($throwException)
117
+				throw $exception;
118
+			else
119
+				return false;
120
+		}
121 121
     	
122
-    	return true;
123
-    }
122
+		return true;
123
+	}
124 124
     
125
-    /**
126
-     * Add multiple files, clone file if file id is provided.
127
-     * May be used to update backref for all files.
128
-     *
129
-     * @param array $files array of existing filestorage ids or array with values for the new file
130
-     * @param string|null $backref Backref for all files
131
-     * @return array Newly created Meta Ids sorted in ascending order
132
-     */
133
-    public static function putMany($files, $backref = null)
134
-    {
135
-    	$ids = [];
136
-    	foreach ((array) $files as $file) {
137
-    		if (! is_numeric($file)) {
138
-    			$ids[] = self::put($file);
125
+	/**
126
+	 * Add multiple files, clone file if file id is provided.
127
+	 * May be used to update backref for all files.
128
+	 *
129
+	 * @param array $files array of existing filestorage ids or array with values for the new file
130
+	 * @param string|null $backref Backref for all files
131
+	 * @return array Newly created Meta Ids sorted in ascending order
132
+	 */
133
+	public static function putMany($files, $backref = null)
134
+	{
135
+		$ids = [];
136
+		foreach ((array) $files as $file) {
137
+			if (! is_numeric($file)) {
138
+				$ids[] = self::put($file);
139 139
     			
140
-    			continue;
141
-    		}
140
+				continue;
141
+			}
142 142
     		
143
-    		$meta = self::get($file, false)->toArray();
143
+			$meta = self::get($file, false)->toArray();
144 144
     			
145
-    		if ($backref && $meta['backref'] != $backref) {
146
-    			$meta['backref'] = $backref;
147
-    			unset($meta['link']);
145
+			if ($backref && $meta['backref'] != $backref) {
146
+				$meta['backref'] = $backref;
147
+				unset($meta['link']);
148 148
     			
149
-    			self::put($meta);
150
-    		}
149
+				self::put($meta);
150
+			}
151 151
     			
152
-    		$ids[] = $file;
153
-    	}
152
+			$ids[] = $file;
153
+		}
154 154
     	
155
-    	sort($ids);
155
+		sort($ids);
156 156
     	
157
-    	return $ids;
158
-    }
157
+		return $ids;
158
+	}
159 159
         
160
-    /**
161
-     * @param string|array     $metaOrFile
162
-     * @param string     $content    Content of the file
163
-     * 
164
-     * @return int Filestorage ID
165
-     * @throws LinkDuplicate
166
-     */
167
-    public static function put($metaOrFile, $content = null) 
168
-    {
169
-    	$meta = $metaOrFile;
170
-    	if (! $content && is_string($metaOrFile)) {
171
-    		$content = file_get_contents($metaOrFile);
160
+	/**
161
+	 * @param string|array     $metaOrFile
162
+	 * @param string     $content    Content of the file
163
+	 * 
164
+	 * @return int Filestorage ID
165
+	 * @throws LinkDuplicate
166
+	 */
167
+	public static function put($metaOrFile, $content = null) 
168
+	{
169
+		$meta = $metaOrFile;
170
+		if (! $content && is_string($metaOrFile)) {
171
+			$content = file_get_contents($metaOrFile);
172 172
     		
173
-    		$meta = [
174
-    				'name' => basename($metaOrFile)
175
-    		];
176
-    	}
173
+			$meta = [
174
+					'name' => basename($metaOrFile)
175
+			];
176
+		}
177 177
     	
178
-    	if (!empty($meta['link']) && self::getIdByLink($meta['link'], false)) {
179
-    		throw new LinkDuplicate($meta['link']);
180
-    	}
178
+		if (!empty($meta['link']) && self::getIdByLink($meta['link'], false)) {
179
+			throw new LinkDuplicate($meta['link']);
180
+		}
181 181
     	
182
-    	if ($file = $meta['file']?? null) {
183
-    		$path = is_array($file)? $file['path']: $file;
182
+		if ($file = $meta['file']?? null) {
183
+			$path = is_array($file)? $file['path']: $file;
184 184
     		
185
-    		$meta['name'] = $meta['name']?? basename($path);
185
+			$meta['name'] = $meta['name']?? basename($path);
186 186
     		
187
-    		$content = $content?: file_get_contents($path);
187
+			$content = $content?: file_get_contents($path);
188 188
     		
189
-    		unset($meta['file']);
190
-    	}
189
+			unset($meta['file']);
190
+		}
191 191
 	
192
-    	return self::updateOrCreate(['id' => $meta['id']?? null], array_merge([
193
-    			'created_at' => time(),
194
-    			'created_by' => Auth::id(),
195
-    			'file_id' => File::putData($meta['content']?? $content)
196
-    	], $meta))->id;
197
-    }
192
+		return self::updateOrCreate(['id' => $meta['id']?? null], array_merge([
193
+				'created_at' => time(),
194
+				'created_by' => Auth::id(),
195
+				'file_id' => File::putData($meta['content']?? $content)
196
+		], $meta))->id;
197
+	}
198 198
     
199
-    public function getThumbnailAttribute()
200
-    {
201
-    	if (! $this->thumbnailPossible()) return false;
199
+	public function getThumbnailAttribute()
200
+	{
201
+		if (! $this->thumbnailPossible()) return false;
202 202
     	
203
-    	$image = new \Imagick($this->meta->file->path . '[0]');
203
+		$image = new \Imagick($this->meta->file->path . '[0]');
204 204
     	
205
-    	$image->setImageFormat('jpg');
205
+		$image->setImageFormat('jpg');
206 206
     	
207
-    	$mime = 'image/jpeg';
207
+		$mime = 'image/jpeg';
208 208
     	
209
-    	$name = 'preview.jpeg';
209
+		$name = 'preview.jpeg';
210 210
     	
211
-    	$contents = $image . '';
211
+		$contents = $image . '';
212 212
     	
213
-    	return collect(compact('mime', 'name', 'contents'));
214
-    }
213
+		return collect(compact('mime', 'name', 'contents'));
214
+	}
215 215
     
216
-    protected function thumbnailPossible() {
217
-    	return $this->file->type == 'application/pdf' && class_exists('Imagick');
218
-    }
216
+	protected function thumbnailPossible() {
217
+		return $this->file->type == 'application/pdf' && class_exists('Imagick');
218
+	}
219 219
 }
220 220
\ No newline at end of file
Please login to merge, or discard this patch.
src/Database/Models/AccessLog.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@
 block discarded – undo
8 8
     
9 9
 	public $timestamps = false;
10 10
 	
11
-    protected $table = 'filestorage_access_log';
12
-    protected static $unguarded = true;    
11
+	protected $table = 'filestorage_access_log';
12
+	protected static $unguarded = true;    
13 13
 
14 14
 }
15 15
\ No newline at end of file
Please login to merge, or discard this patch.
src/Database/Models/Remote.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -6,23 +6,23 @@
 block discarded – undo
6 6
 use Illuminate\Support\Facades\Auth;
7 7
 
8 8
 class Remote extends Model {
9
-    const DEFAULT_PERIOD = '1 week';
9
+	const DEFAULT_PERIOD = '1 week';
10 10
     
11
-    protected $table = 'filestorage_remote';
12
-    protected static $unguarded = true;    
11
+	protected $table = 'filestorage_remote';
12
+	protected static $unguarded = true;    
13 13
 
14
-    public static function access($metaId, $token)
15
-    {
16
-    	return (bool) self::where('meta_id', $metaId)->where('token', $token)->where('expires_at', '>', date('Y-m-d H:i:s'))->count();
17
-    }
14
+	public static function access($metaId, $token)
15
+	{
16
+		return (bool) self::where('meta_id', $metaId)->where('token', $token)->where('expires_at', '>', date('Y-m-d H:i:s'))->count();
17
+	}
18 18
     
19
-    public static function grant($metaId, $expires = self::DEFAULT_PERIOD)
20
-    {
19
+	public static function grant($metaId, $expires = self::DEFAULT_PERIOD)
20
+	{
21 21
 		return self::create([
22 22
 				'meta_id' => $metaId,
23 23
 				'token' => md5(uniqid(rand(), true)),
24 24
 				'created_by' => Auth::id()?: 0,
25 25
 				'expires_at' => date('Y-m-d H:i:s', strtotime($expires)),
26 26
 		]);
27
-    }
27
+	}
28 28
 }
29 29
\ No newline at end of file
Please login to merge, or discard this patch.
src/Database/Migrations/2019_11_16_091615_create_filestorage_tables.php 1 patch
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -6,74 +6,74 @@
 block discarded – undo
6 6
 
7 7
 class CreateFilestorageTables extends Migration
8 8
 {
9
-    /**
10
-     * Run the migrations.
11
-     *
12
-     * @return void
13
-     */
14
-    public function up()
15
-    {
16
-    	$this->down();
9
+	/**
10
+	 * Run the migrations.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function up()
15
+	{
16
+		$this->down();
17 17
     	
18
-        Schema::create('filestorage_files', function (Blueprint $table) {
19
-            $table->bigIncrements('id');
20
-            $table->string('hash', 128);
21
-            $table->integer('size');
22
-            $table->string('type', 256);
18
+		Schema::create('filestorage_files', function (Blueprint $table) {
19
+			$table->bigIncrements('id');
20
+			$table->string('hash', 128);
21
+			$table->integer('size');
22
+			$table->string('type', 256);
23 23
             
24
-            $table->softDeletes();
25
-        });
24
+			$table->softDeletes();
25
+		});
26 26
         
27
-        Schema::create('filestorage_meta', function (Blueprint $table) {
28
-            $table->bigIncrements('id');
29
-            $table->string('name', 256);
30
-            $table->string('link', 128)->nullable();
31
-            $table->string('backref', 128)->nullable();
32
-            $table->unsignedBigInteger('file_id');
33
-            $table->unsignedBigInteger('created_by')->nullable();
34
-            $table->timestamps();
27
+		Schema::create('filestorage_meta', function (Blueprint $table) {
28
+			$table->bigIncrements('id');
29
+			$table->string('name', 256);
30
+			$table->string('link', 128)->nullable();
31
+			$table->string('backref', 128)->nullable();
32
+			$table->unsignedBigInteger('file_id');
33
+			$table->unsignedBigInteger('created_by')->nullable();
34
+			$table->timestamps();
35 35
             
36
-            $table->softDeletes();
36
+			$table->softDeletes();
37 37
             
38
-            $table->foreign('file_id')->references('id')->on('filestorage_files');
39
-            $table->foreign('created_by')->references('id')->on('users');
40
-        });
38
+			$table->foreign('file_id')->references('id')->on('filestorage_files');
39
+			$table->foreign('created_by')->references('id')->on('users');
40
+		});
41 41
         
42
-        Schema::create('filestorage_remote', function (Blueprint $table) {
43
-            $table->bigIncrements('id');
44
-            $table->unsignedBigInteger('meta_id');            
45
-            $table->string('token', 128);
46
-            $table->unsignedBigInteger('created_by');
47
-            $table->timestamp('expires_at');
48
-            $table->timestamps();
42
+		Schema::create('filestorage_remote', function (Blueprint $table) {
43
+			$table->bigIncrements('id');
44
+			$table->unsignedBigInteger('meta_id');            
45
+			$table->string('token', 128);
46
+			$table->unsignedBigInteger('created_by');
47
+			$table->timestamp('expires_at');
48
+			$table->timestamps();
49 49
             
50
-            $table->foreign('meta_id')->references('id')->on('filestorage_meta');
51
-            $table->foreign('created_by')->references('id')->on('users');
52
-        });
50
+			$table->foreign('meta_id')->references('id')->on('filestorage_meta');
51
+			$table->foreign('created_by')->references('id')->on('users');
52
+		});
53 53
         
54
-        Schema::create('filestorage_access_log', function (Blueprint $table) {
55
-            $table->bigIncrements('id');
56
-            $table->unsignedBigInteger('meta_id');            
57
-            $table->timestamp('accessed_at');
58
-            $table->unsignedBigInteger('accessed_by');
59
-            $table->string('type', 32);
60
-            $table->string('ip_address', 32);
61
-            $table->string('host_name', 64);
54
+		Schema::create('filestorage_access_log', function (Blueprint $table) {
55
+			$table->bigIncrements('id');
56
+			$table->unsignedBigInteger('meta_id');            
57
+			$table->timestamp('accessed_at');
58
+			$table->unsignedBigInteger('accessed_by');
59
+			$table->string('type', 32);
60
+			$table->string('ip_address', 32);
61
+			$table->string('host_name', 64);
62 62
                         
63
-            $table->foreign('meta_id')->references('id')->on('filestorage_meta');
64
-        });
65
-    }
63
+			$table->foreign('meta_id')->references('id')->on('filestorage_meta');
64
+		});
65
+	}
66 66
 
67
-    /**
68
-     * Reverse the migrations.
69
-     *
70
-     * @return void
71
-     */
72
-    public function down()
73
-    {
74
-    	Schema::dropIfExists('filestorage_remote');
75
-    	Schema::dropIfExists('filestorage_access_log');
76
-    	Schema::dropIfExists('filestorage_meta');
77
-        Schema::dropIfExists('filestorage_files');
78
-    }
67
+	/**
68
+	 * Reverse the migrations.
69
+	 *
70
+	 * @return void
71
+	 */
72
+	public function down()
73
+	{
74
+		Schema::dropIfExists('filestorage_remote');
75
+		Schema::dropIfExists('filestorage_access_log');
76
+		Schema::dropIfExists('filestorage_meta');
77
+		Schema::dropIfExists('filestorage_files');
78
+	}
79 79
 }
Please login to merge, or discard this patch.