diff --git a/src/fs/AssetsFs.php b/src/fs/AssetsFs.php index 6351cb8..f4ef407 100644 --- a/src/fs/AssetsFs.php +++ b/src/fs/AssetsFs.php @@ -13,8 +13,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(); }