2
2
3
3
namespace FullscreenInteractive \SilverStripe \AzureStorage \Adapter ;
4
4
5
+ use FullscreenInteractive \SilverStripe \AzureStorage \Service \BlobService ;
5
6
use InvalidArgumentException ;
6
7
use League \Flysystem \AzureBlobStorage \AzureBlobStorageAdapter ;
7
- use MicrosoftAzure \Storage \Blob \BlobRestProxy ;
8
8
use SilverStripe \Assets \Flysystem \PublicAdapter as SilverstripePublicAdapter ;
9
9
use SilverStripe \Control \Controller ;
10
10
11
11
class PublicAdapter extends AzureBlobStorageAdapter implements SilverstripePublicAdapter
12
12
{
13
- public function __construct ($ connectionUrl = '' , $ containerName = '' )
13
+ private $ assetDomain ;
14
+
15
+ public function __construct ($ connectionUrl = '' , $ containerName = '' , $ assetDomain = '' )
14
16
{
15
17
if (!$ connectionUrl ) {
16
18
throw new InvalidArgumentException ("AZURE_CONNECTION_URL environment variable not set " );
@@ -20,7 +22,15 @@ public function __construct($connectionUrl = '', $containerName = '')
20
22
throw new InvalidArgumentException ("AZURE_CONTAINER_NAME environment variable not set " );
21
23
}
22
24
23
- $ client = BlobRestProxy::createBlobService ($ connectionUrl );
25
+ $ client = BlobService::clientForConnection ($ connectionUrl );
26
+
27
+ if ($ assetDomain ) {
28
+ $ this ->assetDomain = $ assetDomain ;
29
+ } else {
30
+ $ this ->assetDomain = (string ) BlobService::getClient ()
31
+ ->getPsrPrimaryUri ()
32
+ ->withPath ($ containerName );
33
+ }
24
34
25
35
parent ::__construct ($ client , $ containerName );
26
36
}
@@ -32,10 +42,14 @@ public function __construct($connectionUrl = '', $containerName = '')
32
42
*/
33
43
public function getPublicUrl ($ path )
34
44
{
35
- if ($ meta = $ this ->getMetadata ($ path )) {
36
- return Controller::join_links (ASSETS_DIR , $ meta ['path ' ]);
45
+ $ parts = explode ('/ ' , $ path );
46
+
47
+ if (isset ($ parts [0 ]) && $ parts [0 ] === ASSETS_DIR ) {
48
+ array_shift ($ parts );
37
49
}
38
50
39
- return '' ;
51
+ $ path = implode ('/ ' , $ parts );
52
+
53
+ return Controller::join_links ($ this ->assetDomain , $ path );
40
54
}
41
55
}
0 commit comments