-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
try to reduce AWS bill by using cloudfront to download upload
- Loading branch information
1 parent
554dde4
commit 38c9cb2
Showing
2 changed files
with
156 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of By Night. | ||
* (c) 2013-present Guillaume Sainthillier <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace App\Flysystem; | ||
|
||
use League\Flysystem\Config; | ||
use League\Flysystem\FileAttributes; | ||
use League\Flysystem\FilesystemAdapter; | ||
use League\Flysystem\UnableToCheckDirectoryExistence; | ||
use League\Flysystem\UnableToCopyFile; | ||
use League\Flysystem\UnableToCreateDirectory; | ||
use League\Flysystem\UnableToDeleteDirectory; | ||
use League\Flysystem\UnableToDeleteFile; | ||
use League\Flysystem\UnableToListContents; | ||
use League\Flysystem\UnableToMoveFile; | ||
use League\Flysystem\UnableToReadFile; | ||
use League\Flysystem\UnableToRetrieveMetadata; | ||
use League\Flysystem\UnableToSetVisibility; | ||
use League\Flysystem\UnableToWriteFile; | ||
use Symfony\Component\HttpClient\Response\StreamableInterface; | ||
use Symfony\Contracts\HttpClient\Exception\ExceptionInterface; | ||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; | ||
use Symfony\Contracts\HttpClient\HttpClientInterface; | ||
|
||
class HttpClientAdapter implements FilesystemAdapter | ||
{ | ||
private readonly HttpClientInterface $httpClient; | ||
|
||
public function __construct( | ||
HttpClientInterface $httpClient, | ||
array $options = [] | ||
) { | ||
$this->httpClient = $httpClient->withOptions($options); | ||
} | ||
|
||
public function fileExists(string $path): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function directoryExists(string $path): bool | ||
{ | ||
throw new UnableToCheckDirectoryExistence('This is a readonly adapter.'); | ||
} | ||
|
||
public function write(string $path, string $contents, Config $config): void | ||
{ | ||
throw UnableToWriteFile::atLocation($path, 'This is a readonly adapter.'); | ||
} | ||
|
||
public function writeStream(string $path, $contents, Config $config): void | ||
{ | ||
throw UnableToWriteFile::atLocation($path, 'This is a readonly adapter.'); | ||
} | ||
|
||
public function read(string $path): string | ||
{ | ||
try { | ||
return $this->httpClient->request('GET', $path)->getContent(); | ||
} catch (TransportExceptionInterface|ExceptionInterface $exception) { | ||
throw UnableToReadFile::fromLocation($path, $exception->getMessage(), $exception); | ||
} | ||
} | ||
|
||
public function readStream(string $path) | ||
{ | ||
try { | ||
$response = $this->httpClient->request('GET', $path); | ||
if (!$response instanceof StreamableInterface) { | ||
throw UnableToReadFile::fromLocation($path, 'Response is not streamable.'); | ||
} | ||
|
||
return $response->toStream(); | ||
} catch (TransportExceptionInterface|ExceptionInterface $exception) { | ||
throw UnableToReadFile::fromLocation($path, $exception->getMessage(), $exception); | ||
} | ||
} | ||
|
||
public function delete(string $path): void | ||
{ | ||
throw UnableToDeleteFile::atLocation($path, 'This is a readonly adapter.'); | ||
} | ||
|
||
public function deleteDirectory(string $path): void | ||
{ | ||
throw UnableToDeleteDirectory::atLocation($path, 'This is a readonly adapter.'); | ||
} | ||
|
||
public function createDirectory(string $path, Config $config): void | ||
{ | ||
throw UnableToCreateDirectory::atLocation($path, 'This is a readonly adapter.'); | ||
} | ||
|
||
public function setVisibility(string $path, string $visibility): void | ||
{ | ||
throw UnableToSetVisibility::atLocation($path, 'This is a readonly adapter.'); | ||
} | ||
|
||
public function visibility(string $path): FileAttributes | ||
{ | ||
throw UnableToRetrieveMetadata::visibility($path, 'This is a readonly adapter.'); | ||
} | ||
|
||
public function mimeType(string $path): FileAttributes | ||
{ | ||
throw UnableToRetrieveMetadata::mimeType($path, 'This is a readonly adapter.'); | ||
} | ||
|
||
public function lastModified(string $path): FileAttributes | ||
{ | ||
throw UnableToRetrieveMetadata::lastModified($path, 'This is a readonly adapter.'); | ||
} | ||
|
||
public function fileSize(string $path): FileAttributes | ||
{ | ||
throw UnableToRetrieveMetadata::fileSize($path, 'This is a readonly adapter.'); | ||
} | ||
|
||
public function listContents(string $path, bool $deep): iterable | ||
{ | ||
throw UnableToListContents::atLocation($path, 'This is a readonly adapter.'); | ||
} | ||
|
||
public function move(string $source, string $destination, Config $config): void | ||
{ | ||
throw new UnableToMoveFile("Unable to move file from $source to $destination as this is a readonly adapter."); | ||
} | ||
|
||
public function copy(string $source, string $destination, Config $config): void | ||
{ | ||
throw new UnableToCopyFile("Unable to copy file from $source to $destination as this is a readonly adapter."); | ||
} | ||
} |