Skip to content

Commit e01166b

Browse files
committed
Ensure artifacts serve locally
1 parent c0114bf commit e01166b

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

src/fs/AssetsFs.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace craft\cloud\fs;
44

5+
use craft\cloud\Helper;
56
use craft\cloud\Module;
67
use League\Uri\Contracts\SegmentedPathInterface;
78

@@ -13,8 +14,12 @@ class AssetsFs extends Fs
1314

1415
public function init(): void
1516
{
16-
$this->useLocalFs = !Module::getInstance()->getConfig()->useAssetCdn;
1717
parent::init();
18+
$this->useLocalFs = !Module::getInstance()->getConfig()->useAssetCdn;
19+
20+
if ($this->useLocalFs) {
21+
$this->baseUrl = $this->getLocalFs()->getRootUrl();
22+
}
1823
}
1924

2025
/**

src/fs/BuildArtifactsFs.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,25 @@
22

33
namespace craft\cloud\fs;
44

5+
use craft\cloud\Helper;
56
use craft\cloud\Module;
67
use League\Uri\Contracts\SegmentedPathInterface;
78

89
class BuildArtifactsFs extends BuildsFs
910
{
1011
public bool $hasUrls = true;
12+
public ?string $localFsPath = '@webroot';
13+
public ?string $localFsUrl = '@web';
1114

1215
public function init(): void
1316
{
14-
$this->baseUrl = Module::getInstance()->getConfig()->artifactBaseUrl;
1517
parent::init();
18+
$this->useLocalFs = !Helper::isCraftCloud();
19+
$this->baseUrl = Module::getInstance()->getConfig()->artifactBaseUrl;
20+
21+
if ($this->useLocalFs && !$this->baseUrl) {
22+
$this->baseUrl = $this->getLocalFs()->getRootUrl();
23+
}
1624
}
1725

1826
public function createBucketPrefix(): SegmentedPathInterface

src/fs/Fs.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ protected function getLocalFs(): Local
7272
$this->localFs = $this->localFs ?? Craft::createObject([
7373
'class' => Local::class,
7474
'hasUrls' => $this->hasUrls,
75-
'path' => $path->toString(),
75+
'path' => $path?->toString(),
7676
'url' => $this->localFsUrl,
7777
]);
7878

@@ -93,10 +93,8 @@ public function getRootUrl(): ?string
9393

9494
public function createUrl(string $path = ''): UriInterface
9595
{
96-
$baseUrl = $this->useLocalFs ? $this->getLocalFs()->getRootUrl() : $this->baseUrl;
97-
98-
if ($baseUrl) {
99-
return Modifier::from($baseUrl)
96+
if ($this->baseUrl) {
97+
return Modifier::from($this->baseUrl)
10098
->appendSegment($this->createPath($path))
10199
->getUri();
102100
}

0 commit comments

Comments
 (0)