Merge remote-tracking branch 'upstream/0.7.x' into feat-dart-env
This commit is contained in:
commit
596c72bb85
3
.env
3
.env
|
@ -35,4 +35,7 @@ _APP_FUNCTIONS_CPUS=1
|
||||||
_APP_FUNCTIONS_MEMORY=128
|
_APP_FUNCTIONS_MEMORY=128
|
||||||
_APP_FUNCTIONS_MEMORY_SWAP=128
|
_APP_FUNCTIONS_MEMORY_SWAP=128
|
||||||
_APP_MAINTENANCE_INTERVAL=86400
|
_APP_MAINTENANCE_INTERVAL=86400
|
||||||
|
_APP_MAINTENANCE_RETENTION_EXECUTION=1209600
|
||||||
|
_APP_MAINTENANCE_RETENTION_ABUSE=86400
|
||||||
|
_APP_MAINTENANCE_RETENTION_AUDIT=1209600
|
||||||
_APP_USAGE_STATS=enabled
|
_APP_USAGE_STATS=enabled
|
|
@ -100,7 +100,11 @@ ENV _APP_SERVER=swoole \
|
||||||
_APP_SETUP=self-hosted \
|
_APP_SETUP=self-hosted \
|
||||||
_APP_VERSION=$VERSION \
|
_APP_VERSION=$VERSION \
|
||||||
_APP_USAGE_STATS=enabled \
|
_APP_USAGE_STATS=enabled \
|
||||||
|
# 14 Days = 1209600 s
|
||||||
|
_APP_MAINTENANCE_RETENTION_EXECUTION=1209600 \
|
||||||
|
_APP_MAINTENANCE_RETENTION_AUDIT=1209600 \
|
||||||
# 1 Day = 86400 s
|
# 1 Day = 86400 s
|
||||||
|
_APP_MAINTENANCE_RETENTION_ABUSE=86400 \
|
||||||
_APP_MAINTENANCE_INTERVAL=86400
|
_APP_MAINTENANCE_INTERVAL=86400
|
||||||
#ENV _APP_SMTP_SECURE ''
|
#ENV _APP_SMTP_SECURE ''
|
||||||
#ENV _APP_SMTP_USERNAME ''
|
#ENV _APP_SMTP_USERNAME ''
|
||||||
|
|
|
@ -374,6 +374,30 @@ return [
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'question' => '',
|
'question' => '',
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'name' => '_APP_MAINTENANCE_RETENTION_EXECUTION',
|
||||||
|
'description' => 'The maximum duration (in seconds) upto which to retain execution logs. The default value is 1209600 seconds (14 days).',
|
||||||
|
'introduction' => '0.7.0',
|
||||||
|
'default' => '1209600',
|
||||||
|
'required' => false,
|
||||||
|
'question' => '',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => '_APP_MAINTENANCE_RETENTION_AUDIT',
|
||||||
|
'description' => 'IThe maximum duration (in seconds) upto which to retain audit logs. The default value is 1209600 seconds (14 days).',
|
||||||
|
'introduction' => '0.7.0',
|
||||||
|
'default' => '1209600',
|
||||||
|
'required' => false,
|
||||||
|
'question' => '',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => '_APP_MAINTENANCE_RETENTION_ABUSE',
|
||||||
|
'description' => 'The maximum duration (in seconds) upto which to retain abuse logs. The default value is 86400 seconds (1 day).',
|
||||||
|
'introduction' => '0.7.0',
|
||||||
|
'default' => '86400',
|
||||||
|
'required' => false,
|
||||||
|
'question' => '',
|
||||||
|
]
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|
|
@ -4,11 +4,11 @@ use Appwrite\Database\Database;
|
||||||
use Appwrite\Database\Document;
|
use Appwrite\Database\Document;
|
||||||
use Appwrite\Database\Validator\Authorization;
|
use Appwrite\Database\Validator\Authorization;
|
||||||
use Appwrite\Database\Validator\UID;
|
use Appwrite\Database\Validator\UID;
|
||||||
use Appwrite\Storage\Storage;
|
use Utopia\Storage\Storage;
|
||||||
use Appwrite\Storage\Validator\File;
|
use Utopia\Storage\Validator\File;
|
||||||
use Appwrite\Storage\Validator\FileSize;
|
use Utopia\Storage\Validator\FileSize;
|
||||||
use Appwrite\Storage\Validator\FileType;
|
use Utopia\Storage\Validator\FileType;
|
||||||
use Appwrite\Storage\Validator\Upload;
|
use Utopia\Storage\Validator\Upload;
|
||||||
use Appwrite\Utopia\Response;
|
use Appwrite\Utopia\Response;
|
||||||
use Appwrite\Task\Validator\Cron;
|
use Appwrite\Task\Validator\Cron;
|
||||||
use Utopia\App;
|
use Utopia\App;
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
use Utopia\App;
|
use Utopia\App;
|
||||||
use Utopia\Exception;
|
use Utopia\Exception;
|
||||||
use Appwrite\Storage\Device\Local;
|
use Utopia\Storage\Device\Local;
|
||||||
use Appwrite\Storage\Storage;
|
use Utopia\Storage\Storage;
|
||||||
use Appwrite\ClamAV\Network;
|
use Appwrite\ClamAV\Network;
|
||||||
use Appwrite\Event\Event;
|
use Appwrite\Event\Event;
|
||||||
|
|
||||||
|
|
|
@ -13,11 +13,11 @@ use Appwrite\ClamAV\Network;
|
||||||
use Appwrite\Database\Database;
|
use Appwrite\Database\Database;
|
||||||
use Appwrite\Database\Document;
|
use Appwrite\Database\Document;
|
||||||
use Appwrite\Database\Validator\UID;
|
use Appwrite\Database\Validator\UID;
|
||||||
use Appwrite\Storage\Storage;
|
use Utopia\Storage\Storage;
|
||||||
use Appwrite\Storage\Validator\File;
|
use Utopia\Storage\Validator\File;
|
||||||
use Appwrite\Storage\Validator\FileSize;
|
use Utopia\Storage\Validator\FileSize;
|
||||||
use Appwrite\Storage\Validator\Upload;
|
use Utopia\Storage\Validator\Upload;
|
||||||
use Appwrite\Storage\Compression\Algorithms\GZIP;
|
use Utopia\Storage\Compression\Algorithms\GZIP;
|
||||||
use Appwrite\Resize\Resize;
|
use Appwrite\Resize\Resize;
|
||||||
use Appwrite\OpenSSL\OpenSSL;
|
use Appwrite\OpenSSL\OpenSSL;
|
||||||
use Appwrite\Utopia\Response;
|
use Appwrite\Utopia\Response;
|
||||||
|
|
|
@ -14,8 +14,8 @@ use Appwrite\Database\Database;
|
||||||
use Appwrite\Database\Document;
|
use Appwrite\Database\Document;
|
||||||
use Appwrite\Database\Validator\Authorization;
|
use Appwrite\Database\Validator\Authorization;
|
||||||
use Appwrite\Network\Validator\Origin;
|
use Appwrite\Network\Validator\Origin;
|
||||||
use Appwrite\Storage\Device\Local;
|
use Utopia\Storage\Device\Local;
|
||||||
use Appwrite\Storage\Storage;
|
use Utopia\Storage\Storage;
|
||||||
use Appwrite\Utopia\Response\Filters\V06;
|
use Appwrite\Utopia\Response\Filters\V06;
|
||||||
use Utopia\CLI\Console;
|
use Utopia\CLI\Console;
|
||||||
|
|
||||||
|
@ -83,9 +83,6 @@ App::init(function ($utopia, $request, $response, $console, $project, $user, $lo
|
||||||
: '.'.$request->getHostname()
|
: '.'.$request->getHostname()
|
||||||
);
|
);
|
||||||
|
|
||||||
Storage::setDevice('files', new Local(APP_STORAGE_UPLOADS.'/app-'.$project->getId()));
|
|
||||||
Storage::setDevice('functions', new Local(APP_STORAGE_FUNCTIONS.'/app-'.$project->getId()));
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Response format
|
* Response format
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -8,7 +8,7 @@ use Utopia\Validator\Numeric;
|
||||||
use Utopia\Validator\Text;
|
use Utopia\Validator\Text;
|
||||||
use Utopia\Validator\ArrayList;
|
use Utopia\Validator\ArrayList;
|
||||||
use Utopia\Validator\Host;
|
use Utopia\Validator\Host;
|
||||||
use Appwrite\Storage\Validator\File;
|
use Utopia\Storage\Validator\File;
|
||||||
|
|
||||||
App::get('/v1/mock/tests/foo')
|
App::get('/v1/mock/tests/foo')
|
||||||
->desc('Mock a get request for SDK tests')
|
->desc('Mock a get request for SDK tests')
|
||||||
|
|
|
@ -6,8 +6,8 @@ use Utopia\App;
|
||||||
use Utopia\Exception;
|
use Utopia\Exception;
|
||||||
use Utopia\Abuse\Abuse;
|
use Utopia\Abuse\Abuse;
|
||||||
use Utopia\Abuse\Adapters\TimeLimit;
|
use Utopia\Abuse\Adapters\TimeLimit;
|
||||||
use Appwrite\Storage\Device\Local;
|
use Utopia\Storage\Device\Local;
|
||||||
use Appwrite\Storage\Storage;
|
use Utopia\Storage\Storage;
|
||||||
|
|
||||||
App::init(function ($utopia, $request, $response, $project, $user, $register, $events, $audits, $usage, $deletes) {
|
App::init(function ($utopia, $request, $response, $project, $user, $register, $events, $audits, $usage, $deletes) {
|
||||||
/** @var Utopia\App $utopia */
|
/** @var Utopia\App $utopia */
|
||||||
|
|
|
@ -7,7 +7,7 @@ use Utopia\Domains\Domain;
|
||||||
use Appwrite\Database\Database;
|
use Appwrite\Database\Database;
|
||||||
use Appwrite\Database\Validator\Authorization;
|
use Appwrite\Database\Validator\Authorization;
|
||||||
use Appwrite\Database\Validator\UID;
|
use Appwrite\Database\Validator\UID;
|
||||||
use Appwrite\Storage\Storage;
|
use Utopia\Storage\Storage;
|
||||||
|
|
||||||
App::init(function ($layout) {
|
App::init(function ($layout) {
|
||||||
/** @var Utopia\View $layout */
|
/** @var Utopia\View $layout */
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
global $cli;
|
global $cli;
|
||||||
|
|
||||||
use Appwrite\ClamAV\Network;
|
use Appwrite\ClamAV\Network;
|
||||||
use Appwrite\Storage\Device\Local;
|
use Utopia\Storage\Device\Local;
|
||||||
use Appwrite\Storage\Storage;
|
use Utopia\Storage\Storage;
|
||||||
use Utopia\App;
|
use Utopia\App;
|
||||||
use Utopia\CLI\Console;
|
use Utopia\CLI\Console;
|
||||||
use Utopia\Domains\Domain;
|
use Utopia\Domains\Domain;
|
||||||
|
|
|
@ -12,10 +12,11 @@ Console::title('Maintenance V1');
|
||||||
|
|
||||||
Console::success(APP_NAME.' maintenance process v1 has started');
|
Console::success(APP_NAME.' maintenance process v1 has started');
|
||||||
|
|
||||||
function notifyDeleteExecutionLogs()
|
function notifyDeleteExecutionLogs(int $interval)
|
||||||
{
|
{
|
||||||
Resque::enqueue(Event::DELETE_QUEUE_NAME, Event::DELETE_CLASS_NAME, [
|
Resque::enqueue(Event::DELETE_QUEUE_NAME, Event::DELETE_CLASS_NAME, [
|
||||||
'type' => DELETE_TYPE_EXECUTIONS
|
'type' => DELETE_TYPE_EXECUTIONS,
|
||||||
|
'timestamp' => time() - $interval
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,14 +42,15 @@ $cli
|
||||||
->action(function () {
|
->action(function () {
|
||||||
// # of days in seconds (1 day = 86400s)
|
// # of days in seconds (1 day = 86400s)
|
||||||
$interval = (int) App::getEnv('_APP_MAINTENANCE_INTERVAL', '86400');
|
$interval = (int) App::getEnv('_APP_MAINTENANCE_INTERVAL', '86400');
|
||||||
|
$executionLogsRetention = (int) App::getEnv('_APP_MAINTENANCE_RETENTION_EXECUTION', '1209600');
|
||||||
|
$auditLogRetention = (int) App::getEnv('_APP_MAINTENANCE_RETENTION_AUDIT', '1209600');
|
||||||
|
$abuseLogsRetention = (int) App::getEnv('_APP_MAINTENANCE_RETENTION_ABUSE', '86400');
|
||||||
|
|
||||||
Console::loop(function() use ($interval){
|
Console::loop(function() use ($interval, $executionLogsRetention, $abuseLogsRetention, $auditLogRetention){
|
||||||
$time = date('d-m-Y H:i:s', time());
|
$time = date('d-m-Y H:i:s', time());
|
||||||
Console::info("[{$time}] Notifying deletes workers every {$interval} seconds");
|
Console::info("[{$time}] Notifying deletes workers every {$interval} seconds");
|
||||||
notifyDeleteExecutionLogs();
|
notifyDeleteExecutionLogs($executionLogsRetention);
|
||||||
notifyDeleteAbuseLogs($interval);
|
notifyDeleteAbuseLogs($abuseLogsRetention);
|
||||||
notifyDeleteAuditLogs($interval);
|
notifyDeleteAuditLogs($auditLogRetention);
|
||||||
|
|
||||||
}, $interval);
|
}, $interval);
|
||||||
|
|
||||||
});
|
});
|
|
@ -279,11 +279,10 @@ services:
|
||||||
- _APP_REDIS_HOST
|
- _APP_REDIS_HOST
|
||||||
- _APP_REDIS_PORT
|
- _APP_REDIS_PORT
|
||||||
- _APP_MAINTENANCE_INTERVAL
|
- _APP_MAINTENANCE_INTERVAL
|
||||||
- _APP_DB_HOST
|
- _APP_MAINTENANCE_RETENTION_EXECUTION
|
||||||
- _APP_DB_PORT
|
- _APP_MAINTENANCE_RETENTION_ABUSE
|
||||||
- _APP_DB_SCHEMA
|
- _APP_MAINTENANCE_RETENTION_AUDIT
|
||||||
- _APP_DB_USER
|
|
||||||
- _APP_DB_PASS
|
|
||||||
|
|
||||||
appwrite-schedule:
|
appwrite-schedule:
|
||||||
image: appwrite/appwrite:<?php echo $version."\n"; ?>
|
image: appwrite/appwrite:<?php echo $version."\n"; ?>
|
||||||
|
|
|
@ -5,7 +5,7 @@ use Appwrite\Database\Adapter\MySQL as MySQLAdapter;
|
||||||
use Appwrite\Database\Adapter\Redis as RedisAdapter;
|
use Appwrite\Database\Adapter\Redis as RedisAdapter;
|
||||||
use Appwrite\Database\Document;
|
use Appwrite\Database\Document;
|
||||||
use Appwrite\Database\Validator\Authorization;
|
use Appwrite\Database\Validator\Authorization;
|
||||||
use Appwrite\Storage\Device\Local;
|
use Utopia\Storage\Device\Local;
|
||||||
use Utopia\Abuse\Abuse;
|
use Utopia\Abuse\Abuse;
|
||||||
use Utopia\Abuse\Adapters\TimeLimit;
|
use Utopia\Abuse\Adapters\TimeLimit;
|
||||||
use Utopia\CLI\Console;
|
use Utopia\CLI\Console;
|
||||||
|
@ -59,7 +59,7 @@ class DeletesV1
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DELETE_TYPE_EXECUTIONS:
|
case DELETE_TYPE_EXECUTIONS:
|
||||||
$this->deleteExecutionLogs();
|
$this->deleteExecutionLogs($this->args['timestamp']);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DELETE_TYPE_AUDIT:
|
case DELETE_TYPE_AUDIT:
|
||||||
|
@ -121,16 +121,17 @@ class DeletesV1
|
||||||
], $this->getProjectDB($projectId));
|
], $this->getProjectDB($projectId));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function deleteExecutionLogs()
|
protected function deleteExecutionLogs($timestamp)
|
||||||
{
|
{
|
||||||
$this->deleteForProjectIds(function($projectId) {
|
$this->deleteForProjectIds(function($projectId) use ($timestamp) {
|
||||||
if (!($projectDB = $this->getProjectDB($projectId))) {
|
if (!($projectDB = $this->getProjectDB($projectId))) {
|
||||||
throw new Exception('Failed to get projectDB for project '.$projectId);
|
throw new Exception('Failed to get projectDB for project '.$projectId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete Executions
|
// Delete Executions
|
||||||
$this->deleteByGroup([
|
$this->deleteByGroup([
|
||||||
'$collection='.Database::SYSTEM_COLLECTION_EXECUTIONS
|
'$collection='.Database::SYSTEM_COLLECTION_EXECUTIONS,
|
||||||
|
'dateCreated<'.$timestamp
|
||||||
], $projectDB);
|
], $projectDB);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@
|
||||||
"utopia-php/domains": "0.2.*",
|
"utopia-php/domains": "0.2.*",
|
||||||
"utopia-php/swoole": "0.2.*",
|
"utopia-php/swoole": "0.2.*",
|
||||||
"utopia-php/system": "0.3.*",
|
"utopia-php/system": "0.3.*",
|
||||||
|
"utopia-php/storage": "0.1.*",
|
||||||
|
|
||||||
"resque/php-resque": "1.3.6",
|
"resque/php-resque": "1.3.6",
|
||||||
"matomo/device-detector": "3.13.0",
|
"matomo/device-detector": "3.13.0",
|
||||||
|
|
52
composer.lock
generated
52
composer.lock
generated
|
@ -1695,6 +1695,58 @@
|
||||||
},
|
},
|
||||||
"time": "2020-10-24T08:51:37+00:00"
|
"time": "2020-10-24T08:51:37+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "utopia-php/storage",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/utopia-php/storage.git",
|
||||||
|
"reference": "00e9045cee6bd1ec1d1f27329c329494ef420c19"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/utopia-php/storage/zipball/00e9045cee6bd1ec1d1f27329c329494ef420c19",
|
||||||
|
"reference": "00e9045cee6bd1ec1d1f27329c329494ef420c19",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=7.4",
|
||||||
|
"utopia-php/framework": "0.10.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "^9.3",
|
||||||
|
"vimeo/psalm": "4.0.1"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Utopia\\Storage\\": "src/Storage"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Eldad Fux",
|
||||||
|
"email": "eldad@appwrite.io"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "A simple Storage library to manage application storage",
|
||||||
|
"keywords": [
|
||||||
|
"framework",
|
||||||
|
"php",
|
||||||
|
"storage",
|
||||||
|
"upf",
|
||||||
|
"utopia"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/utopia-php/storage/issues",
|
||||||
|
"source": "https://github.com/utopia-php/storage/tree/0.1.0"
|
||||||
|
},
|
||||||
|
"time": "2021-01-22T07:27:20+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "utopia-php/swoole",
|
"name": "utopia-php/swoole",
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
|
|
|
@ -330,6 +330,9 @@ services:
|
||||||
- _APP_REDIS_HOST
|
- _APP_REDIS_HOST
|
||||||
- _APP_REDIS_PORT
|
- _APP_REDIS_PORT
|
||||||
- _APP_MAINTENANCE_INTERVAL
|
- _APP_MAINTENANCE_INTERVAL
|
||||||
|
- _APP_MAINTENANCE_RETENTION_EXECUTION
|
||||||
|
- _APP_MAINTENANCE_RETENTION_ABUSE
|
||||||
|
- _APP_MAINTENANCE_RETENTION_AUDIT
|
||||||
|
|
||||||
appwrite-schedule:
|
appwrite-schedule:
|
||||||
entrypoint: schedule
|
entrypoint: schedule
|
||||||
|
|
|
@ -218,7 +218,7 @@ class OpenAPI3 extends Format
|
||||||
$node['schema']['x-example'] = '{}';
|
$node['schema']['x-example'] = '{}';
|
||||||
//$node['schema']['format'] = 'json';
|
//$node['schema']['format'] = 'json';
|
||||||
break;
|
break;
|
||||||
case 'Appwrite\Storage\Validator\File':
|
case 'Utopia\Storage\Validator\File':
|
||||||
$consumes = ['multipart/form-data'];
|
$consumes = ['multipart/form-data'];
|
||||||
$node['schema']['type'] = 'string';
|
$node['schema']['type'] = 'string';
|
||||||
$node['schema']['format'] = 'binary';
|
$node['schema']['format'] = 'binary';
|
||||||
|
|
|
@ -210,7 +210,7 @@ class Swagger2 extends Format
|
||||||
$node['x-example'] = '{}';
|
$node['x-example'] = '{}';
|
||||||
//$node['format'] = 'json';
|
//$node['format'] = 'json';
|
||||||
break;
|
break;
|
||||||
case 'Appwrite\Storage\Validator\File':
|
case 'Utopia\Storage\Validator\File':
|
||||||
$consumes = ['multipart/form-data'];
|
$consumes = ['multipart/form-data'];
|
||||||
$node['type'] = 'file';
|
$node['type'] = 'file';
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Appwrite\Storage\Compression\Algorithms;
|
|
||||||
|
|
||||||
use Appwrite\Storage\Compression\Compression;
|
|
||||||
|
|
||||||
class GZIP extends Compression
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getName(): string
|
|
||||||
{
|
|
||||||
return 'gzip';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Compress.
|
|
||||||
*
|
|
||||||
* We use gzencode over gzcompress for better support of the first format among other tools.
|
|
||||||
* (http://stackoverflow.com/a/621987/2299554)
|
|
||||||
*
|
|
||||||
* @see http://php.net/manual/en/function.gzencode.php
|
|
||||||
*
|
|
||||||
* @param string $data
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function compress(string $data):string
|
|
||||||
{
|
|
||||||
return \gzencode($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Decompress.
|
|
||||||
*
|
|
||||||
* @param string $data
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function decompress(string $data):string
|
|
||||||
{
|
|
||||||
return \gzdecode($data);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Appwrite\Storage\Compression;
|
|
||||||
|
|
||||||
abstract class Compression
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Return the name of compression algorithm.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
abstract public function getName(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $data
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
abstract public function compress(string $data);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $data
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
abstract public function decompress(string $data);
|
|
||||||
}
|
|
|
@ -1,167 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Appwrite\Storage;
|
|
||||||
|
|
||||||
use Exception;
|
|
||||||
|
|
||||||
abstract class Device
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Get Name.
|
|
||||||
*
|
|
||||||
* Get storage device name
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
abstract public function getName(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Description.
|
|
||||||
*
|
|
||||||
* Get storage device description and purpose.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
abstract public function getDescription(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Root.
|
|
||||||
*
|
|
||||||
* Get storage device root path
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
abstract public function getRoot(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Path.
|
|
||||||
*
|
|
||||||
* Each device hold a complex directory structure that is being build in this method.
|
|
||||||
*
|
|
||||||
* @param $filename
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
abstract public function getPath($filename): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Upload.
|
|
||||||
*
|
|
||||||
* Upload a file to desired destination in the selected disk, return true on success and false on failure.
|
|
||||||
*
|
|
||||||
* @param string $source
|
|
||||||
* @param string $path
|
|
||||||
*
|
|
||||||
* @throws \Exception
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
abstract public function upload($source, $path): bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read file by given path.
|
|
||||||
*
|
|
||||||
* @param string $path
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
abstract public function read(string $path): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write file by given path.
|
|
||||||
*
|
|
||||||
* @param string $path
|
|
||||||
* @param string $data
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
abstract public function write(string $path, string $data): bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Move file from given source to given path, return true on success and false on failure.
|
|
||||||
*
|
|
||||||
* @see http://php.net/manual/en/function.filesize.php
|
|
||||||
*
|
|
||||||
* @param string $source
|
|
||||||
* @param string $target
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
abstract public function move(string $source, string $target): bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete file in given path return true on success and false on failure.
|
|
||||||
*
|
|
||||||
* @see http://php.net/manual/en/function.filesize.php
|
|
||||||
*
|
|
||||||
* @param string $path
|
|
||||||
* @param bool $recursive
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
abstract public function delete(string $path, bool $recursive = false): bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns given file path its size.
|
|
||||||
*
|
|
||||||
* @see http://php.net/manual/en/function.filesize.php
|
|
||||||
*
|
|
||||||
* @param $path
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
abstract public function getFileSize(string $path): int;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns given file path its mime type.
|
|
||||||
*
|
|
||||||
* @see http://php.net/manual/en/function.mime-content-type.php
|
|
||||||
*
|
|
||||||
* @param $path
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
abstract public function getFileMimeType(string $path): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns given file path its MD5 hash value.
|
|
||||||
*
|
|
||||||
* @see http://php.net/manual/en/function.md5-file.php
|
|
||||||
*
|
|
||||||
* @param $path
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
abstract public function getFileHash(string $path): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get directory size in bytes.
|
|
||||||
*
|
|
||||||
* Return -1 on error
|
|
||||||
*
|
|
||||||
* Based on http://www.jonasjohn.de/snippets/php/dir-size.htm
|
|
||||||
*
|
|
||||||
* @param $path
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
abstract public function getDirectorySize(string $path): int;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Partition Free Space.
|
|
||||||
*
|
|
||||||
* disk_free_space — Returns available space on filesystem or disk partition
|
|
||||||
*
|
|
||||||
* @return float
|
|
||||||
*/
|
|
||||||
abstract public function getPartitionFreeSpace(): float;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Partition Total Space.
|
|
||||||
*
|
|
||||||
* disk_total_space — Returns the total size of a filesystem or disk partition
|
|
||||||
*
|
|
||||||
* @return float
|
|
||||||
*/
|
|
||||||
abstract public function getPartitionTotalSpace(): float;
|
|
||||||
}
|
|
|
@ -1,280 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Appwrite\Storage\Device;
|
|
||||||
|
|
||||||
use Exception;
|
|
||||||
use Appwrite\Storage\Device;
|
|
||||||
|
|
||||||
class Local extends Device
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $root = 'temp';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Local constructor.
|
|
||||||
*
|
|
||||||
* @param string $root
|
|
||||||
*/
|
|
||||||
public function __construct($root = '')
|
|
||||||
{
|
|
||||||
$this->root = $root;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getName():string
|
|
||||||
{
|
|
||||||
return 'Local Storage';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getDescription():string
|
|
||||||
{
|
|
||||||
return 'Adapter for Local storage that is in the physical or virtual machine or mounted to it.';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getRoot():string
|
|
||||||
{
|
|
||||||
return $this->root;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $filename
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getPath($filename):string
|
|
||||||
{
|
|
||||||
$path = '';
|
|
||||||
|
|
||||||
for ($i = 0; $i < 4; ++$i) {
|
|
||||||
$path = ($i < \strlen($filename)) ? $path.DIRECTORY_SEPARATOR.$filename[$i] : $path.DIRECTORY_SEPARATOR.'x';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->getRoot().$path.DIRECTORY_SEPARATOR.$filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Upload.
|
|
||||||
*
|
|
||||||
* Upload a file to desired destination in the selected disk.
|
|
||||||
*
|
|
||||||
* @param string $target
|
|
||||||
* @param string $filename
|
|
||||||
*
|
|
||||||
* @throws \Exception
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function upload($source, $path):bool
|
|
||||||
{
|
|
||||||
if (!\file_exists(\dirname($path))) { // Checks if directory path to file exists
|
|
||||||
if (!@\mkdir(\dirname($path), 0755, true)) {
|
|
||||||
throw new Exception('Can\'t create directory: '.\dirname($path));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (\move_uploaded_file($source, $path)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read file by given path.
|
|
||||||
*
|
|
||||||
* @param string $path
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function read(string $path):string
|
|
||||||
{
|
|
||||||
return \file_get_contents($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write file by given path.
|
|
||||||
*
|
|
||||||
* @param string $path
|
|
||||||
* @param string $data
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function write(string $path, string $data): bool
|
|
||||||
{
|
|
||||||
if (!\file_exists(\dirname($path))) { // Checks if directory path to file exists
|
|
||||||
if (!@\mkdir(\dirname($path), 0755, true)) {
|
|
||||||
throw new Exception('Can\'t create directory '.\dirname($path));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (bool)\file_put_contents($path, $data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Move file from given source to given path, Return true on success and false on failure.
|
|
||||||
*
|
|
||||||
* @see http://php.net/manual/en/function.filesize.php
|
|
||||||
*
|
|
||||||
* @param string $source
|
|
||||||
* @param string $target
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function move(string $source, string $target):bool
|
|
||||||
{
|
|
||||||
if (!\file_exists(\dirname($target))) { // Checks if directory path to file exists
|
|
||||||
if (!@\mkdir(\dirname($target), 0755, true)) {
|
|
||||||
throw new Exception('Can\'t create directory '.\dirname($target));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (\rename($source, $target)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete file in given path, Return true on success and false on failure.
|
|
||||||
*
|
|
||||||
* @see http://php.net/manual/en/function.filesize.php
|
|
||||||
*
|
|
||||||
* @param string $path
|
|
||||||
* @param bool $recursive
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function delete(string $path, bool $recursive = false):bool
|
|
||||||
{
|
|
||||||
if (\is_dir($path) && $recursive) {
|
|
||||||
$files = \glob($path.'*', GLOB_MARK); // GLOB_MARK adds a slash to directories returned
|
|
||||||
|
|
||||||
foreach ($files as $file) {
|
|
||||||
$this->delete($file, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
\rmdir($path);
|
|
||||||
} elseif (\is_file($path)) {
|
|
||||||
return \unlink($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns given file path its size.
|
|
||||||
*
|
|
||||||
* @see http://php.net/manual/en/function.filesize.php
|
|
||||||
*
|
|
||||||
* @param $path
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getFileSize(string $path):int
|
|
||||||
{
|
|
||||||
return \filesize($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns given file path its mime type.
|
|
||||||
*
|
|
||||||
* @see http://php.net/manual/en/function.mime-content-type.php
|
|
||||||
*
|
|
||||||
* @param $path
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getFileMimeType(string $path):string
|
|
||||||
{
|
|
||||||
return \mime_content_type($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns given file path its MD5 hash value.
|
|
||||||
*
|
|
||||||
* @see http://php.net/manual/en/function.md5-file.php
|
|
||||||
*
|
|
||||||
* @param $path
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getFileHash(string $path):string
|
|
||||||
{
|
|
||||||
return \md5_file($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get directory size in bytes.
|
|
||||||
*
|
|
||||||
* Return -1 on error
|
|
||||||
*
|
|
||||||
* Based on http://www.jonasjohn.de/snippets/php/dir-size.htm
|
|
||||||
*
|
|
||||||
* @param $path
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getDirectorySize(string $path):int
|
|
||||||
{
|
|
||||||
$size = 0;
|
|
||||||
|
|
||||||
$directory = \opendir($path);
|
|
||||||
|
|
||||||
if (!$directory) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (($file = \readdir($directory)) !== false) {
|
|
||||||
// Skip file pointers
|
|
||||||
if ($file[0] == '.') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Go recursive down, or add the file size
|
|
||||||
if (\is_dir($path.$file)) {
|
|
||||||
$size += $this->getDirectorySize($path.$file.DIRECTORY_SEPARATOR);
|
|
||||||
} else {
|
|
||||||
$size += \filesize($path.$file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
\closedir($directory);
|
|
||||||
|
|
||||||
return $size;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Partition Free Space.
|
|
||||||
*
|
|
||||||
* disk_free_space — Returns available space on filesystem or disk partition
|
|
||||||
*
|
|
||||||
* @return float
|
|
||||||
*/
|
|
||||||
public function getPartitionFreeSpace():float
|
|
||||||
{
|
|
||||||
return \disk_free_space($this->getRoot());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Partition Total Space.
|
|
||||||
*
|
|
||||||
* disk_total_space — Returns the total size of a filesystem or disk partition
|
|
||||||
*
|
|
||||||
* @return float
|
|
||||||
*/
|
|
||||||
public function getPartitionTotalSpace():float
|
|
||||||
{
|
|
||||||
return \disk_total_space($this->getRoot());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,196 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Appwrite\Storage\Device;
|
|
||||||
|
|
||||||
use Appwrite\Storage\Device;
|
|
||||||
|
|
||||||
class S3 extends Device
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getName():string
|
|
||||||
{
|
|
||||||
return 'S3 Storage';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getDescription():string
|
|
||||||
{
|
|
||||||
return 'S3 Bucket Storage drive for AWS or on premise solution';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getRoot():string
|
|
||||||
{
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $filename
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getPath($filename):string
|
|
||||||
{
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Upload.
|
|
||||||
*
|
|
||||||
* Upload a file to desired destination in the selected disk.
|
|
||||||
*
|
|
||||||
* @param string $target
|
|
||||||
* @param string $filename
|
|
||||||
*
|
|
||||||
* @throws \Exception
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function upload($source, $path):bool
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read file by given path.
|
|
||||||
*
|
|
||||||
* @param string $path
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function read(string $path):string
|
|
||||||
{
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write file by given path.
|
|
||||||
*
|
|
||||||
* @param string $path
|
|
||||||
* @param string $data
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function write(string $path, string $data):bool
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Move file from given source to given path, Return true on success and false on failure.
|
|
||||||
*
|
|
||||||
* @see http://php.net/manual/en/function.filesize.php
|
|
||||||
*
|
|
||||||
* @param string $source
|
|
||||||
* @param string $target
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function move(string $source, string $target):bool
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete file in given path, Return true on success and false on failure.
|
|
||||||
*
|
|
||||||
* @see http://php.net/manual/en/function.filesize.php
|
|
||||||
*
|
|
||||||
* @param string $path
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function delete(string $path, bool $recursive = false):bool
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns given file path its size.
|
|
||||||
*
|
|
||||||
* @see http://php.net/manual/en/function.filesize.php
|
|
||||||
*
|
|
||||||
* @param $path
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getFileSize(string $path):int
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns given file path its mime type.
|
|
||||||
*
|
|
||||||
* @see http://php.net/manual/en/function.mime-content-type.php
|
|
||||||
*
|
|
||||||
* @param $path
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getFileMimeType(string $path):string
|
|
||||||
{
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns given file path its MD5 hash value.
|
|
||||||
*
|
|
||||||
* @see http://php.net/manual/en/function.md5-file.php
|
|
||||||
*
|
|
||||||
* @param $path
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getFileHash(string $path):string
|
|
||||||
{
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get directory size in bytes.
|
|
||||||
*
|
|
||||||
* Return -1 on error
|
|
||||||
*
|
|
||||||
* Based on http://www.jonasjohn.de/snippets/php/dir-size.htm
|
|
||||||
*
|
|
||||||
* @param $path
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getDirectorySize(string $path):int
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Partition Free Space.
|
|
||||||
*
|
|
||||||
* disk_free_space — Returns available space on filesystem or disk partition
|
|
||||||
*
|
|
||||||
* @return float
|
|
||||||
*/
|
|
||||||
public function getPartitionFreeSpace():float
|
|
||||||
{
|
|
||||||
return 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Partition Total Space.
|
|
||||||
*
|
|
||||||
* disk_total_space — Returns the total size of a filesystem or disk partition
|
|
||||||
*
|
|
||||||
* @return float
|
|
||||||
*/
|
|
||||||
public function getPartitionTotalSpace():float
|
|
||||||
{
|
|
||||||
return 0.0;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,113 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Appwrite\Storage;
|
|
||||||
|
|
||||||
use Exception;
|
|
||||||
|
|
||||||
class Storage
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Devices.
|
|
||||||
*
|
|
||||||
* List of all available storage devices
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public static $devices = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set Device.
|
|
||||||
*
|
|
||||||
* Add device by name
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
* @param Device $device
|
|
||||||
*
|
|
||||||
* @throws Exception
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function setDevice($name, Device $device): void
|
|
||||||
{
|
|
||||||
self::$devices[$name] = $device;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Device.
|
|
||||||
*
|
|
||||||
* Get device by name
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
*
|
|
||||||
* @return Device
|
|
||||||
*
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public static function getDevice($name)
|
|
||||||
{
|
|
||||||
if (!\array_key_exists($name, self::$devices)) {
|
|
||||||
throw new Exception('The device "'.$name.'" is not listed');
|
|
||||||
}
|
|
||||||
|
|
||||||
return self::$devices[$name];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exists.
|
|
||||||
*
|
|
||||||
* Checks if given storage name is registered or not
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public static function exists($name)
|
|
||||||
{
|
|
||||||
return (bool) \array_key_exists($name, self::$devices);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Human readable data size format from bytes input.
|
|
||||||
*
|
|
||||||
* Based on: https://stackoverflow.com/a/38659168/2299554
|
|
||||||
*
|
|
||||||
* @param int $bytes
|
|
||||||
* @param int $decimals
|
|
||||||
* @param string $system
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function human(int $bytes, $decimals = 2, $system = 'metric')
|
|
||||||
{
|
|
||||||
$mod = ($system === 'binary') ? 1024 : 1000;
|
|
||||||
|
|
||||||
$units = array(
|
|
||||||
'binary' => array(
|
|
||||||
'B',
|
|
||||||
'KiB',
|
|
||||||
'MiB',
|
|
||||||
'GiB',
|
|
||||||
'TiB',
|
|
||||||
'PiB',
|
|
||||||
'EiB',
|
|
||||||
'ZiB',
|
|
||||||
'YiB',
|
|
||||||
),
|
|
||||||
'metric' => array(
|
|
||||||
'B',
|
|
||||||
'kB',
|
|
||||||
'MB',
|
|
||||||
'GB',
|
|
||||||
'TB',
|
|
||||||
'PB',
|
|
||||||
'EB',
|
|
||||||
'ZB',
|
|
||||||
'YB',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
$factor = (int)floor((strlen((string)$bytes) - 1) / 3);
|
|
||||||
|
|
||||||
return sprintf("%.{$decimals}f%s", $bytes / pow($mod, $factor), $units[$system][$factor]);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Appwrite\Storage\Validator;
|
|
||||||
|
|
||||||
use Utopia\Validator;
|
|
||||||
|
|
||||||
class File extends Validator
|
|
||||||
{
|
|
||||||
public function getDescription()
|
|
||||||
{
|
|
||||||
return 'File is not valid';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* NOT MUCH RIGHT NOW.
|
|
||||||
*
|
|
||||||
* TODO think what to do here, currently only used for parameter to be present in SDKs
|
|
||||||
*
|
|
||||||
* @param mixed $name
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isValid($name)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,37 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Appwrite\Storage\Validator;
|
|
||||||
|
|
||||||
use Utopia\Validator;
|
|
||||||
|
|
||||||
class FileName extends Validator
|
|
||||||
{
|
|
||||||
public function getDescription()
|
|
||||||
{
|
|
||||||
return 'Filename is not valid';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The file name can only contain "a-z", "A-Z", "0-9" and "-" and not empty.
|
|
||||||
*
|
|
||||||
* @param mixed $name
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isValid($name)
|
|
||||||
{
|
|
||||||
if (empty($name)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_string($name)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!\preg_match('/^[a-zA-Z0-9.]+$/', $name)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,48 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Appwrite\Storage\Validator;
|
|
||||||
|
|
||||||
use Utopia\Validator;
|
|
||||||
|
|
||||||
class FileSize extends Validator
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
protected $max;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Max size in bytes
|
|
||||||
*
|
|
||||||
* @param int $max
|
|
||||||
*/
|
|
||||||
public function __construct($max)
|
|
||||||
{
|
|
||||||
$this->max = $max;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDescription()
|
|
||||||
{
|
|
||||||
return 'File size can\'t be bigger than '.$this->max;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Finds whether a file size is smaller than required limit.
|
|
||||||
*
|
|
||||||
* @param mixed $fileSize
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isValid($fileSize)
|
|
||||||
{
|
|
||||||
if (!is_int($fileSize)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($fileSize > $this->max) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,93 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Appwrite\Storage\Validator;
|
|
||||||
|
|
||||||
use Exception;
|
|
||||||
use Utopia\Validator;
|
|
||||||
|
|
||||||
class FileType extends Validator
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* File Types Constants.
|
|
||||||
*/
|
|
||||||
const FILE_TYPE_JPEG = 'jpeg';
|
|
||||||
const FILE_TYPE_GIF = 'gif';
|
|
||||||
const FILE_TYPE_PNG = 'png';
|
|
||||||
const FILE_TYPE_GZIP = 'gz';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* File Type Binaries.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $types = array(
|
|
||||||
self::FILE_TYPE_JPEG => "\xFF\xD8\xFF",
|
|
||||||
self::FILE_TYPE_GIF => 'GIF',
|
|
||||||
self::FILE_TYPE_PNG => "\x89\x50\x4e\x47\x0d\x0a",
|
|
||||||
self::FILE_TYPE_GZIP => "application/x-gzip",
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $whiteList;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $whiteList
|
|
||||||
*
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function __construct(array $whiteList)
|
|
||||||
{
|
|
||||||
foreach ($whiteList as $key) {
|
|
||||||
if (!isset($this->types[$key])) {
|
|
||||||
throw new Exception('Unknown file mime type');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->whiteList = $whiteList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDescription()
|
|
||||||
{
|
|
||||||
return 'File mime-type is not allowed ';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Is Valid.
|
|
||||||
*
|
|
||||||
* Binary check to finds whether a file is of valid type
|
|
||||||
*
|
|
||||||
* @see http://stackoverflow.com/a/3313196
|
|
||||||
*
|
|
||||||
* @param string $path
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isValid($path)
|
|
||||||
{
|
|
||||||
if (!\is_readable($path)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$handle = \fopen($path, 'r');
|
|
||||||
|
|
||||||
if (!$handle) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$bytes = \fgets($handle, 8);
|
|
||||||
|
|
||||||
foreach ($this->whiteList as $key) {
|
|
||||||
if (\strpos($bytes, $this->types[$key]) === 0) {
|
|
||||||
\fclose($handle);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
\fclose($handle);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Appwrite\Storage\Validator;
|
|
||||||
|
|
||||||
use Utopia\Validator;
|
|
||||||
|
|
||||||
class Upload extends Validator
|
|
||||||
{
|
|
||||||
public function getDescription()
|
|
||||||
{
|
|
||||||
return 'Not a valid upload file';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if a file is a valid upload file
|
|
||||||
*
|
|
||||||
* @param mixed $path
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isValid($path)
|
|
||||||
{
|
|
||||||
if (!is_string($path)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (\is_uploaded_file($path)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,80 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Appwrite\Tests;
|
|
||||||
|
|
||||||
use Appwrite\Storage\Compression\Algorithms\GZIP;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
class GZIPTest extends TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var GZIP
|
|
||||||
*/
|
|
||||||
protected $object = null;
|
|
||||||
|
|
||||||
public function setUp(): void
|
|
||||||
{
|
|
||||||
$this->object = new GZIP();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function tearDown(): void
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testName()
|
|
||||||
{
|
|
||||||
$this->assertEquals($this->object->getName(), 'gzip');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testCompressDecompressWithText()
|
|
||||||
{
|
|
||||||
$demo = 'This is a demo string';
|
|
||||||
$demoSize = mb_strlen($demo, '8bit');
|
|
||||||
|
|
||||||
$data = $this->object->compress($demo);
|
|
||||||
$dataSize = mb_strlen($data, '8bit');
|
|
||||||
|
|
||||||
$this->assertEquals($demoSize, 21);
|
|
||||||
$this->assertEquals($dataSize, 39);
|
|
||||||
|
|
||||||
$this->assertEquals($this->object->decompress($data), $demo);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testCompressDecompressWithJPGImage()
|
|
||||||
{
|
|
||||||
$demo = \file_get_contents(__DIR__ . '/../../../../resources/disk-a/kitten-1.jpg');
|
|
||||||
$demoSize = mb_strlen($demo, '8bit');
|
|
||||||
|
|
||||||
$data = $this->object->compress($demo);
|
|
||||||
$dataSize = mb_strlen($data, '8bit');
|
|
||||||
|
|
||||||
$this->assertEquals($demoSize, 599639);
|
|
||||||
$this->assertEquals($dataSize, 599107);
|
|
||||||
|
|
||||||
$this->assertGreaterThan($dataSize, $demoSize);
|
|
||||||
|
|
||||||
$data = $this->object->decompress($data);
|
|
||||||
$dataSize = mb_strlen($data, '8bit');
|
|
||||||
|
|
||||||
$this->assertEquals($dataSize, 599639);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testCompressDecompressWithPNGImage()
|
|
||||||
{
|
|
||||||
$demo = \file_get_contents(__DIR__ . '/../../../../resources/disk-b/kitten-1.png');
|
|
||||||
$demoSize = mb_strlen($demo, '8bit');
|
|
||||||
|
|
||||||
$data = $this->object->compress($demo);
|
|
||||||
$dataSize = mb_strlen($data, '8bit');
|
|
||||||
|
|
||||||
$this->assertEquals($demoSize, 3038056);
|
|
||||||
$this->assertEquals($dataSize, 3029202);
|
|
||||||
|
|
||||||
$this->assertGreaterThan($dataSize, $demoSize);
|
|
||||||
|
|
||||||
$data = $this->object->decompress($data);
|
|
||||||
$dataSize = mb_strlen($data, '8bit');
|
|
||||||
|
|
||||||
$this->assertEquals($dataSize, 3038056);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,123 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Appwrite\Tests;
|
|
||||||
|
|
||||||
use Appwrite\Storage\Device\Local;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
class LocalTest extends TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var Local
|
|
||||||
*/
|
|
||||||
protected $object = null;
|
|
||||||
|
|
||||||
public function setUp(): void
|
|
||||||
{
|
|
||||||
$this->object = new Local(realpath(__DIR__ . '/../../../resources/disk-a'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function tearDown(): void
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testName()
|
|
||||||
{
|
|
||||||
$this->assertEquals($this->object->getName(), 'Local Storage');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDescription()
|
|
||||||
{
|
|
||||||
$this->assertEquals($this->object->getDescription(), 'Adapter for Local storage that is in the physical or virtual machine or mounted to it.');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testRoot()
|
|
||||||
{
|
|
||||||
$this->assertEquals($this->object->getRoot(), '/usr/src/code/tests/resources/disk-a');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testPath()
|
|
||||||
{
|
|
||||||
$this->assertEquals($this->object->getPath('image.png'), '/usr/src/code/tests/resources/disk-a/i/m/a/g/image.png');
|
|
||||||
$this->assertEquals($this->object->getPath('x.png'), '/usr/src/code/tests/resources/disk-a/x/./p/n/x.png');
|
|
||||||
$this->assertEquals($this->object->getPath('y'), '/usr/src/code/tests/resources/disk-a/y/x/x/x/y');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testWrite()
|
|
||||||
{
|
|
||||||
$this->assertEquals($this->object->write($this->object->getPath('text.txt'), 'Hello World'), true);
|
|
||||||
$this->assertEquals(file_exists($this->object->getPath('text.txt')), true);
|
|
||||||
$this->assertEquals(is_readable($this->object->getPath('text.txt')), true);
|
|
||||||
|
|
||||||
$this->object->delete($this->object->getPath('text.txt'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testRead()
|
|
||||||
{
|
|
||||||
$this->assertEquals($this->object->write($this->object->getPath('text-for-read.txt'), 'Hello World'), true);
|
|
||||||
$this->assertEquals($this->object->read($this->object->getPath('text-for-read.txt')), 'Hello World');
|
|
||||||
|
|
||||||
$this->object->delete($this->object->getPath('text-for-read.txt'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testMove()
|
|
||||||
{
|
|
||||||
$this->assertEquals($this->object->write($this->object->getPath('text-for-move.txt'), 'Hello World'), true);
|
|
||||||
$this->assertEquals($this->object->read($this->object->getPath('text-for-move.txt')), 'Hello World');
|
|
||||||
$this->assertEquals($this->object->move($this->object->getPath('text-for-move.txt'), $this->object->getPath('text-for-move-new.txt')), true);
|
|
||||||
$this->assertEquals($this->object->read($this->object->getPath('text-for-move-new.txt')), 'Hello World');
|
|
||||||
$this->assertEquals(file_exists($this->object->getPath('text-for-move.txt')), false);
|
|
||||||
$this->assertEquals(is_readable($this->object->getPath('text-for-move.txt')), false);
|
|
||||||
$this->assertEquals(file_exists($this->object->getPath('text-for-move-new.txt')), true);
|
|
||||||
$this->assertEquals(is_readable($this->object->getPath('text-for-move-new.txt')), true);
|
|
||||||
|
|
||||||
$this->object->delete($this->object->getPath('text-for-move-new.txt'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDelete()
|
|
||||||
{
|
|
||||||
$this->assertEquals($this->object->write($this->object->getPath('text-for-delete.txt'), 'Hello World'), true);
|
|
||||||
$this->assertEquals($this->object->read($this->object->getPath('text-for-delete.txt')), 'Hello World');
|
|
||||||
$this->assertEquals($this->object->delete($this->object->getPath('text-for-delete.txt')), true);
|
|
||||||
$this->assertEquals(file_exists($this->object->getPath('text-for-delete.txt')), false);
|
|
||||||
$this->assertEquals(is_readable($this->object->getPath('text-for-delete.txt')), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testFileSize()
|
|
||||||
{
|
|
||||||
$this->assertEquals($this->object->getFileSize(__DIR__ . '/../../../resources/disk-a/kitten-1.jpg'), 599639);
|
|
||||||
$this->assertEquals($this->object->getFileSize(__DIR__ . '/../../../resources/disk-a/kitten-2.jpg'), 131958);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testFileMimeType()
|
|
||||||
{
|
|
||||||
$this->assertEquals($this->object->getFileMimeType(__DIR__ . '/../../../resources/disk-a/kitten-1.jpg'), 'image/jpeg');
|
|
||||||
$this->assertEquals($this->object->getFileMimeType(__DIR__ . '/../../../resources/disk-a/kitten-2.jpg'), 'image/jpeg');
|
|
||||||
$this->assertEquals($this->object->getFileMimeType(__DIR__ . '/../../../resources/disk-b/kitten-1.png'), 'image/png');
|
|
||||||
$this->assertEquals($this->object->getFileMimeType(__DIR__ . '/../../../resources/disk-b/kitten-2.png'), 'image/png');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testFileHash()
|
|
||||||
{
|
|
||||||
$this->assertEquals($this->object->getFileHash(__DIR__ . '/../../../resources/disk-a/kitten-1.jpg'), '7551f343143d2e24ab4aaf4624996b6a');
|
|
||||||
$this->assertEquals($this->object->getFileHash(__DIR__ . '/../../../resources/disk-a/kitten-2.jpg'), '81702fdeef2e55b1a22617bce4951cb5');
|
|
||||||
$this->assertEquals($this->object->getFileHash(__DIR__ . '/../../../resources/disk-b/kitten-1.png'), '03010f4f02980521a8fd6213b52ec313');
|
|
||||||
$this->assertEquals($this->object->getFileHash(__DIR__ . '/../../../resources/disk-b/kitten-2.png'), '8a9ed992b77e4b62b10e3a5c8ed72062');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDirectorySize()
|
|
||||||
{
|
|
||||||
$this->assertGreaterThan(0, $this->object->getDirectorySize(__DIR__ . '/../../../resources/disk-a/'));
|
|
||||||
$this->assertGreaterThan(0, $this->object->getDirectorySize(__DIR__ . '/../../../resources/disk-b/'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testPartitionFreeSpace()
|
|
||||||
{
|
|
||||||
$this->assertGreaterThan(0, $this->object->getPartitionFreeSpace());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testPartitionTotalSpace()
|
|
||||||
{
|
|
||||||
$this->assertGreaterThan(0, $this->object->getPartitionTotalSpace());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,42 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Appwrite\Tests;
|
|
||||||
|
|
||||||
use Exception;
|
|
||||||
use Appwrite\Storage\Storage;
|
|
||||||
use Appwrite\Storage\Device\Local;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
Storage::setDevice('disk-a', new Local(__DIR__ . '/../../resources/disk-a'));
|
|
||||||
Storage::setDevice('disk-b', new Local(__DIR__ . '/../../resources/disk-b'));
|
|
||||||
|
|
||||||
class StorageTest extends TestCase
|
|
||||||
{
|
|
||||||
public function setUp(): void
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public function tearDown(): void
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetters()
|
|
||||||
{
|
|
||||||
$this->assertEquals(get_class(Storage::getDevice('disk-a')), 'Appwrite\Storage\Device\Local');
|
|
||||||
$this->assertEquals(get_class(Storage::getDevice('disk-b')), 'Appwrite\Storage\Device\Local');
|
|
||||||
|
|
||||||
try {
|
|
||||||
get_class(Storage::getDevice('disk-c'));
|
|
||||||
$this->fail("Expected exception not thrown");
|
|
||||||
} catch (Exception $e) {
|
|
||||||
$this->assertEquals('The device "disk-c" is not listed', $e->getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testExists()
|
|
||||||
{
|
|
||||||
$this->assertEquals(Storage::exists('disk-a'), true);
|
|
||||||
$this->assertEquals(Storage::exists('disk-b'), true);
|
|
||||||
$this->assertEquals(Storage::exists('disk-c'), false);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Appwrite\Tests;
|
|
||||||
|
|
||||||
use Appwrite\Storage\Validator\FileName;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
class FileNameTest extends TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var FileName
|
|
||||||
*/
|
|
||||||
protected $object = null;
|
|
||||||
|
|
||||||
public function setUp(): void
|
|
||||||
{
|
|
||||||
$this->object = new FileName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function tearDown(): void
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testValues()
|
|
||||||
{
|
|
||||||
$this->assertEquals($this->object->isValid(''), false);
|
|
||||||
$this->assertEquals($this->object->isValid(null), false);
|
|
||||||
$this->assertEquals($this->object->isValid(false), false);
|
|
||||||
$this->assertEquals($this->object->isValid('../test'), false);
|
|
||||||
$this->assertEquals($this->object->isValid('test.png'), true);
|
|
||||||
$this->assertEquals($this->object->isValid('test'), true);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Appwrite\Tests;
|
|
||||||
|
|
||||||
use Appwrite\Storage\Validator\FileSize;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
class FileSizeTest extends TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var FileSize
|
|
||||||
*/
|
|
||||||
protected $object = null;
|
|
||||||
|
|
||||||
public function setUp(): void
|
|
||||||
{
|
|
||||||
$this->object = new FileSize(1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function tearDown(): void
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testValues()
|
|
||||||
{
|
|
||||||
$this->assertEquals($this->object->isValid(1001), false);
|
|
||||||
$this->assertEquals($this->object->isValid(1000), true);
|
|
||||||
$this->assertEquals($this->object->isValid(999), true);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Appwrite\Tests;
|
|
||||||
|
|
||||||
use Appwrite\Storage\Validator\FileType;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
class FileTypeTest extends TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var FileType
|
|
||||||
*/
|
|
||||||
protected $object = null;
|
|
||||||
|
|
||||||
public function setUp(): void
|
|
||||||
{
|
|
||||||
$this->object = new FileType([FileType::FILE_TYPE_JPEG]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function tearDown(): void
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testValues()
|
|
||||||
{
|
|
||||||
$this->assertEquals($this->object->isValid(__DIR__ . '/../../../resources/disk-a/kitten-1.jpg'), true);
|
|
||||||
$this->assertEquals($this->object->isValid(__DIR__ . '/../../../resources/disk-a/kitten-2.jpg'), true);
|
|
||||||
$this->assertEquals($this->object->isValid(__DIR__ . '/../../../resources/disk-b/kitten-1.png'), false);
|
|
||||||
$this->assertEquals($this->object->isValid(__DIR__ . '/../../../resources/disk-b/kitten-2.png'), false);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,32 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Appwrite\Tests;
|
|
||||||
|
|
||||||
use Appwrite\Storage\Validator\Upload;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
class UploadTest extends TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var Upload
|
|
||||||
*/
|
|
||||||
protected $object = null;
|
|
||||||
|
|
||||||
public function setUp(): void
|
|
||||||
{
|
|
||||||
$this->object = new Upload();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function tearDown(): void
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testValues()
|
|
||||||
{
|
|
||||||
$this->assertEquals($this->object->isValid(__DIR__ . '/../../../resources/disk-a/kitten-1.jpg'), false);
|
|
||||||
$this->assertEquals($this->object->isValid(__DIR__ . '/../../../resources/disk-a/kitten-2.jpg'), false);
|
|
||||||
$this->assertEquals($this->object->isValid(__DIR__ . '/../../../resources/disk-b/kitten-1.png'), false);
|
|
||||||
$this->assertEquals($this->object->isValid(__DIR__ . '/../../../resources/disk-b/kitten-2.png'), false);
|
|
||||||
$this->assertEquals($this->object->isValid(__FILE__), false);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue