Host images locally
We don’t need the complexity of S3. Sepcifically the complexity of managing my own AWS account, flysystem made the Laravel side easy. A command is added to copy the the S3 files over to local storage.
This commit is contained in:
parent
d80e8164c8
commit
d7da42b626
47 changed files with 295 additions and 214 deletions
|
@ -16,7 +16,7 @@ class DownloadWebMentionJobTest extends TestCase
|
|||
{
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$fs = new FileSystem();
|
||||
$fs = new FileSystem;
|
||||
if ($fs->exists(storage_path() . '/HTML/https')) {
|
||||
$fs->deleteDirectory(storage_path() . '/HTML/https');
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ class ProcessBookmarkJobTest extends TestCase
|
|||
$bookmark = Bookmark::factory()->create();
|
||||
$service = $this->createMock(BookmarkService::class);
|
||||
$service->method('getArchiveLink')
|
||||
->will($this->throwException(new InternetArchiveException()));
|
||||
->will($this->throwException(new InternetArchiveException));
|
||||
$this->app->instance(BookmarkService::class, $service);
|
||||
|
||||
$job = new ProcessBookmark($bookmark);
|
||||
|
|
|
@ -14,38 +14,48 @@ class ProcessMediaJobTest extends TestCase
|
|||
/** @test */
|
||||
public function nonMediaFilesAreNotSaved(): void
|
||||
{
|
||||
Storage::fake('s3');
|
||||
$manager = app()->make(ImageManager::class);
|
||||
Storage::disk('local')->put('file.txt', 'This is not an image');
|
||||
Storage::disk('local')->put('media/file.txt', 'This is not an image');
|
||||
$job = new ProcessMedia('file.txt');
|
||||
$job->handle($manager);
|
||||
|
||||
$this->assertFalse(file_exists(storage_path('app') . '/file.txt'));
|
||||
$this->assertFileDoesNotExist(storage_path('app/media/') . 'file.txt');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function smallImagesAreNotResized(): void
|
||||
{
|
||||
Storage::fake('s3');
|
||||
$manager = app()->make(ImageManager::class);
|
||||
Storage::disk('local')->put('aaron.png', file_get_contents(__DIR__ . '/../../aaron.png'));
|
||||
Storage::disk('local')->put('media/aaron.png', file_get_contents(__DIR__ . '/../../aaron.png'));
|
||||
$job = new ProcessMedia('aaron.png');
|
||||
$job->handle($manager);
|
||||
|
||||
$this->assertFalse(file_exists(storage_path('app') . '/aaron.png'));
|
||||
$this->assertFileDoesNotExist(storage_path('app/media/') . 'aaron.png');
|
||||
|
||||
// Tidy up files created by the job
|
||||
Storage::disk('local')->delete('public/media/aaron.png');
|
||||
Storage::disk('local')->delete('public/media');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function largeImagesHaveSmallerImagesCreated(): void
|
||||
{
|
||||
$manager = app()->make(ImageManager::class);
|
||||
Storage::disk('local')->put('test-image.jpg', file_get_contents(__DIR__.'/../../test-image.jpg'));
|
||||
Storage::fake('s3');
|
||||
Storage::disk('local')->put('media/test-image.jpg', file_get_contents(__DIR__.'/../../test-image.jpg'));
|
||||
$job = new ProcessMedia('test-image.jpg');
|
||||
$job->handle($manager);
|
||||
|
||||
Storage::disk('s3')->assertExists('media/test-image-small.jpg');
|
||||
Storage::disk('s3')->assertExists('media/test-image-medium.jpg');
|
||||
$this->assertFalse(file_exists(storage_path('app') . '/test-image.jpg'));
|
||||
Storage::disk('local')->assertExists('public/media/test-image.jpg');
|
||||
Storage::disk('local')->assertExists('public/media/test-image-small.jpg');
|
||||
Storage::disk('local')->assertExists('public/media/test-image-medium.jpg');
|
||||
|
||||
$this->assertFileDoesNotExist(storage_path('app/media/') . 'test-image.jpg');
|
||||
|
||||
// Tidy up files created by the job
|
||||
Storage::disk('local')->delete('public/media/test-image.jpg');
|
||||
Storage::disk('local')->delete('public/media/test-image-small.jpg');
|
||||
Storage::disk('local')->delete('public/media/test-image-medium.jpg');
|
||||
$this->removeDirIfEmpty(storage_path('app/public/media'));
|
||||
$this->removeDirIfEmpty(storage_path('app/media'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ class ProcessWebMentionJobTest extends TestCase
|
|||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$fs = new FileSystem();
|
||||
$fs = new FileSystem;
|
||||
if ($fs->exists(storage_path() . '/HTML/https')) {
|
||||
$fs->deleteDirectory(storage_path() . '/HTML/https');
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ class ProcessWebMentionJobTest extends TestCase
|
|||
{
|
||||
$this->expectException(RemoteContentNotFoundException::class);
|
||||
|
||||
$parser = new Parser();
|
||||
$parser = new Parser;
|
||||
$mock = new MockHandler([
|
||||
new Response(404),
|
||||
]);
|
||||
|
@ -56,7 +56,7 @@ class ProcessWebMentionJobTest extends TestCase
|
|||
{
|
||||
Queue::fake();
|
||||
|
||||
$parser = new Parser();
|
||||
$parser = new Parser;
|
||||
|
||||
$html = <<<'HTML'
|
||||
<div class="h-entry">
|
||||
|
@ -88,7 +88,7 @@ class ProcessWebMentionJobTest extends TestCase
|
|||
{
|
||||
Queue::fake();
|
||||
|
||||
$parser = new Parser();
|
||||
$parser = new Parser;
|
||||
$note = Note::factory()->create();
|
||||
$source = 'https://aaronpk.localhost/reply/1';
|
||||
WebMention::factory()->create([
|
||||
|
@ -123,7 +123,7 @@ class ProcessWebMentionJobTest extends TestCase
|
|||
/** @test */
|
||||
public function webmentionReplyGetsDeletedWhenReplyToValueChanges(): void
|
||||
{
|
||||
$parser = new Parser();
|
||||
$parser = new Parser;
|
||||
|
||||
$html = <<<'HTML'
|
||||
<div class="h-entry">
|
||||
|
@ -139,7 +139,7 @@ class ProcessWebMentionJobTest extends TestCase
|
|||
|
||||
$note = Note::factory()->create();
|
||||
$source = 'https://example.org/reply/1';
|
||||
$webmention = new WebMention();
|
||||
$webmention = new WebMention;
|
||||
$webmention->source = $source;
|
||||
$webmention->target = config('app.url') . '/notes/E';
|
||||
$webmention->type = 'in-reply-to';
|
||||
|
@ -160,7 +160,7 @@ class ProcessWebMentionJobTest extends TestCase
|
|||
/** @test */
|
||||
public function webmentionLikeGetsDeletedWhenLikeOfValueChanges(): void
|
||||
{
|
||||
$parser = new Parser();
|
||||
$parser = new Parser;
|
||||
|
||||
$html = <<<'HTML'
|
||||
<div class="h-entry">
|
||||
|
@ -176,7 +176,7 @@ class ProcessWebMentionJobTest extends TestCase
|
|||
|
||||
$note = Note::factory()->create();
|
||||
$source = 'https://example.org/reply/1';
|
||||
$webmention = new WebMention();
|
||||
$webmention = new WebMention;
|
||||
$webmention->source = $source;
|
||||
$webmention->target = config('app.url') . '/notes/E';
|
||||
$webmention->type = 'like-of';
|
||||
|
@ -197,7 +197,7 @@ class ProcessWebMentionJobTest extends TestCase
|
|||
/** @test */
|
||||
public function webmentionRepostGetsDeletedWhenRepostOfValueChanges(): void
|
||||
{
|
||||
$parser = new Parser();
|
||||
$parser = new Parser;
|
||||
|
||||
$html = <<<'HTML'
|
||||
<div class="h-entry">
|
||||
|
@ -213,7 +213,7 @@ class ProcessWebMentionJobTest extends TestCase
|
|||
|
||||
$note = Note::factory()->create();
|
||||
$source = 'https://example.org/reply/1';
|
||||
$webmention = new WebMention();
|
||||
$webmention = new WebMention;
|
||||
$webmention->source = $source;
|
||||
$webmention->target = config('app.url') . '/notes/E';
|
||||
$webmention->type = 'repost-of';
|
||||
|
|
|
@ -30,7 +30,7 @@ class SaveProfileImageJobTest extends TestCase
|
|||
$mf = ['items' => []];
|
||||
$authorship = $this->createMock(Authorship::class);
|
||||
$authorship->method('findAuthor')
|
||||
->will($this->throwException(new AuthorshipParserException()));
|
||||
->will($this->throwException(new AuthorshipParserException));
|
||||
$job = new SaveProfileImage($mf);
|
||||
|
||||
$this->assertNull($job->handle($authorship));
|
||||
|
|
|
@ -17,7 +17,7 @@ class SendWebMentionJobTest extends TestCase
|
|||
/** @test */
|
||||
public function discoverWebmentionEndpointOnOwnDomain(): void
|
||||
{
|
||||
$note = new Note();
|
||||
$note = new Note;
|
||||
$job = new SendWebMentions($note);
|
||||
$this->assertNull($job->discoverWebmentionEndpoint(config('app.url')));
|
||||
$this->assertNull($job->discoverWebmentionEndpoint('/notes/tagged/test'));
|
||||
|
@ -34,7 +34,7 @@ class SendWebMentionJobTest extends TestCase
|
|||
$client = new Client(['handler' => $handler]);
|
||||
$this->app->instance(Client::class, $client);
|
||||
|
||||
$job = new SendWebMentions(new Note());
|
||||
$job = new SendWebMentions(new Note);
|
||||
$this->assertEquals($url, $job->discoverWebmentionEndpoint('https://example.org'));
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ class SendWebMentionJobTest extends TestCase
|
|||
$client = new Client(['handler' => $handler]);
|
||||
$this->app->instance(Client::class, $client);
|
||||
|
||||
$job = new SendWebMentions(new Note());
|
||||
$job = new SendWebMentions(new Note);
|
||||
$this->assertEquals(
|
||||
'https://example.org/webmention',
|
||||
$job->discoverWebmentionEndpoint('https://example.org')
|
||||
|
@ -67,7 +67,7 @@ class SendWebMentionJobTest extends TestCase
|
|||
$client = new Client(['handler' => $handler]);
|
||||
$this->app->instance(Client::class, $client);
|
||||
|
||||
$job = new SendWebMentions(new Note());
|
||||
$job = new SendWebMentions(new Note);
|
||||
$this->assertEquals(
|
||||
'https://example.org/webmention',
|
||||
$job->discoverWebmentionEndpoint('https://example.org')
|
||||
|
@ -77,7 +77,7 @@ class SendWebMentionJobTest extends TestCase
|
|||
/** @test */
|
||||
public function ensureEmptyNoteDoesNotTriggerAnyActions(): void
|
||||
{
|
||||
$job = new SendWebMentions(new Note());
|
||||
$job = new SendWebMentions(new Note);
|
||||
$this->assertNull($job->handle());
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ class SendWebMentionJobTest extends TestCase
|
|||
{
|
||||
$uri = '/blog/post';
|
||||
$base = 'https://example.org/';
|
||||
$job = new SendWebMentions(new Note());
|
||||
$job = new SendWebMentions(new Note);
|
||||
$this->assertEquals('https://example.org/blog/post', $job->resolveUri($uri, $base));
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ class SendWebMentionJobTest extends TestCase
|
|||
$client = new Client(['handler' => $handler]);
|
||||
$this->app->instance(Client::class, $client);
|
||||
|
||||
$note = new Note();
|
||||
$note = new Note;
|
||||
$note->note = 'Hi [Aaron](https://aaronparecki.com)';
|
||||
$note->save();
|
||||
$job = new SendWebMentions($note);
|
||||
|
@ -121,7 +121,7 @@ class SendWebMentionJobTest extends TestCase
|
|||
$client = new Client(['handler' => $handler]);
|
||||
$this->app->instance(Client::class, $client);
|
||||
|
||||
$job = new SendWebMentions(new Note());
|
||||
$job = new SendWebMentions(new Note);
|
||||
$this->assertNull($job->discoverWebmentionEndpoint('https://example.org'));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue