Merge pull request #1170 from lohanidamodar/fix-image-preview-validator

fix-image-preview-validator
This commit is contained in:
Eldad A. Fux 2021-05-21 15:25:09 +03:00 committed by GitHub
commit 4cfce5547e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 33 deletions

View file

@ -22,6 +22,7 @@ use Utopia\Image\Image;
use Appwrite\OpenSSL\OpenSSL; use Appwrite\OpenSSL\OpenSSL;
use Appwrite\Utopia\Response; use Appwrite\Utopia\Response;
use Utopia\Config\Config; use Utopia\Config\Config;
use Utopia\Validator\Numeric;
App::post('/v1/storage/files') App::post('/v1/storage/files')
->desc('Create File') ->desc('Create File')
@ -245,7 +246,7 @@ App::get('/v1/storage/files/:fileId/preview')
->param('borderWidth', 0, new Range(0, 100), 'Preview image border in pixels. Pass an integer between 0 to 100. Defaults to 0.', true) ->param('borderWidth', 0, new Range(0, 100), 'Preview image border in pixels. Pass an integer between 0 to 100. Defaults to 0.', true)
->param('borderColor', '', new HexColor(), 'Preview image border color. Use a valid HEX color, no # is needed for prefix.', true) ->param('borderColor', '', new HexColor(), 'Preview image border color. Use a valid HEX color, no # is needed for prefix.', true)
->param('borderRadius', 0, new Range(0, 4000), 'Preview image border radius in pixels. Pass an integer between 0 to 4000.', true) ->param('borderRadius', 0, new Range(0, 4000), 'Preview image border radius in pixels. Pass an integer between 0 to 4000.', true)
->param('opacity', 1, new Range(0,1), 'Preview image opacity. Only works with images having an alpha channel (like png). Pass a number between 0 to 1.', true) ->param('opacity', 1, new Range(0,1, Range::TYPE_FLOAT), 'Preview image opacity. Only works with images having an alpha channel (like png). Pass a number between 0 to 1.', true)
->param('rotation', 0, new Range(0,360), 'Preview image rotation in degrees. Pass an integer between 0 and 360.', true) ->param('rotation', 0, new Range(0,360), 'Preview image rotation in degrees. Pass an integer between 0 and 360.', true)
->param('background', '', new HexColor(), 'Preview image background color. Only works with transparent images (png). Use a valid HEX color, no # is needed for prefix.', true) ->param('background', '', new HexColor(), 'Preview image background color. Only works with transparent images (png). Use a valid HEX color, no # is needed for prefix.', true)
->param('output', '', new WhiteList(\array_keys(Config::getParam('storage-outputs')), true), 'Output format type (jpeg, jpg, png, gif and webp).', true) ->param('output', '', new WhiteList(\array_keys(Config::getParam('storage-outputs')), true), 'Output format type (jpeg, jpg, png, gif and webp).', true)

12
composer.lock generated
View file

@ -1693,16 +1693,16 @@
}, },
{ {
"name": "utopia-php/framework", "name": "utopia-php/framework",
"version": "0.14.0", "version": "0.14.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/utopia-php/framework.git", "url": "https://github.com/utopia-php/framework.git",
"reference": "92d4a36f3b0e22393a31877c5317c96e01760339" "reference": "632113288bebe41cbef79f0d355bd91609767b8c"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/utopia-php/framework/zipball/92d4a36f3b0e22393a31877c5317c96e01760339", "url": "https://api.github.com/repos/utopia-php/framework/zipball/632113288bebe41cbef79f0d355bd91609767b8c",
"reference": "92d4a36f3b0e22393a31877c5317c96e01760339", "reference": "632113288bebe41cbef79f0d355bd91609767b8c",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1736,9 +1736,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/utopia-php/framework/issues", "issues": "https://github.com/utopia-php/framework/issues",
"source": "https://github.com/utopia-php/framework/tree/0.14.0" "source": "https://github.com/utopia-php/framework/tree/0.14.1"
}, },
"time": "2021-04-15T21:01:44+00:00" "time": "2021-05-21T06:41:45+00:00"
}, },
{ {
"name": "utopia-php/image", "name": "utopia-php/image",

View file

@ -5,6 +5,7 @@ namespace Appwrite\Specification\Format;
use Appwrite\Specification\Format; use Appwrite\Specification\Format;
use Appwrite\Template\Template; use Appwrite\Template\Template;
use stdClass; use stdClass;
use Utopia\Validator;
class OpenAPI3 extends Format class OpenAPI3 extends Format
{ {
@ -230,24 +231,24 @@ class OpenAPI3 extends Format
switch ((!empty($validator)) ? \get_class($validator) : '') { switch ((!empty($validator)) ? \get_class($validator) : '') {
case 'Utopia\Validator\Text': case 'Utopia\Validator\Text':
$node['schema']['type'] = 'string'; $node['schema']['type'] = $validator->getType();
$node['schema']['x-example'] = '['.\strtoupper(Template::fromCamelCaseToSnake($node['name'])).']'; $node['schema']['x-example'] = '['.\strtoupper(Template::fromCamelCaseToSnake($node['name'])).']';
break; break;
case 'Utopia\Validator\Boolean': case 'Utopia\Validator\Boolean':
$node['schema']['type'] = 'boolean'; $node['schema']['type'] = $validator->getType();
$node['schema']['x-example'] = false; $node['schema']['x-example'] = false;
break; break;
case 'Appwrite\Database\Validator\UID': case 'Appwrite\Database\Validator\UID':
$node['schema']['type'] = 'string'; $node['schema']['type'] = $validator->getType();
$node['schema']['x-example'] = '['.\strtoupper(Template::fromCamelCaseToSnake($node['name'])).']'; $node['schema']['x-example'] = '['.\strtoupper(Template::fromCamelCaseToSnake($node['name'])).']';
break; break;
case 'Appwrite\Network\Validator\Email': case 'Appwrite\Network\Validator\Email':
$node['schema']['type'] = 'string'; $node['schema']['type'] = $validator->getType();
$node['schema']['format'] = 'email'; $node['schema']['format'] = 'email';
$node['schema']['x-example'] = 'email@example.com'; $node['schema']['x-example'] = 'email@example.com';
break; break;
case 'Appwrite\Network\Validator\URL': case 'Appwrite\Network\Validator\URL':
$node['schema']['type'] = 'string'; $node['schema']['type'] = $validator->getType();
$node['schema']['format'] = 'url'; $node['schema']['format'] = 'url';
$node['schema']['x-example'] = 'https://example.com'; $node['schema']['x-example'] = 'https://example.com';
break; break;
@ -261,7 +262,7 @@ class OpenAPI3 extends Format
break; break;
case 'Utopia\Storage\Validator\File': case 'Utopia\Storage\Validator\File':
$consumes = ['multipart/form-data']; $consumes = ['multipart/form-data'];
$node['schema']['type'] = 'string'; $node['schema']['type'] = $validator->getType();
$node['schema']['format'] = 'binary'; $node['schema']['format'] = 'binary';
break; break;
case 'Utopia\Validator\ArrayList': case 'Utopia\Validator\ArrayList':
@ -271,24 +272,24 @@ class OpenAPI3 extends Format
]; ];
break; break;
case 'Appwrite\Auth\Validator\Password': case 'Appwrite\Auth\Validator\Password':
$node['schema']['type'] = 'string'; $node['schema']['type'] = $validator->getType();
$node['schema']['format'] = 'format'; $node['schema']['format'] = 'password';
$node['schema']['x-example'] = 'password'; $node['schema']['x-example'] = 'password';
break; break;
case 'Utopia\Validator\Range': /** @var \Utopia\Validator\Range $validator */ case 'Utopia\Validator\Range': /** @var \Utopia\Validator\Range $validator */
$node['schema']['type'] = 'integer'; $node['schema']['type'] = $validator->getType() === Validator::TYPE_FLOAT ? 'number': $validator->getType();
$node['schema']['format'] = 'int32'; $node['schema']['format'] = $validator->getType() == Validator::TYPE_INTEGER ? 'int32' : 'float';
$node['schema']['x-example'] = $validator->getMin(); $node['schema']['x-example'] = $validator->getMin();
break; break;
case 'Utopia\Validator\Numeric': case 'Utopia\Validator\Numeric':
$node['schema']['type'] = 'integer'; $node['schema']['type'] = $validator->getType();
$node['schema']['format'] = 'int32'; $node['schema']['format'] = 'int32';
break; break;
case 'Utopia\Validator\Length': case 'Utopia\Validator\Length':
$node['schema']['type'] = 'string'; $node['schema']['type'] = $validator->getType();
break; break;
case 'Appwrite\Network\Validator\Host': case 'Appwrite\Network\Validator\Host':
$node['schema']['type'] = 'string'; $node['schema']['type'] = $validator->getType();
$node['schema']['format'] = 'url'; $node['schema']['format'] = 'url';
$node['schema']['x-example'] = 'https://example.com'; $node['schema']['x-example'] = 'https://example.com';
break; break;

View file

@ -6,6 +6,7 @@ use Appwrite\Specification\Format;
use Appwrite\Template\Template; use Appwrite\Template\Template;
use Appwrite\Utopia\Response\Model; use Appwrite\Utopia\Response\Model;
use stdClass; use stdClass;
use Utopia\Validator;
class Swagger2 extends Format class Swagger2 extends Format
{ {
@ -227,24 +228,24 @@ class Swagger2 extends Format
switch ((!empty($validator)) ? \get_class($validator) : '') { switch ((!empty($validator)) ? \get_class($validator) : '') {
case 'Utopia\Validator\Text': case 'Utopia\Validator\Text':
$node['type'] = 'string'; $node['type'] = $validator->getType();
$node['x-example'] = '['.\strtoupper(Template::fromCamelCaseToSnake($node['name'])).']'; $node['x-example'] = '['.\strtoupper(Template::fromCamelCaseToSnake($node['name'])).']';
break; break;
case 'Utopia\Validator\Boolean': case 'Utopia\Validator\Boolean':
$node['type'] = 'boolean'; $node['type'] = $validator->getType();
$node['x-example'] = false; $node['x-example'] = false;
break; break;
case 'Appwrite\Database\Validator\UID': case 'Appwrite\Database\Validator\UID':
$node['type'] = 'string'; $node['type'] = $validator->getType();
$node['x-example'] = '['.\strtoupper(Template::fromCamelCaseToSnake($node['name'])).']'; $node['x-example'] = '['.\strtoupper(Template::fromCamelCaseToSnake($node['name'])).']';
break; break;
case 'Appwrite\Network\Validator\Email': case 'Appwrite\Network\Validator\Email':
$node['type'] = 'string'; $node['type'] = $validator->getType();
$node['format'] = 'email'; $node['format'] = 'email';
$node['x-example'] = 'email@example.com'; $node['x-example'] = 'email@example.com';
break; break;
case 'Appwrite\Network\Validator\URL': case 'Appwrite\Network\Validator\URL':
$node['type'] = 'string'; $node['type'] = $validator->getType();
$node['format'] = 'url'; $node['format'] = 'url';
$node['x-example'] = 'https://example.com'; $node['x-example'] = 'https://example.com';
break; break;
@ -258,7 +259,7 @@ class Swagger2 extends Format
break; break;
case 'Utopia\Storage\Validator\File': case 'Utopia\Storage\Validator\File':
$consumes = ['multipart/form-data']; $consumes = ['multipart/form-data'];
$node['type'] = 'file'; $node['type'] = $validator->getType();
break; break;
case 'Utopia\Validator\ArrayList': case 'Utopia\Validator\ArrayList':
$node['type'] = 'array'; $node['type'] = 'array';
@ -268,24 +269,24 @@ class Swagger2 extends Format
]; ];
break; break;
case 'Appwrite\Auth\Validator\Password': case 'Appwrite\Auth\Validator\Password':
$node['type'] = 'string'; $node['type'] = $validator->getType();
$node['format'] = 'format'; $node['format'] = 'password';
$node['x-example'] = 'password'; $node['x-example'] = 'password';
break; break;
case 'Utopia\Validator\Range': /** @var \Utopia\Validator\Range $validator */ case 'Utopia\Validator\Range': /** @var \Utopia\Validator\Range $validator */
$node['type'] = 'integer'; $node['type'] = $validator->getType() === Validator::TYPE_FLOAT ? 'number': $validator->getType();
$node['format'] = 'int32'; $node['format'] = $validator->getType() == Validator::TYPE_INTEGER ? 'int32' : 'float';
$node['x-example'] = $validator->getMin(); $node['x-example'] = $validator->getMin();
break; break;
case 'Utopia\Validator\Numeric': case 'Utopia\Validator\Numeric':
$node['type'] = 'integer'; $node['type'] = $validator->getType();
$node['format'] = 'int32'; $node['format'] = 'int32';
break; break;
case 'Utopia\Validator\Length': case 'Utopia\Validator\Length':
$node['type'] = 'string'; $node['type'] = $validator->getType();
break; break;
case 'Appwrite\Network\Validator\Host': case 'Appwrite\Network\Validator\Host':
$node['type'] = 'string'; $node['type'] = $validator->getType();
$node['format'] = 'url'; $node['format'] = 'url';
$node['x-example'] = 'https://example.com'; $node['x-example'] = 'https://example.com';
break; break;