From e01166b071341cd74186df843c8b050458129ce6 Mon Sep 17 00:00:00 2001 From: Tim Kelty Date: Tue, 14 Oct 2025 16:14:40 -0700 Subject: [PATCH 1/2] Ensure artifacts serve locally --- src/fs/AssetsFs.php | 7 ++++++- src/fs/BuildArtifactsFs.php | 10 +++++++++- src/fs/Fs.php | 8 +++----- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/fs/AssetsFs.php b/src/fs/AssetsFs.php index 6351cb8..5f99922 100644 --- a/src/fs/AssetsFs.php +++ b/src/fs/AssetsFs.php @@ -2,6 +2,7 @@ namespace craft\cloud\fs; +use craft\cloud\Helper; use craft\cloud\Module; use League\Uri\Contracts\SegmentedPathInterface; @@ -13,8 +14,12 @@ class AssetsFs extends Fs public function init(): void { - $this->useLocalFs = !Module::getInstance()->getConfig()->useAssetCdn; parent::init(); + $this->useLocalFs = !Module::getInstance()->getConfig()->useAssetCdn; + + if ($this->useLocalFs) { + $this->baseUrl = $this->getLocalFs()->getRootUrl(); + } } /** diff --git a/src/fs/BuildArtifactsFs.php b/src/fs/BuildArtifactsFs.php index 326bf34..2e97bf1 100644 --- a/src/fs/BuildArtifactsFs.php +++ b/src/fs/BuildArtifactsFs.php @@ -2,17 +2,25 @@ namespace craft\cloud\fs; +use craft\cloud\Helper; use craft\cloud\Module; use League\Uri\Contracts\SegmentedPathInterface; class BuildArtifactsFs extends BuildsFs { public bool $hasUrls = true; + public ?string $localFsPath = '@webroot'; + public ?string $localFsUrl = '@web'; public function init(): void { - $this->baseUrl = Module::getInstance()->getConfig()->artifactBaseUrl; parent::init(); + $this->useLocalFs = !Helper::isCraftCloud(); + $this->baseUrl = Module::getInstance()->getConfig()->artifactBaseUrl; + + if ($this->useLocalFs && !$this->baseUrl) { + $this->baseUrl = $this->getLocalFs()->getRootUrl(); + } } public function createBucketPrefix(): SegmentedPathInterface diff --git a/src/fs/Fs.php b/src/fs/Fs.php index bd1b0ce..1abbc88 100644 --- a/src/fs/Fs.php +++ b/src/fs/Fs.php @@ -72,7 +72,7 @@ protected function getLocalFs(): Local $this->localFs = $this->localFs ?? Craft::createObject([ 'class' => Local::class, 'hasUrls' => $this->hasUrls, - 'path' => $path->toString(), + 'path' => $path?->toString(), 'url' => $this->localFsUrl, ]); @@ -93,10 +93,8 @@ public function getRootUrl(): ?string public function createUrl(string $path = ''): UriInterface { - $baseUrl = $this->useLocalFs ? $this->getLocalFs()->getRootUrl() : $this->baseUrl; - - if ($baseUrl) { - return Modifier::from($baseUrl) + if ($this->baseUrl) { + return Modifier::from($this->baseUrl) ->appendSegment($this->createPath($path)) ->getUri(); } From 203c6039cdd573d9192344d43712c00eddfaec3b Mon Sep 17 00:00:00 2001 From: Tim Kelty Date: Tue, 14 Oct 2025 16:32:13 -0700 Subject: [PATCH 2/2] CS --- src/fs/AssetsFs.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/fs/AssetsFs.php b/src/fs/AssetsFs.php index 5f99922..f4ef407 100644 --- a/src/fs/AssetsFs.php +++ b/src/fs/AssetsFs.php @@ -2,7 +2,6 @@ namespace craft\cloud\fs; -use craft\cloud\Helper; use craft\cloud\Module; use League\Uri\Contracts\SegmentedPathInterface;