Skip to content

Commit

Permalink
Merge 5b39df0 into 5f180d1
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Maurice committed Sep 26, 2023
2 parents 5f180d1 + 5b39df0 commit 01f46c7
Show file tree
Hide file tree
Showing 23 changed files with 463 additions and 494 deletions.
12 changes: 12 additions & 0 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ public function getConfigForm(PhpRenderer $renderer): string
}
$form->init();
$form->setData($data);

// Disable fieldset if corresponding section exists in local.config.php
foreach (['aws', 'azure', 'digital_ocean', 'dropbox', 'google', 'scaleway', 'wasabi'] as $key) {
if (isset($config['file_store'][$key])) {
$fieldset = $form->get("anycloud_$key");
$fieldset->setLabel($fieldset->getLabel().' (disabled because configuration exists in local.config.php)');
foreach ($fieldset->getElements() as $element) {
$element->setAttribute('disabled', true);
}
}
}

$html = $renderer->render('anycloud/module/config', [
'form' => $form,
]);
Expand Down
147 changes: 146 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,155 @@ It is recommended that once you pick an external storage service you continue us
## Installation and Configuration
1. Install the plugin by [downloading and unzipping the latest module](https://github.com/HBLL-Collection-Development/omeka-s-any-cloud/releases) and loading it into the `modules` directory of your Omeka S instance.
2. Enable the plugin from the Admin side of your installation under “Modules”.
3. Configure the module from the Admin side to include credentials for the cloud storage system you would like to use.
3. Configure the module from the Admin side to include credentials for the cloud storage system you would like to use. You can also choose to configure the module from the `config/local.config.php` file (see [server-side configuration](#server-side-configuration))

After that, when you upload media for an item, it will upload to your selected cloud service rather than to your server’s local storage.

### Server-side configuration

It's possible to configure the module entirely by editing the
`config/local.config.php` file.

First, you need to change the alias for `Omeka\File\Store` to the adapter you
want to use, and then you have to configure the adapter itself inside the
`file_store` section.

For instance, if you want to use Dropbox, `config/local.config.php` should look like this:

```php
<?php

return [
'service_manager' => [
'aliases' => [
'Omeka\File\Store' => 'AnyCloud\File\Store\Dropbox',
],
],
'file_store' => [
'dropbox' => [
'access_token' => 'YOUR_ACCESS_TOKEN',
],
],
];
```

#### AWS

Alias should be set to `AnyCloud\File\Store\Aws`.

Available options:

```php
'file_store' => [
'aws' => [
'key' => 'KEY',
'secret' => 'SECRET',
'region' => 'REGION',
'endpoint' => 'ENDPOINT',
'bucket' => 'BUCKET',
],
],
```

#### Azure

Alias should be set to `AnyCloud\File\Store\Azure`.

Available options:

```php
'file_store' => [
'azure' => [
'account_name' => 'ACCOUNT_NAME',
'account_key' => 'ACCOUNT_KEY',
'container_name' => 'CONTAINER_NAME',
],
],
```

#### Digital Ocean

Alias should be set to `AnyCloud\File\Store\DigitalOcean`.

Available options:

```php
'file_store' => [
'digital_ocean' => [
'key' => 'KEY',
'secret' => 'SECRET',
'region' => 'REGION',
'endpoint' => 'ENDPOINT',
'bucket' => 'BUCKET',
],
],
```

#### Dropbox

Alias should be set to `AnyCloud\File\Store\Dropbox`.

Available options:

```php
'file_store' => [
'dropbox' => [
'access_token' => 'ACCESS_TOKEN',
],
],
```

#### Google

Alias should be set to `AnyCloud\File\Store\Google`.

Available options:

```php
'file_store' => [
'google' => [
'project_id' => 'PROJECT_ID',
'credentials_path' => '/path/to/credentials.json', // This path is relative to AnyCloud's module path
],
],
```

#### Scaleway

Alias should be set to `AnyCloud\File\Store\Scaleway`.

Available options:

```php
'file_store' => [
'scaleway' => [
'key' => 'KEY',
'secret' => 'SECRET',
'region' => 'REGION',
'endpoint' => 'ENDPOINT',
'bucket' => 'BUCKET',
],
],
```

#### Wasabi

Alias should be set to `AnyCloud\File\Store\Wasabi`.

Available options:

```php
'file_store' => [
'wasabi' => [
'key' => 'KEY',
'secret' => 'SECRET',
'region' => 'REGION',
'endpoint' => 'ENDPOINT',
'bucket' => 'BUCKET',
],
],
```

## Known Issues
1. No migration from one cloud/filesystem to another. Pick one or manually transfer things if you decide to change services.

Expand Down
8 changes: 8 additions & 0 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
'service_manager' => [
'factories' => [
File\Store\AnyCloud::class => Service\File\Store\AnyCloudFactory::class,

File\Store\Aws::class => Service\File\Store\AwsFactory::class,
File\Store\Azure::class => Service\File\Store\AzureFactory::class,
File\Store\DigitalOcean::class => Service\File\Store\DigitalOceanFactory::class,
File\Store\Dropbox::class => Service\File\Store\DropboxFactory::class,
File\Store\Google::class => Service\File\Store\GoogleFactory::class,
File\Store\Scaleway::class => Service\File\Store\ScalewayFactory::class,
File\Store\Wasabi::class => Service\File\Store\WasabiFactory::class,
],
],
'anycloud' => [
Expand Down
83 changes: 0 additions & 83 deletions src/File/Store/AnyCloud.php

This file was deleted.

11 changes: 11 additions & 0 deletions src/File/Store/Dropbox.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace AnyCloud\File\Store;

class Dropbox extends Flysystem
{
public function getUri($storagePath)
{
return $this->filesystem->temporaryUrl($storagePath);
}
}
39 changes: 39 additions & 0 deletions src/File/Store/Flysystem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace AnyCloud\File\Store;

use League\Flysystem\Filesystem;
use League\Flysystem\Visibility;
use Omeka\File\Store\StoreInterface;

class Flysystem implements StoreInterface
{
protected $filesystem;

public function __construct(Filesystem $filesystem)
{
$this->filesystem = $filesystem;
}

public function put($source, $storagePath)
{
$fh = fopen($source, 'r');
if ($fh === false) {
throw new \Omeka\File\Exception\RuntimeException(sprintf('Failed to open "%s"', $source));
}

$config = ['visibility' => Visibility::PUBLIC];
$this->filesystem->writeStream($storagePath, $fh, $config);
fclose($fh);
}

public function delete($storagePath)
{
$this->filesystem->delete($storagePath);
}

public function getUri($storagePath)
{
return $this->filesystem->publicUrl($storagePath);
}
}
15 changes: 15 additions & 0 deletions src/FilesystemAdapter/DropboxAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace AnyCloud\FilesystemAdapter;

use DateTimeInterface;
use League\Flysystem\Config;
use League\Flysystem\UrlGeneration\TemporaryUrlGenerator;

class DropboxAdapter extends \Spatie\FlysystemDropbox\DropboxAdapter implements TemporaryUrlGenerator
{
public function temporaryUrl(string $path, DateTimeInterface $expiresAt, Config $config): string
{
return $this->client->getTemporaryLink($path);
}
}
34 changes: 0 additions & 34 deletions src/Service/File/Adapter/AdapterInterface.php

This file was deleted.

0 comments on commit 01f46c7

Please sign in to comment.