1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Epesi\FileStorage\Models; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Auth; |
6
|
|
|
use atk4\data\Model; |
7
|
|
|
use Epesi\Core\Data\HasEpesiConnection; |
|
|
|
|
8
|
|
|
use Epesi\Core\System\User\Database\Models\atk4\User; |
9
|
|
|
|
10
|
|
|
class FileRemoteAccess extends Model |
11
|
|
|
{ |
12
|
|
|
use HasEpesiConnection; |
13
|
|
|
|
14
|
|
|
const DEFAULT_PERIOD = '1 week'; |
15
|
|
|
|
16
|
|
|
public $table = 'filestorage_remote_access'; |
17
|
|
|
|
18
|
|
|
public function init() |
19
|
|
|
{ |
20
|
|
|
parent::init(); |
21
|
|
|
|
22
|
|
|
$this->addFields([ |
23
|
|
|
'token', |
24
|
|
|
'expires_at' => ['type' => 'datetime'], |
25
|
|
|
]); |
26
|
|
|
|
27
|
|
|
$this->hasOne('file_id', File::class)->addTitle(['field' => 'file', 'caption' => __('File Name')]); |
|
|
|
|
28
|
|
|
$this->hasOne('created_by', User::class)->addTitle(['field' => 'created_by_user', 'caption' => __('Created By')]); |
29
|
|
|
|
30
|
|
|
$this->addCalculatedField('href', [[__CLASS__, 'getHrefField']]); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public static function check($fileId, $token) |
34
|
|
|
{ |
35
|
|
|
return (bool) self::create() |
36
|
|
|
->addCrits([ |
37
|
|
|
['file_id', $fileId], |
38
|
|
|
['token', $token], |
39
|
|
|
['expires_at', '>', date('Y-m-d H:i:s')] |
40
|
|
|
]) |
41
|
|
|
->action('count')->getOne(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public static function grant($file, $expires = self::DEFAULT_PERIOD) |
45
|
|
|
{ |
46
|
|
|
return self::create()->insert([ |
47
|
|
|
'file_id' => is_numeric($file)? $file: $file->id, |
48
|
|
|
'token' => md5(uniqid(rand(), true)), |
49
|
|
|
'created_by' => Auth::id()?: 0, |
50
|
|
|
'expires_at' => date('Y-m-d H:i:s', strtotime($expires)), |
51
|
|
|
]); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public static function getHrefField($model) |
55
|
|
|
{ |
56
|
|
|
return url('file') . '?' . http_build_query(['id' => $model['file_id'], 'token' => $model['token']]); |
57
|
|
|
} |
58
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths