zstd compression support on endpoints
This commit is contained in:
parent
6c04550558
commit
5fa7d34757
|
@ -6,7 +6,6 @@ use Appwrite\Event\Delete;
|
|||
use Appwrite\Event\Event;
|
||||
use Appwrite\Utopia\Database\Validator\CustomId;
|
||||
use Appwrite\OpenSSL\OpenSSL;
|
||||
use Appwrite\Usage\Stats;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Utopia\App;
|
||||
use Utopia\Config\Config;
|
||||
|
@ -27,8 +26,8 @@ use Utopia\Database\Validator\UID;
|
|||
use Appwrite\Extend\Exception;
|
||||
use Utopia\Image\Image;
|
||||
use Utopia\Storage\Compression\Algorithms\GZIP;
|
||||
use Utopia\Storage\Compression\Algorithms\Zstd;
|
||||
use Utopia\Storage\Device;
|
||||
use Utopia\Storage\Device\Local;
|
||||
use Utopia\Storage\Storage;
|
||||
use Utopia\Storage\Validator\File;
|
||||
use Utopia\Storage\Validator\FileExt;
|
||||
|
@ -37,7 +36,6 @@ use Utopia\Storage\Validator\Upload;
|
|||
use Utopia\Validator\ArrayList;
|
||||
use Utopia\Validator\Boolean;
|
||||
use Utopia\Validator\HexColor;
|
||||
use Utopia\Validator\Integer;
|
||||
use Utopia\Validator\Range;
|
||||
use Utopia\Validator\Text;
|
||||
use Utopia\Validator\WhiteList;
|
||||
|
@ -502,9 +500,17 @@ App::post('/v1/storage/buckets/:bucketId/files')
|
|||
$mimeType = $deviceFiles->getFileMimeType($path); // Get mime-type before compression and encryption
|
||||
$data = '';
|
||||
// Compression
|
||||
if ($fileSize <= APP_STORAGE_READ_BUFFER) {
|
||||
$algorithm = $bucket->getAttribute('compression', 'none');
|
||||
if ($fileSize <= APP_STORAGE_READ_BUFFER && $algorithm != 'none') {
|
||||
$data = $deviceFiles->read($path);
|
||||
$compressor = new GZIP();
|
||||
switch($algorithm) {
|
||||
case 'zstd':
|
||||
$compressor = new Zstd();
|
||||
case 'gzip':
|
||||
default:
|
||||
$compressor = new GZIP();
|
||||
break;
|
||||
}
|
||||
$data = $compressor->compress($data);
|
||||
}
|
||||
|
||||
|
@ -524,8 +530,6 @@ App::post('/v1/storage/buckets/:bucketId/files')
|
|||
}
|
||||
|
||||
$sizeActual = $deviceFiles->getFileSize($path);
|
||||
|
||||
$algorithm = empty($compressor) ? '' : $compressor->getName();
|
||||
$fileHash = $deviceFiles->getFileHash($path);
|
||||
|
||||
if ($bucket->getAttribute('encryption', true) && $fileSize <= APP_STORAGE_READ_BUFFER) {
|
||||
|
@ -840,7 +844,7 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/preview')
|
|||
|
||||
$path = $file->getAttribute('path');
|
||||
$type = \strtolower(\pathinfo($path, PATHINFO_EXTENSION));
|
||||
$algorithm = $file->getAttribute('algorithm');
|
||||
$algorithm = $file->getAttribute('algorithm', 'none');
|
||||
$cipher = $file->getAttribute('openSSLCipher');
|
||||
$mime = $file->getAttribute('mimeType');
|
||||
if (!\in_array($mime, $inputs) || $file->getAttribute('sizeActual') > (int) App::getEnv('_APP_STORAGE_PREVIEW_LIMIT', 20000000)) {
|
||||
|
@ -851,16 +855,13 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/preview')
|
|||
$path = $fileLogos['default_image'];
|
||||
}
|
||||
|
||||
$algorithm = null;
|
||||
$algorithm = 'none';
|
||||
$cipher = null;
|
||||
$background = (empty($background)) ? 'eceff1' : $background;
|
||||
$type = \strtolower(\pathinfo($path, PATHINFO_EXTENSION));
|
||||
$deviceFiles = $deviceLocal;
|
||||
}
|
||||
|
||||
|
||||
$compressor = new GZIP();
|
||||
|
||||
if (!$deviceFiles->exists($path)) {
|
||||
throw new Exception(Exception::STORAGE_FILE_NOT_FOUND);
|
||||
}
|
||||
|
@ -885,8 +886,15 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/preview')
|
|||
);
|
||||
}
|
||||
|
||||
if (!empty($algorithm)) {
|
||||
$source = $compressor->decompress($source);
|
||||
switch($algorithm) {
|
||||
case 'zstd':
|
||||
$compressor = new Zstd();
|
||||
$source = $compressor->decompress($source);
|
||||
break;
|
||||
case 'gzip':
|
||||
$compressor = new GZIP();
|
||||
$source = $compressor->decompress($source);
|
||||
break;
|
||||
}
|
||||
|
||||
$image = new Image($source);
|
||||
|
@ -1021,12 +1029,21 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/download')
|
|||
);
|
||||
}
|
||||
|
||||
if (!empty($file->getAttribute('algorithm', ''))) {
|
||||
if (empty($source)) {
|
||||
$source = $deviceFiles->read($path);
|
||||
}
|
||||
$compressor = new GZIP();
|
||||
$source = $compressor->decompress($source);
|
||||
switch($file->getAttribute('algorithm', 'none')) {
|
||||
case 'zstd':
|
||||
if (empty($source)) {
|
||||
$source = $deviceFiles->read($path);
|
||||
}
|
||||
$compressor = new Zstd();
|
||||
$source = $compressor->decompress($source);
|
||||
break;
|
||||
case 'gzip':
|
||||
if (empty($source)) {
|
||||
$source = $deviceFiles->read($path);
|
||||
}
|
||||
$compressor = new GZIP();
|
||||
$source = $compressor->decompress($source);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!empty($source)) {
|
||||
|
@ -1162,12 +1179,21 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/view')
|
|||
);
|
||||
}
|
||||
|
||||
if (!empty($file->getAttribute('algorithm', ''))) {
|
||||
if (empty($source)) {
|
||||
$source = $deviceFiles->read($path);
|
||||
}
|
||||
$compressor = new GZIP();
|
||||
$source = $compressor->decompress($source);
|
||||
switch($file->getAttribute('algorithm', 'none')) {
|
||||
case 'zstd':
|
||||
if (empty($source)) {
|
||||
$source = $deviceFiles->read($path);
|
||||
}
|
||||
$compressor = new Zstd();
|
||||
$source = $compressor->decompress($source);
|
||||
break;
|
||||
case 'gzip':
|
||||
if (empty($source)) {
|
||||
$source = $deviceFiles->read($path);
|
||||
}
|
||||
$compressor = new GZIP();
|
||||
$source = $compressor->decompress($source);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!empty($source)) {
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
"utopia-php/preloader": "0.2.*",
|
||||
"utopia-php/domains": "1.1.*",
|
||||
"utopia-php/swoole": "0.3.*",
|
||||
"utopia-php/storage": "0.9.*",
|
||||
"utopia-php/storage": "dev-feat-zstd-compression",
|
||||
"utopia-php/websocket": "0.1.0",
|
||||
"utopia-php/image": "0.5.*",
|
||||
"utopia-php/orchestration": "0.6.*",
|
||||
|
|
32
composer.lock
generated
32
composer.lock
generated
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "1145ff29befcc4aa21b5002da0b8319c",
|
||||
"content-hash": "b1491fd16c44267bc71fb96581278b3f",
|
||||
"packages": [
|
||||
{
|
||||
"name": "adhocore/jwt",
|
||||
|
@ -2556,19 +2556,22 @@
|
|||
},
|
||||
{
|
||||
"name": "utopia-php/storage",
|
||||
"version": "0.9.0",
|
||||
"version": "dev-feat-zstd-compression",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/storage.git",
|
||||
"reference": "c7912481a56e17cc86358fa8de57309de5e88ef7"
|
||||
"reference": "e049f2c10b9cb84b4490850d7b9e7360352c36d2"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/storage/zipball/c7912481a56e17cc86358fa8de57309de5e88ef7",
|
||||
"reference": "c7912481a56e17cc86358fa8de57309de5e88ef7",
|
||||
"url": "https://api.github.com/repos/utopia-php/storage/zipball/e049f2c10b9cb84b4490850d7b9e7360352c36d2",
|
||||
"reference": "e049f2c10b9cb84b4490850d7b9e7360352c36d2",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-fileinfo": "*",
|
||||
"ext-zlib": "*",
|
||||
"ext-zstd": "*",
|
||||
"php": ">=8.0",
|
||||
"utopia-php/framework": "0.*.*"
|
||||
},
|
||||
|
@ -2602,9 +2605,9 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/storage/issues",
|
||||
"source": "https://github.com/utopia-php/storage/tree/0.9.0"
|
||||
"source": "https://github.com/utopia-php/storage/tree/feat-zstd-compression"
|
||||
},
|
||||
"time": "2022-05-19T11:05:45+00:00"
|
||||
"time": "2022-08-22T09:19:07+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/swoole",
|
||||
|
@ -3534,16 +3537,16 @@
|
|||
},
|
||||
{
|
||||
"name": "phpunit/php-code-coverage",
|
||||
"version": "9.2.16",
|
||||
"version": "9.2.17",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
|
||||
"reference": "2593003befdcc10db5e213f9f28814f5aa8ac073"
|
||||
"reference": "aa94dc41e8661fe90c7316849907cba3007b10d8"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/2593003befdcc10db5e213f9f28814f5aa8ac073",
|
||||
"reference": "2593003befdcc10db5e213f9f28814f5aa8ac073",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/aa94dc41e8661fe90c7316849907cba3007b10d8",
|
||||
"reference": "aa94dc41e8661fe90c7316849907cba3007b10d8",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -3599,7 +3602,7 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/sebastianbergmann/php-code-coverage/issues",
|
||||
"source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.16"
|
||||
"source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.17"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -3607,7 +3610,7 @@
|
|||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2022-08-20T05:26:47+00:00"
|
||||
"time": "2022-08-30T12:24:04+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpunit/php-file-iterator",
|
||||
|
@ -5366,6 +5369,7 @@
|
|||
],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": {
|
||||
"utopia-php/storage": 20,
|
||||
"appwrite/sdk-generator": 20
|
||||
},
|
||||
"prefer-stable": false,
|
||||
|
@ -5391,5 +5395,5 @@
|
|||
"platform-overrides": {
|
||||
"php": "8.0"
|
||||
},
|
||||
"plugin-api-version": "2.3.0"
|
||||
"plugin-api-version": "2.2.0"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue