mirror of
https://github.com/appwrite/appwrite
synced 2026-05-23 00:49:02 +00:00
use inline validator
This commit is contained in:
parent
60e57eb9c5
commit
08c9db7c60
2 changed files with 4 additions and 19 deletions
|
|
@ -17,7 +17,7 @@ use Utopia\Database\Validator\Authorization;
|
|||
use Utopia\Database\Validator\Datetime as DatetimeValidator;
|
||||
use Utopia\Database\Validator\UID;
|
||||
use Utopia\Platform\Scope\HTTP;
|
||||
use Utopia\Validator\Text;
|
||||
use Utopia\Validator\Nullable;
|
||||
|
||||
class Create extends Action
|
||||
{
|
||||
|
|
@ -61,7 +61,7 @@ class Create extends Action
|
|||
))
|
||||
->param('bucketId', '', new UID(), 'Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).')
|
||||
->param('fileId', '', new UID(), 'File unique ID.')
|
||||
->param('expire', null, new Text(100), 'Token expiry date', true)
|
||||
->param('expire', null, new Nullable(new DatetimeValidator(requireDateInFuture: true)), 'Token expiry date', true)
|
||||
->inject('response')
|
||||
->inject('dbForProject')
|
||||
->inject('queueForEvents')
|
||||
|
|
@ -70,14 +70,6 @@ class Create extends Action
|
|||
|
||||
public function action(string $bucketId, string $fileId, ?string $expire, Response $response, Database $dbForProject, Event $queueForEvents): void
|
||||
{
|
||||
if (!is_null($expire)) {
|
||||
$validator = new DatetimeValidator(requireDateInFuture: true, precision: DateTimeValidator::PRECISION_DAYS, offset: 0);
|
||||
if (!$validator->isValid($expire)) {
|
||||
throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Token expiry date must be a valid date, and at least 1 day from now');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @var Document $bucket
|
||||
* @var Document $file
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ use Utopia\Database\Validator\Datetime as DatetimeValidator;
|
|||
use Utopia\Database\Validator\UID;
|
||||
use Utopia\Platform\Action;
|
||||
use Utopia\Platform\Scope\HTTP;
|
||||
use Utopia\Validator\Text;
|
||||
use Utopia\Validator\Nullable;
|
||||
|
||||
class Update extends Action
|
||||
{
|
||||
|
|
@ -57,7 +57,7 @@ class Update extends Action
|
|||
contentType: ContentType::JSON
|
||||
))
|
||||
->param('tokenId', '', new UID(), 'Token unique ID.')
|
||||
->param('expire', null, new Text(100), 'File token expiry date', true)
|
||||
->param('expire', null, new Nullable(new DatetimeValidator(requireDateInFuture: true)), 'File token expiry date', true)
|
||||
->inject('response')
|
||||
->inject('dbForProject')
|
||||
->inject('queueForEvents')
|
||||
|
|
@ -66,13 +66,6 @@ class Update extends Action
|
|||
|
||||
public function action(string $tokenId, ?string $expire, Response $response, Database $dbForProject, Event $queueForEvents)
|
||||
{
|
||||
if (!is_null($expire)) {
|
||||
$validator = new DatetimeValidator(requireDateInFuture: true, precision: DateTimeValidator::PRECISION_DAYS, offset: 0);
|
||||
if (!$validator->isValid($expire)) {
|
||||
throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Token expiry date must be a valid date, and at least 1 day from now');
|
||||
}
|
||||
}
|
||||
|
||||
$token = $dbForProject->getDocument('resourceTokens', $tokenId);
|
||||
|
||||
if ($token->isEmpty()) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue