implemented cache for remote filesystems

fixes #424
This commit is contained in:
SergiX44 2022-02-08 22:24:16 +01:00
parent dea92d9ada
commit 7634741676
5 changed files with 610 additions and 410 deletions

View file

@ -3,6 +3,8 @@
use App\Database\DB; use App\Database\DB;
use App\Web\Lang; use App\Web\Lang;
use Aws\S3\S3Client; use Aws\S3\S3Client;
use League\Flysystem\Cached\CachedAdapter;
use League\Flysystem\Cached\Storage\Adapter;
use function DI\factory; use function DI\factory;
use function DI\get; use function DI\get;
use Google\Cloud\Storage\StorageClient; use Google\Cloud\Storage\StorageClient;
@ -46,58 +48,61 @@ return [
Filesystem::class => factory(function (Container $container) { Filesystem::class => factory(function (Container $container) {
$config = $container->get('config'); $config = $container->get('config');
switch ($config['storage']['driver']) { $driver = $config['storage']['driver'];
case 'local': if ($driver === 'local') {
return new Filesystem(new Local($config['storage']['path'])); return new Filesystem(new Local($config['storage']['path']));
case 's3': } elseif ($driver === 's3') {
$client = new S3Client([ $client = new S3Client([
'credentials' => [ 'credentials' => [
'key' => $config['storage']['key'], 'key' => $config['storage']['key'],
'secret' => $config['storage']['secret'], 'secret' => $config['storage']['secret'],
], ],
'region' => $config['storage']['region'], 'region' => $config['storage']['region'],
'endpoint' => $config['storage']['endpoint'], 'endpoint' => $config['storage']['endpoint'],
'version' => 'latest', 'version' => 'latest',
'use_path_style_endpoint' => $config['storage']['use_path_style_endpoint'] ?? false, 'use_path_style_endpoint' => $config['storage']['use_path_style_endpoint'] ?? false,
'@http' => ['stream' => true], '@http' => ['stream' => true],
]); ]);
return new Filesystem(new AwsS3Adapter($client, $config['storage']['bucket'], $config['storage']['path'])); $adapter = new AwsS3Adapter($client, $config['storage']['bucket'], $config['storage']['path']);
case 'dropbox': } elseif ($driver === 'dropbox') {
$client = new DropboxClient($config['storage']['token']); $client = new DropboxClient($config['storage']['token']);
return new Filesystem(new DropboxAdapter($client), ['case_sensitive' => false]); $adapter = new DropboxAdapter($client);
case 'ftp': } elseif ($driver === 'ftp') {
return new Filesystem(new FtpAdapter([ $adapter = new FtpAdapter([
'host' => $config['storage']['host'], 'host' => $config['storage']['host'],
'username' => $config['storage']['username'], 'username' => $config['storage']['username'],
'password' => $config['storage']['password'], 'password' => $config['storage']['password'],
'port' => $config['storage']['port'], 'port' => $config['storage']['port'],
'root' => $config['storage']['path'], 'root' => $config['storage']['path'],
'passive' => $config['storage']['passive'], 'passive' => $config['storage']['passive'],
'ssl' => $config['storage']['ssl'], 'ssl' => $config['storage']['ssl'],
'timeout' => 30, 'timeout' => 30,
])); ]);
case 'google-cloud': } elseif ($driver === 'google-cloud') {
$client = new StorageClient([ $client = new StorageClient([
'projectId' => $config['storage']['project_id'], 'projectId' => $config['storage']['project_id'],
'keyFilePath' => $config['storage']['key_path'], 'keyFilePath' => $config['storage']['key_path'],
]); ]);
return new Filesystem(new GoogleStorageAdapter($client, $client->bucket($config['storage']['bucket']))); $adapter = new GoogleStorageAdapter($client, $client->bucket($config['storage']['bucket']));
case 'azure': } elseif ($driver === 'azure') {
$client = BlobRestProxy::createBlobService( $client = BlobRestProxy::createBlobService(
sprintf( sprintf(
'DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s;', 'DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s;',
$config['storage']['account_name'], $config['storage']['account_name'],
$config['storage']['account_key'] $config['storage']['account_key']
) )
); );
return new Filesystem(new AzureBlobStorageAdapter($client, $config['storage']['container_name'])); $adapter = new AzureBlobStorageAdapter($client, $config['storage']['container_name']);
default: } else {
throw new InvalidArgumentException('The driver specified is not supported.'); throw new InvalidArgumentException('The driver specified is not supported.');
} }
$cache = new Adapter(new Local(BASE_DIR.'resources/cache/fs'), 'file', 300); // 5min
return new Filesystem(new CachedAdapter($adapter, $cache));
}), }),
'storage' => get(Filesystem::class), 'storage' => get(Filesystem::class),

View file

@ -6,12 +6,12 @@
"type": "project", "type": "project",
"require": { "require": {
"php": ">=7.2", "php": ">=7.2",
"ext-filter": "*",
"ext-gd": "*", "ext-gd": "*",
"ext-intl": "*", "ext-intl": "*",
"ext-json": "*", "ext-json": "*",
"ext-pdo": "*", "ext-pdo": "*",
"ext-zip": "*", "ext-zip": "*",
"ext-filter": "*",
"erusev/parsedown": "^1.7", "erusev/parsedown": "^1.7",
"guzzlehttp/psr7": "^1.6", "guzzlehttp/psr7": "^1.6",
"http-interop/http-factory-guzzle": "^1.0", "http-interop/http-factory-guzzle": "^1.0",
@ -19,6 +19,7 @@
"league/flysystem": "^1.1.4", "league/flysystem": "^1.1.4",
"league/flysystem-aws-s3-v3": "^1.0", "league/flysystem-aws-s3-v3": "^1.0",
"league/flysystem-azure-blob-storage": "^0.1.6", "league/flysystem-azure-blob-storage": "^0.1.6",
"league/flysystem-cached-adapter": "^1.1",
"maennchen/zipstream-php": "^2.0", "maennchen/zipstream-php": "^2.0",
"monolog/monolog": "^1.23", "monolog/monolog": "^1.23",
"php-di/slim-bridge": "^3.0", "php-di/slim-bridge": "^3.0",

803
composer.lock generated

File diff suppressed because it is too large Load diff

107
package-lock.json generated
View file

@ -109,9 +109,9 @@
} }
}, },
"bootstrap": { "bootstrap": {
"version": "4.6.0", "version": "4.6.1",
"resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-4.6.0.tgz", "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-4.6.1.tgz",
"integrity": "sha512-Io55IuQY3kydzHtbGvQya3H+KorS/M9rSNyfCGCg9WZ4pyT/lCxIlpJgG1GXW/PswzC84Tr2fBYi+7+jFVQQBw==" "integrity": "sha512-0dj+VgI9Ecom+rvvpNZ4MUZJz8dcX7WCX+eTID9+/8HgOkv3dsRzi8BGeZJCQU6flWQVYxwTQnEZFrmJSEO7og=="
}, },
"bootstrap4-toggle": { "bootstrap4-toggle": {
"version": "3.6.1", "version": "3.6.1",
@ -186,9 +186,9 @@
} }
}, },
"clipboard": { "clipboard": {
"version": "2.0.8", "version": "2.0.10",
"resolved": "https://registry.npmjs.org/clipboard/-/clipboard-2.0.8.tgz", "resolved": "https://registry.npmjs.org/clipboard/-/clipboard-2.0.10.tgz",
"integrity": "sha512-Y6WO0unAIQp5bLmk1zdThRhgJt/x3ks6f30s3oE3H1mgIEU33XyQjEf8gsf6DxC7NPX8Y1SsNWjUjL/ywLnnbQ==", "integrity": "sha512-cz3m2YVwFz95qSEbCDi2fzLN/epEN9zXBvfgAoGkvGOJZATMl9gtTDVOtBYkx2ODUJl2kvmud7n32sV2BpYR4g==",
"requires": { "requires": {
"good-listener": "^1.2.2", "good-listener": "^1.2.2",
"select": "^1.1.2", "select": "^1.1.2",
@ -238,14 +238,14 @@
"dev": true "dev": true
}, },
"core-js": { "core-js": {
"version": "3.18.3", "version": "3.21.0",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-3.18.3.tgz", "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.21.0.tgz",
"integrity": "sha512-tReEhtMReZaPFVw7dajMx0vlsz3oOb8ajgPoHVYGxr8ErnZ6PcYEvvmjGmXlfpnxpkYSdOQttjB+MvVbCGfvLw==" "integrity": "sha512-YUdI3fFu4TF/2WykQ2xzSiTQdldLB4KVuL9WeAy5XONZYt5Cun/fpQvctoKbCgvPhmzADeesTk/j2Rdx77AcKQ=="
}, },
"core-util-is": { "core-util-is": {
"version": "1.0.2", "version": "1.0.3",
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==",
"dev": true "dev": true
}, },
"custom-event-polyfill": { "custom-event-polyfill": {
@ -698,43 +698,63 @@
} }
}, },
"grunt-contrib-jshint": { "grunt-contrib-jshint": {
"version": "2.1.0", "version": "3.1.1",
"resolved": "https://registry.npmjs.org/grunt-contrib-jshint/-/grunt-contrib-jshint-2.1.0.tgz", "resolved": "https://registry.npmjs.org/grunt-contrib-jshint/-/grunt-contrib-jshint-3.1.1.tgz",
"integrity": "sha512-65S2/C/6RfjY/umTxfwXXn+wVvaYmykHkHSsW6Q6rhkbv3oudTEgqnFFZvWzWCoHUb+3GMZLbP3oSrNyvshmIQ==", "integrity": "sha512-EwMY6L91FqTcMlZTVoDeeq/EZL+7MoFyo1rxIea9sxyv73geVggeE37jcUhNbu5hLbxHE82CGIUqitHuR2/q+g==",
"dev": true, "dev": true,
"requires": { "requires": {
"chalk": "^2.4.2", "chalk": "^4.1.0",
"hooker": "^0.2.3", "hooker": "^0.2.3",
"jshint": "~2.10.2" "jshint": "~2.13.0"
}, },
"dependencies": { "dependencies": {
"ansi-styles": { "ansi-styles": {
"version": "3.2.1", "version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"dev": true, "dev": true,
"requires": { "requires": {
"color-convert": "^1.9.0" "color-convert": "^2.0.1"
} }
}, },
"chalk": { "chalk": {
"version": "2.4.2", "version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dev": true, "dev": true,
"requires": { "requires": {
"ansi-styles": "^3.2.1", "ansi-styles": "^4.1.0",
"escape-string-regexp": "^1.0.5", "supports-color": "^7.1.0"
"supports-color": "^5.3.0"
} }
}, },
"supports-color": { "color-convert": {
"version": "5.5.0", "version": "2.0.1",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"has-flag": "^3.0.0" "color-name": "~1.1.4"
}
},
"color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"dev": true
},
"has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
"dev": true
},
"supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"dev": true,
"requires": {
"has-flag": "^4.0.0"
} }
} }
} }
@ -1205,18 +1225,17 @@
} }
}, },
"jshint": { "jshint": {
"version": "2.10.3", "version": "2.13.4",
"resolved": "https://registry.npmjs.org/jshint/-/jshint-2.10.3.tgz", "resolved": "https://registry.npmjs.org/jshint/-/jshint-2.13.4.tgz",
"integrity": "sha512-d8AoXcNNYzmm7cdmulQ3dQApbrPYArtVBO6n4xOICe4QsXGNHCAKDcFORzqP52LhK61KX0VhY39yYzCsNq+bxQ==", "integrity": "sha512-HO3bosL84b2qWqI0q+kpT/OpRJwo0R4ivgmxaO848+bo10rc50SkPnrtwSFXttW0ym4np8jbJvLwk5NziB7jIw==",
"dev": true, "dev": true,
"requires": { "requires": {
"cli": "~1.0.0", "cli": "~1.0.0",
"console-browserify": "1.1.x", "console-browserify": "1.1.x",
"exit": "0.1.x", "exit": "0.1.x",
"htmlparser2": "3.8.x", "htmlparser2": "3.8.x",
"lodash": "~4.17.11", "lodash": "~4.17.21",
"minimatch": "~3.0.2", "minimatch": "~3.0.2",
"shelljs": "0.3.x",
"strip-json-comments": "1.0.x" "strip-json-comments": "1.0.x"
} }
}, },
@ -1574,11 +1593,11 @@
} }
}, },
"plyr": { "plyr": {
"version": "3.6.9", "version": "3.6.12",
"resolved": "https://registry.npmjs.org/plyr/-/plyr-3.6.9.tgz", "resolved": "https://registry.npmjs.org/plyr/-/plyr-3.6.12.tgz",
"integrity": "sha512-KYi6o0799iw6yWZSmpZyx0tcrdNB+uGrUb/pskBjBzUax8fevzkqUx9A5vayYRBjlSme2UA8fHjTw3SMeHEvRA==", "integrity": "sha512-42WhYpMS/FEyX2unSEvhYtj1RvJgWvOsjZQFDongOQHA4eVzsyr7b06bzVpinMAOVC9e5H7RCbK+6CCAFIl2VQ==",
"requires": { "requires": {
"core-js": "^3.10.1", "core-js": "^3.20.0",
"custom-event-polyfill": "^1.0.7", "custom-event-polyfill": "^1.0.7",
"loadjs": "^4.2.0", "loadjs": "^4.2.0",
"rangetouch": "^2.0.1", "rangetouch": "^2.0.1",
@ -1711,12 +1730,6 @@
"resolved": "https://registry.npmjs.org/select/-/select-1.1.2.tgz", "resolved": "https://registry.npmjs.org/select/-/select-1.1.2.tgz",
"integrity": "sha1-DnNQrN7ICxEIUoeG7B1EGNEbOW0=" "integrity": "sha1-DnNQrN7ICxEIUoeG7B1EGNEbOW0="
}, },
"shelljs": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.3.0.tgz",
"integrity": "sha1-NZbmMHp4FUT1kfN9phg2DzHbV7E=",
"dev": true
},
"side-channel": { "side-channel": {
"version": "1.0.4", "version": "1.0.4",
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz",

View file

@ -1,14 +1,14 @@
{ {
"dependencies": { "dependencies": {
"@fortawesome/fontawesome-free": "^5.15.2", "@fortawesome/fontawesome-free": "^5.15.2",
"bootstrap": "^4.6.0", "bootstrap": "^4.6.1",
"bootstrap4-toggle": "^3.6.1", "bootstrap4-toggle": "^3.6.1",
"clipboard": "^2.0.7", "clipboard": "^2.0.10",
"dropzone": "^5.9.3", "dropzone": "^5.9.3",
"highlightjs": "^9.16.2", "highlightjs": "^9.16.2",
"highlightjs-line-numbers.js": "^2.8.0", "highlightjs-line-numbers.js": "^2.8.0",
"jquery": "^3.6.0", "jquery": "^3.6.0",
"plyr": "^3.6.4", "plyr": "^3.6.12",
"popper.js": "^1.16.1", "popper.js": "^1.16.1",
"tooltip.js": "^1.3.3" "tooltip.js": "^1.3.3"
}, },
@ -16,7 +16,7 @@
"grunt": "^1.4.1", "grunt": "^1.4.1",
"grunt-contrib-copy": "^1.0.0", "grunt-contrib-copy": "^1.0.0",
"grunt-contrib-cssmin": "^3.0.0", "grunt-contrib-cssmin": "^3.0.0",
"grunt-contrib-jshint": "^2.1.0", "grunt-contrib-jshint": "^3.1.1",
"grunt-contrib-uglify": "^4.0.1", "grunt-contrib-uglify": "^4.0.1",
"grunt-contrib-watch": "^1.1.0", "grunt-contrib-watch": "^1.1.0",
"grunt-shell": "^3.0.1", "grunt-shell": "^3.0.1",