Added S3 file system to media uploads
remove drop box as public storage Change-Id: I9c07fe0d3fa56f302fc5ea50686d10ee768e5a9a Signed-off-by: smarcet <smarcet@gmail.com>
This commit is contained in:
parent
1d7f523806
commit
82a369f9b3
@ -170,4 +170,11 @@ RABBITMQ_SSL_VERIFY_PEER=false
|
||||
DROPBOX_ACCESS_TOKEN=
|
||||
|
||||
MUX_TOKEN_ID=
|
||||
MUX_TOKEN_SECRET=
|
||||
MUX_TOKEN_SECRET=
|
||||
|
||||
# S3
|
||||
AWS_ACCESS_KEY_ID=
|
||||
AWS_SECRET_ACCESS_KEY=
|
||||
AWS_DEFAULT_REGION=
|
||||
AWS_BUCKET=
|
||||
AWS_ENDPOINT=
|
@ -112,8 +112,8 @@ final class OAuth2SummitMediaUploadTypeApiController extends OAuth2ProtectedCont
|
||||
'is_mandatory' => 'required|boolean',
|
||||
// in KB
|
||||
'max_size' => 'required|int|megabyte_aligned',
|
||||
'private_storage_type' => 'required|string|in:'.implode(",", IStorageTypesConstants::ValidTypes),
|
||||
'public_storage_type' => 'required|string|in:'.implode(",", IStorageTypesConstants::ValidTypes),
|
||||
'private_storage_type' => 'required|string|in:'.implode(",", IStorageTypesConstants::ValidPrivateTypes),
|
||||
'public_storage_type' => 'required|string|in:'.implode(",", IStorageTypesConstants::ValidPublicTypes),
|
||||
'type_id' => 'required|int',
|
||||
'presentation_types' => 'sometimes|int_array',
|
||||
];
|
||||
@ -154,8 +154,8 @@ final class OAuth2SummitMediaUploadTypeApiController extends OAuth2ProtectedCont
|
||||
'is_mandatory' => 'sometimes|boolean',
|
||||
// KB
|
||||
'max_size' => 'sometimes|int|megabyte_aligned',
|
||||
'private_storage_type' => 'sometimes|string|in:'.implode(",", IStorageTypesConstants::ValidTypes),
|
||||
'public_storage_type' => 'sometimes|string|in:'.implode(",", IStorageTypesConstants::ValidTypes),
|
||||
'private_storage_type' => 'sometimes|string|in:'.implode(",", IStorageTypesConstants::ValidPrivateTypes),
|
||||
'public_storage_type' => 'sometimes|string|in:'.implode(",", IStorageTypesConstants::ValidPublicTypes),
|
||||
'type_id' => 'sometimes|int',
|
||||
'presentation_types' => 'sometimes|int_array',
|
||||
];
|
||||
|
@ -128,6 +128,7 @@ class PresentationMediaUpload extends PresentationMaterial
|
||||
* @return string
|
||||
*/
|
||||
public function getPath(string $storageType = IStorageTypesConstants::PublicType, ?string $mountingFolder = null): string {
|
||||
|
||||
if(empty($mountingFolder))
|
||||
$mountingFolder = Config::get('mediaupload.mounting_folder');
|
||||
|
||||
@ -135,9 +136,11 @@ class PresentationMediaUpload extends PresentationMaterial
|
||||
|
||||
$summit = $this->getPresentation()->getSummit();
|
||||
$presentation = $this->getPresentation();
|
||||
$format = $storageType == IStorageTypesConstants::PublicType ? '%s/%s/%s': '%s/'.IStorageTypesConstants::PrivateType.'/%s/%s';
|
||||
$format = $storageType == IStorageTypesConstants::PublicType ? '%s/%s/%s': '%s/'.IStorageTypesConstants::PrivateType.'/%s/%s';
|
||||
|
||||
if($this->legacy_path_format)
|
||||
return sprintf($format, $mountingFolder, $summit->getId(), $presentation->getId());
|
||||
|
||||
$presentation->generateSlug();
|
||||
return sprintf($format, $mountingFolder, sprintf("%s-%s",$summit->getId(), filter_var($summit->getRawSlug(), FILTER_SANITIZE_ENCODED)), sprintf("%s-%s", $presentation->getId(), filter_var($presentation->getSlug(), FILTER_SANITIZE_ENCODED)));
|
||||
}
|
||||
@ -145,7 +148,7 @@ class PresentationMediaUpload extends PresentationMaterial
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->legacy_path_format = false;
|
||||
$this->legacy_path_format = true;
|
||||
}
|
||||
|
||||
}
|
@ -15,6 +15,7 @@
|
||||
use App\Models\Utils\IStorageTypesConstants;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use models\exceptions\ValidationException;
|
||||
use models\utils\SilverstripeBaseModel;
|
||||
use Doctrine\ORM\Mapping AS ORM;
|
||||
/**
|
||||
@ -210,7 +211,7 @@ class SummitMediaUploadType extends SilverstripeBaseModel
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPrivateStorageType(): string
|
||||
public function getPrivateStorageType(): ?string
|
||||
{
|
||||
return $this->private_storage_type;
|
||||
}
|
||||
@ -220,13 +221,15 @@ class SummitMediaUploadType extends SilverstripeBaseModel
|
||||
*/
|
||||
public function setPrivateStorageType(string $private_storage_type): void
|
||||
{
|
||||
if(!in_array($private_storage_type, IStorageTypesConstants::ValidPrivateTypes))
|
||||
throw new ValidationException(sprintf("invalid private storage type %s", $private_storage_type));
|
||||
$this->private_storage_type = $private_storage_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPublicStorageType(): string
|
||||
public function getPublicStorageType(): ?string
|
||||
{
|
||||
return $this->public_storage_type;
|
||||
}
|
||||
@ -236,6 +239,9 @@ class SummitMediaUploadType extends SilverstripeBaseModel
|
||||
*/
|
||||
public function setPublicStorageType(string $public_storage_type): void
|
||||
{
|
||||
if(!in_array($public_storage_type, IStorageTypesConstants::ValidPublicTypesTypes))
|
||||
throw new ValidationException(sprintf("invalid public storage type %s", $public_storage_type));
|
||||
|
||||
$this->public_storage_type = $public_storage_type;
|
||||
}
|
||||
|
||||
|
@ -20,10 +20,14 @@ interface IStorageTypesConstants
|
||||
{
|
||||
public const PublicType = 'Public';
|
||||
public const PrivateType = 'Private';
|
||||
|
||||
public const DropBox = 'DropBox';
|
||||
public const Swift = 'Swift';
|
||||
public const S3 = 'S3';
|
||||
public const Local = 'Local';
|
||||
public const None = 'None';
|
||||
|
||||
const ValidTypes = [self::None, self::DropBox, self::Swift, self::Local];
|
||||
const ValidPrivateTypes = [self::None, self::DropBox, self::Local];
|
||||
|
||||
const ValidPublicTypes = [self::None, self::Swift, self::S3, self::Local];
|
||||
}
|
@ -14,6 +14,7 @@
|
||||
use App\Models\Utils\IStorageTypesConstants;
|
||||
use App\Services\FileSystem\Dropbox\DropboxStorageFileDownloadStrategy;
|
||||
use App\Services\FileSystem\Local\LocalStorageFileDownloadStrategy;
|
||||
use App\Services\FileSystem\S3\S3StorageFileDownloadStrategy;
|
||||
use App\Services\FileSystem\Swift\SwiftStorageFileDownloadStrategy;
|
||||
/**
|
||||
* Class FileDownloadStrategyFactory
|
||||
@ -36,6 +37,9 @@ final class FileDownloadStrategyFactory
|
||||
case IStorageTypesConstants::Swift;
|
||||
return new SwiftStorageFileDownloadStrategy();
|
||||
break;
|
||||
case IStorageTypesConstants::S3;
|
||||
return new S3StorageFileDownloadStrategy();
|
||||
break;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -14,6 +14,7 @@
|
||||
use App\Models\Utils\IStorageTypesConstants;
|
||||
use App\Services\FileSystem\Dropbox\DropboxStorageFileUploadStrategy;
|
||||
use App\Services\FileSystem\Local\LocalStorageFileUploadStrategy;
|
||||
use App\Services\FileSystem\S3\S3StorageFileUploadStrategy;
|
||||
use App\Services\FileSystem\Swift\SwiftStorageFileUploadStrategy;
|
||||
/**
|
||||
* Class FileUploadStrategyFactory
|
||||
@ -36,6 +37,9 @@ final class FileUploadStrategyFactory
|
||||
case IStorageTypesConstants::Swift;
|
||||
return new SwiftStorageFileUploadStrategy();
|
||||
break;
|
||||
case IStorageTypesConstants::S3;
|
||||
return new S3StorageFileUploadStrategy();
|
||||
break;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
50
app/Services/FileSystem/S3/S3StorageFileDownloadStrategy.php
Normal file
50
app/Services/FileSystem/S3/S3StorageFileDownloadStrategy.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php namespace App\Services\FileSystem\S3;
|
||||
/**
|
||||
* Copyright 2020 OpenStack Foundation
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
use App\Services\FileSystem\IFileDownloadStrategy;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
/**
|
||||
* Class S3StorageFileDownloadStrategy
|
||||
* @package App\Services\FileSystem\S3
|
||||
*/
|
||||
final class S3StorageFileDownloadStrategy implements IFileDownloadStrategy
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function download(string $path, string $name, array $options = [])
|
||||
{
|
||||
return Storage::disk('s3')->download(
|
||||
$path,
|
||||
$name,
|
||||
$options
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getUrl(string $relativeFileName): ?string
|
||||
{
|
||||
return Storage::disk('s3')->url($relativeFileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function delete(string $relativeFileName)
|
||||
{
|
||||
return Storage::disk('s3')->delete($relativeFileName);
|
||||
}
|
||||
}
|
32
app/Services/FileSystem/S3/S3StorageFileUploadStrategy.php
Normal file
32
app/Services/FileSystem/S3/S3StorageFileUploadStrategy.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php namespace App\Services\FileSystem\S3;
|
||||
/**
|
||||
* Copyright 2020 OpenStack Foundation
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
use App\Services\FileSystem\IFileUploadStrategy;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
/**
|
||||
* Class S3StorageFileUploadStrategy
|
||||
* @package App\Services\FileSystem\S3
|
||||
*/
|
||||
final class S3StorageFileUploadStrategy implements IFileUploadStrategy
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function save(UploadedFile $file, string $path, string $filename)
|
||||
{
|
||||
return Storage::disk('s3')->putFileAs($path, $file, $filename);
|
||||
}
|
||||
}
|
@ -49,7 +49,8 @@
|
||||
"spatie/laravel-cors": "^1.6",
|
||||
"stripe/stripe-php": "^6.37",
|
||||
"symfony/yaml": "4.2.2",
|
||||
"tecnickcom/tcpdf": "^6.2"
|
||||
"tecnickcom/tcpdf": "^6.2",
|
||||
"league/flysystem-aws-s3-v3": "^1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"filp/whoops": "^2.0",
|
||||
|
765
composer.lock
generated
765
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -54,6 +54,16 @@ return [
|
||||
'visibility' => 'public',
|
||||
],
|
||||
|
||||
's3' => [
|
||||
'driver' => 's3',
|
||||
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||
'region' => env('AWS_DEFAULT_REGION'),
|
||||
'bucket' => env('AWS_BUCKET'),
|
||||
'url' => env('AWS_URL'),
|
||||
'endpoint' => env('AWS_ENDPOINT'),
|
||||
],
|
||||
|
||||
'assets' => [
|
||||
'driver' => 'swift',
|
||||
'auth_url' => env('CLOUD_STORAGE_AUTH_URL'),
|
||||
|
Loading…
x
Reference in New Issue
Block a user