mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Continue work on Transfers
This commit is contained in:
+1
-1
@@ -29,7 +29,7 @@ ENV VITE_APPWRITE_GROWTH_ENDPOINT=$VITE_APPWRITE_GROWTH_ENDPOINT
|
||||
RUN npm ci
|
||||
RUN npm run build
|
||||
|
||||
FROM appwrite/base:0.1.0 as final
|
||||
FROM ionic/base as final
|
||||
|
||||
LABEL maintainer="team@appwrite.io"
|
||||
|
||||
|
||||
@@ -3641,6 +3641,17 @@ $collections = [
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('search'),
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => 16384,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
]
|
||||
],
|
||||
'indexes' => [
|
||||
@@ -3679,6 +3690,13 @@ $collections = [
|
||||
'lengths' => [Database::LENGTH_KEY],
|
||||
'orders' => [Database::ORDER_ASC],
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('_fulltext_search'),
|
||||
'type' => Database::INDEX_FULLTEXT,
|
||||
'attributes' => ['search'],
|
||||
'lengths' => [],
|
||||
'orders' => [],
|
||||
]
|
||||
],
|
||||
],
|
||||
|
||||
@@ -3730,6 +3748,17 @@ $collections = [
|
||||
'default' => new \stdClass(),
|
||||
'array' => false,
|
||||
'filters' => ['json'],
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('search'),
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => 16384,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
]
|
||||
],
|
||||
'indexes' => [
|
||||
@@ -3746,6 +3775,13 @@ $collections = [
|
||||
'attributes' => ['name'],
|
||||
'lengths' => [Database::LENGTH_KEY],
|
||||
'orders' => [Database::ORDER_ASC],
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('_fulltext_search'),
|
||||
'type' => Database::INDEX_FULLTEXT,
|
||||
'attributes' => ['search'],
|
||||
'lengths' => [],
|
||||
'orders' => [],
|
||||
]
|
||||
]
|
||||
],
|
||||
@@ -3798,6 +3834,17 @@ $collections = [
|
||||
'default' => new \stdClass(),
|
||||
'array' => false,
|
||||
'filters' => ['json'],
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('search'),
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => 16384,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
]
|
||||
],
|
||||
'indexes' => [
|
||||
@@ -3814,6 +3861,13 @@ $collections = [
|
||||
'attributes' => ['name'],
|
||||
'lengths' => [Database::LENGTH_KEY],
|
||||
'orders' => [Database::ORDER_ASC],
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('_fulltext_search'),
|
||||
'type' => Database::INDEX_FULLTEXT,
|
||||
'attributes' => ['search'],
|
||||
'lengths' => [],
|
||||
'orders' => [],
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -77,16 +77,13 @@ App::post('/v1/transfers')
|
||||
|
||||
$eventsInstance->setParam('transferId', $transfer->getId());
|
||||
|
||||
if ($next) {
|
||||
// Async task reschedule
|
||||
$functionEvent = new Transfer();
|
||||
$functionEvent
|
||||
->setTransfer($transfer)
|
||||
->setType('schedule')
|
||||
->setUser($user)
|
||||
->setProject($project)
|
||||
->schedule(new \DateTime($next));
|
||||
}
|
||||
// Trigger Transfer
|
||||
$event = new Transfer();
|
||||
$event
|
||||
->setTransfer($transfer)
|
||||
->setProject($project)
|
||||
->setUser($user)
|
||||
->trigger();
|
||||
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_CREATED)
|
||||
@@ -163,6 +160,52 @@ App::get('/v1/transfers/:transferId')
|
||||
$response->dynamic($transfer, Response::MODEL_TRANSFER);
|
||||
});
|
||||
|
||||
App::post('/v1/transfers/:transferId')
|
||||
->groups(['api', 'transfers'])
|
||||
->desc('Retry Transfer')
|
||||
->label('scope', 'transfers.write')
|
||||
->label('event', 'transfers.[transferId].retry')
|
||||
->label('audits.event', 'transfer.retry')
|
||||
->label('audits.resource', 'transfer/{request.transferId}')
|
||||
->label('sdk.auth', [APP_AUTH_TYPE_KEY])
|
||||
->label('sdk.namespace', 'transfers')
|
||||
->label('sdk.method', 'retry')
|
||||
->label('sdk.description', '/docs/references/transfers/retry-transfer.md')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_TRANSFER)
|
||||
->param('transferId', '', new UID(), 'Transfer unique ID.')
|
||||
->inject('response')
|
||||
->inject('dbForProject')
|
||||
->inject('project')
|
||||
->inject('user')
|
||||
->inject('events')
|
||||
->action(function (string $transferId, Response $response, Database $dbForProject, Document $project, Document $user, Event $eventInstance) {
|
||||
$transfer = $dbForProject->getDocument('transfers', $transferId);
|
||||
|
||||
if ($transfer->isEmpty()) {
|
||||
throw new Exception(Exception::TRANSFER_NOT_FOUND);
|
||||
}
|
||||
|
||||
// if ($transfer->getAttribute('status') !== 'failed') {
|
||||
// throw new Exception(Exception::TRANSFER_IN_PROGRESS, 'Transfer not failed');
|
||||
// }
|
||||
|
||||
$transfer
|
||||
->setAttribute('status', 'pending')
|
||||
->setAttribute('dateUpdated', \time());
|
||||
|
||||
// Trigger Transfer
|
||||
$event = new Transfer();
|
||||
$event
|
||||
->setTransfer($transfer)
|
||||
->setProject($project)
|
||||
->setUser($user)
|
||||
->trigger();
|
||||
|
||||
$response->noContent();
|
||||
});
|
||||
|
||||
App::delete('/v1/transfers/:transferId')
|
||||
->groups(['api', 'transfers'])
|
||||
->desc('Delete Transfer')
|
||||
@@ -305,22 +348,22 @@ App::post('/v1/transfers/source/:sourceId/validate')
|
||||
case 'appwrite': {
|
||||
$testAdapter = new SourcesAppwrite($authData['project'], $authData['endpoint'], $authData['key']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
case 'firebase': {
|
||||
$testAdapter = new Firebase($authData['authObject'], Firebase::AUTH_SERVICEACCOUNT);
|
||||
break;
|
||||
}
|
||||
}
|
||||
case 'supabase': {
|
||||
$testAdapter = new Supabase($authData['url'], $authData['database'], $authData['username'], $authData['password'], $authData['port']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
case 'nhost': {
|
||||
$testAdapter = new NHost($authData['url'], $authData['database'], $authData['username'], $authData['password'], $authData['port']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
default: {
|
||||
throw new Exception(Exception::TRANSFER_SOURCE_NOT_FOUND, 'Source not found', 404);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result = $testAdapter->check($resources);
|
||||
@@ -497,12 +540,12 @@ App::post('/v1/transfers/destination/:destinationId/validate')
|
||||
|
||||
switch ($destination['type']) {
|
||||
case 'appwrite': {
|
||||
$testAdapter = new Appwrite($authData['projectId'], $authData['endpoint'], $authData['key']);
|
||||
break;
|
||||
}
|
||||
$testAdapter = new Appwrite($authData['projectId'], $authData['endpoint'], $authData['key']);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new Exception(Exception::TRANSFER_DESTINATION_NOT_FOUND, 'Destination not found', 404);
|
||||
}
|
||||
throw new Exception(Exception::TRANSFER_DESTINATION_NOT_FOUND, 'Destination not found', 404);
|
||||
}
|
||||
}
|
||||
|
||||
$result = $testAdapter->check($resources);
|
||||
|
||||
@@ -1,19 +1,10 @@
|
||||
<?php
|
||||
|
||||
use Appwrite\Event\Event;
|
||||
use Appwrite\Event\Mail;
|
||||
use Appwrite\Network\Validator\CNAME;
|
||||
use Appwrite\Resque\Worker;
|
||||
use Appwrite\Template\Template;
|
||||
use MongoDB\Operation\Update;
|
||||
use Utopia\App;
|
||||
use Utopia\CLI\Console;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\Query;
|
||||
use Utopia\Domains\Domain;
|
||||
use Utopia\Locale\Locale;
|
||||
use Utopia\Transfer\Destinations\Appwrite as DestinationsAppwrite;
|
||||
use Utopia\Transfer\Source;
|
||||
use Utopia\Transfer\Sources\Appwrite;
|
||||
@@ -37,7 +28,7 @@ class TransfersV1 extends Worker
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return "Transfers";
|
||||
return "transfers";
|
||||
}
|
||||
|
||||
public function init(): void
|
||||
@@ -46,17 +37,10 @@ class TransfersV1 extends Worker
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
switch ($this->args['type']) {
|
||||
case 'processTransfer':
|
||||
$this->processTransfer();
|
||||
break;
|
||||
case 'processVerification':
|
||||
$this->processVerification();
|
||||
break;
|
||||
default:
|
||||
throw new \Exception('Invalid transfer type');
|
||||
break;
|
||||
}
|
||||
var_dump("Test");
|
||||
|
||||
// Process
|
||||
$this->processTransfer();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+14
-13
@@ -83,6 +83,7 @@ services:
|
||||
- ./docs:/usr/src/code/docs
|
||||
- ./public:/usr/src/code/public
|
||||
- ./src:/usr/src/code/src
|
||||
- ./vendor:/usr/src/code/vendor
|
||||
depends_on:
|
||||
- mariadb
|
||||
- redis
|
||||
@@ -585,7 +586,7 @@ services:
|
||||
volumes:
|
||||
- ./app:/usr/src/code/app
|
||||
- ./src:/usr/src/code/src
|
||||
- ./vendor:/usr/src/code/vendor
|
||||
- ./tests:/usr/src/code/tests
|
||||
depends_on:
|
||||
- redis
|
||||
environment:
|
||||
@@ -807,18 +808,18 @@ services:
|
||||
# ports:
|
||||
# - "8081:8081"
|
||||
|
||||
# resque:
|
||||
# image: appwrite/resque-web:1.1.0
|
||||
# restart: unless-stopped
|
||||
# networks:
|
||||
# - appwrite
|
||||
# ports:
|
||||
# - "5678:5678"
|
||||
# environment:
|
||||
# - RESQUE_WEB_HOST=redis
|
||||
# - RESQUE_WEB_PORT=6379
|
||||
# - RESQUE_WEB_HTTP_BASIC_AUTH_USER=user
|
||||
# - RESQUE_WEB_HTTP_BASIC_AUTH_PASSWORD=password
|
||||
resque:
|
||||
image: appwrite/resque-web:1.1.0
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- appwrite
|
||||
ports:
|
||||
- "5678:5678"
|
||||
environment:
|
||||
- RESQUE_WEB_HOST=redis
|
||||
- RESQUE_WEB_PORT=6379
|
||||
- RESQUE_WEB_HTTP_BASIC_AUTH_USER=user
|
||||
- RESQUE_WEB_HTTP_BASIC_AUTH_PASSWORD=password
|
||||
|
||||
# chronograf:
|
||||
# image: chronograf:1.6
|
||||
|
||||
@@ -11,37 +11,12 @@ class Transfer extends Event
|
||||
{
|
||||
protected string $type = '';
|
||||
protected ?Document $transfer = null;
|
||||
protected ?Document $source = null;
|
||||
protected ?Document $destination = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(Event::TRANSFER_QUEUE_NAME, Event::TRANSFER_CLASS_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets type for the transfer event.
|
||||
*
|
||||
* @param string $type
|
||||
* @return self
|
||||
*/
|
||||
public function setType(string $type): self
|
||||
{
|
||||
$this->type = $type;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns set type for the function event.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets transfer document for the transfer event.
|
||||
*
|
||||
@@ -66,53 +41,31 @@ class Transfer extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets source document for the transfer event.
|
||||
*
|
||||
* @param Document $source
|
||||
* Sets transfer type for the transfer event.
|
||||
*
|
||||
* @param string $type
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setSource(Document $source): self
|
||||
public function setType(string $type): self
|
||||
{
|
||||
$this->source = $source;
|
||||
$this->type = $type;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns set source document for the function event.
|
||||
*
|
||||
* @return null|Document
|
||||
* Returns set transfer type for the transfer event.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSource(): ?Document
|
||||
public function getType(): string
|
||||
{
|
||||
return $this->source;
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets destination document for the transfer event.
|
||||
*
|
||||
* @param Document $destination
|
||||
* @return self
|
||||
*/
|
||||
public function setDestination(Document $destination): self
|
||||
{
|
||||
$this->destination = $destination;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns set destination document for the function event.
|
||||
*
|
||||
* @return null|Document
|
||||
*/
|
||||
public function getDestination(): ?Document
|
||||
{
|
||||
return $this->destination;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the function event and sends it to the functions worker.
|
||||
* Executes the transfer event and sends it to the transfers worker.
|
||||
*
|
||||
* @return string|bool
|
||||
* @throws \InvalidArgumentException
|
||||
@@ -122,16 +75,12 @@ class Transfer extends Event
|
||||
return Resque::enqueue($this->queue, $this->class, [
|
||||
'project' => $this->project,
|
||||
'user' => $this->user,
|
||||
'transfer' => $this->transfer,
|
||||
'source' => $this->source,
|
||||
'destination' => $this->destination,
|
||||
'type' => $this->type,
|
||||
'payload' => $this->payload
|
||||
'transfer' => $this->transfer
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules the function event and schedules it in the functions worker queue.
|
||||
* Schedules the transfer event and schedules it in the transfers worker queue.
|
||||
*
|
||||
* @param \DateTime|int $at
|
||||
* @return void
|
||||
@@ -143,11 +92,7 @@ class Transfer extends Event
|
||||
ResqueScheduler::enqueueAt($at, $this->queue, $this->class, [
|
||||
'project' => $this->project,
|
||||
'user' => $this->user,
|
||||
'transfer' => $this->transfer,
|
||||
'source' => $this->source,
|
||||
'destination' => $this->destination,
|
||||
'type' => $this->type,
|
||||
'payload' => $this->payload
|
||||
'transfer' => $this->transfer
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -190,6 +190,7 @@ class Exception extends \Exception
|
||||
public const TRANSFER_DESTINATION_NOT_FOUND = 'transfer_destination_not_found';
|
||||
public const TRANSFER_SOURCE_FAILED = 'transfer_source_failed';
|
||||
public const TRANSFER_DESTINATION_FAILED = 'transfer_destination_failed';
|
||||
public const TRANSFER_IN_PROGRESS = 'transfer_in_progress';
|
||||
|
||||
protected $type = '';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user