Skip to content

Commit d8f3349

Browse files
Public Path Prefix
1 parent 000c485 commit d8f3349

5 files changed

Lines changed: 53 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## \[v3.3.0\] - 2024-08-24
8+
9+
- Add ability to override public path with a prefix, for the purposes of using a CDN
10+
711
## \[v3.2.1\] - 2024-06-13
812

913
- Add missing use statement in AzureFactory (#49)

config/module.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ tags = "amazon s3 aws, wasabi, azure, digital ocean, dropbox, google, sc
55
author = "Jared Howland, Jon Fackrell, & Julian Maurice"
66
author_link = "https://www.jaredhowland.com"
77
; Version is automatically updated using GitHub action `release.yml` in case you forget before releasing
8-
version = "3.2.1"
8+
version = "3.3.0"
99
configurable = true
1010
module_link = "https://github.com/HBLL-Collection-Development/omeka-s-any-cloud"
1111
support_link = "https://github.com/HBLL-Collection-Development/omeka-s-any-cloud/issues"

src/Form/ConfigForm.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,17 @@ private function addS3($id, $name, $label = null): void
144144
'id' => $id.'_endpoint',
145145
],
146146
]);
147+
$awsFieldset->add([
148+
'name' => $id.'_public_path_prefix',
149+
'type' => Element\Text::class,
150+
'options' => [
151+
'label' => $label.'Public Path Prefix',
152+
'info' => 'Overrides the default public path generation with a custom prefix. Can usually leave blank unless you are using a CDN.',
153+
],
154+
'attributes' => [
155+
'id' => $id.'_public_path_prefix',
156+
],
157+
]);
147158
}
148159

149160
/**
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace AnyCloud\Service\File\Adapter\AwsS3V3;
4+
5+
use Aws\S3\S3ClientInterface;
6+
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;
7+
use League\Flysystem\Config;
8+
use League\Flysystem\PathPrefixer;
9+
10+
class AwsS3V3AdapterWrapper extends AwsS3V3Adapter
11+
{
12+
private ?PathPrefixer $prefixer;
13+
14+
public function __construct(
15+
private S3ClientInterface $client,
16+
private array $config,
17+
) {
18+
parent::__construct($client, $config['bucket']);
19+
20+
$pathPrefix = $this->config['public_path_prefix'];
21+
if ($pathPrefix) {
22+
$this->prefixer = new PathPrefixer($pathPrefix, '/');
23+
} else {
24+
$this->prefixer = null;
25+
}
26+
}
27+
28+
public function publicUrl(string $path, Config $cnf): string
29+
{
30+
if ($this->prefixer) {
31+
return $this->prefixer->prefixPath($path);
32+
}
33+
return parent::publicUrl($path, $cnf);
34+
}
35+
}

src/Service/File/Store/AbstractAwsS3V3Factory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace AnyCloud\Service\File\Store;
44

5+
use AnyCloud\Service\File\Adapter\AwsS3V3\AwsS3V3AdapterWrapper;
56
use Aws\S3\S3Client;
6-
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;
77
use League\Flysystem\FilesystemAdapter;
88

99
abstract class AbstractAwsS3V3Factory extends AbstractFlysystemFactory
@@ -20,7 +20,7 @@ protected function getFilesystemAdapter(array $config): FilesystemAdapter
2020
'version' => 'latest',
2121
];
2222
$client = new S3Client($options);
23-
$adapter = new AwsS3V3Adapter($client, $config['bucket']);
23+
$adapter = new AwsS3V3AdapterWrapper($client, $config);
2424

2525
return $adapter;
2626
}

0 commit comments

Comments
 (0)