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
|
@ -78,7 +78,7 @@ class LikesTest extends TestCase
|
|||
/** @test */
|
||||
public function likeWithSimpleAuthor(): void
|
||||
{
|
||||
$like = new Like();
|
||||
$like = new Like;
|
||||
$like->url = 'http://example.org/note/id';
|
||||
$like->save();
|
||||
$id = $like->id;
|
||||
|
@ -107,7 +107,7 @@ class LikesTest extends TestCase
|
|||
$this->app->bind(Client::class, function () use ($client) {
|
||||
return $client;
|
||||
});
|
||||
$authorship = new Authorship();
|
||||
$authorship = new Authorship;
|
||||
|
||||
$job->handle($client, $authorship);
|
||||
|
||||
|
@ -117,7 +117,7 @@ class LikesTest extends TestCase
|
|||
/** @test */
|
||||
public function likeWithHCard(): void
|
||||
{
|
||||
$like = new Like();
|
||||
$like = new Like;
|
||||
$like->url = 'http://example.org/note/id';
|
||||
$like->save();
|
||||
$id = $like->id;
|
||||
|
@ -150,7 +150,7 @@ class LikesTest extends TestCase
|
|||
$this->app->bind(Client::class, function () use ($client) {
|
||||
return $client;
|
||||
});
|
||||
$authorship = new Authorship();
|
||||
$authorship = new Authorship;
|
||||
|
||||
$job->handle($client, $authorship);
|
||||
|
||||
|
@ -160,7 +160,7 @@ class LikesTest extends TestCase
|
|||
/** @test */
|
||||
public function likeWithoutMicroformats(): void
|
||||
{
|
||||
$like = new Like();
|
||||
$like = new Like;
|
||||
$like->url = 'http://example.org/note/id';
|
||||
$like->save();
|
||||
$id = $like->id;
|
||||
|
@ -186,7 +186,7 @@ class LikesTest extends TestCase
|
|||
$this->app->bind(Client::class, function () use ($client) {
|
||||
return $client;
|
||||
});
|
||||
$authorship = new Authorship();
|
||||
$authorship = new Authorship;
|
||||
|
||||
$job->handle($client, $authorship);
|
||||
|
||||
|
@ -196,7 +196,7 @@ class LikesTest extends TestCase
|
|||
/** @test */
|
||||
public function likeThatIsATweet(): void
|
||||
{
|
||||
$like = new Like();
|
||||
$like = new Like;
|
||||
$like->url = 'https://twitter.com/jonnybarnes/status/1050823255123251200';
|
||||
$like->save();
|
||||
$id = $like->id;
|
||||
|
@ -226,7 +226,7 @@ class LikesTest extends TestCase
|
|||
->willReturn($info);
|
||||
$this->app->instance(Codebird::class, $codebirdMock);
|
||||
|
||||
$authorship = new Authorship();
|
||||
$authorship = new Authorship;
|
||||
|
||||
$job->handle($client, $authorship);
|
||||
|
||||
|
@ -236,7 +236,7 @@ class LikesTest extends TestCase
|
|||
/** @test */
|
||||
public function noErrorForFailureToPosseWithBridgy(): void
|
||||
{
|
||||
$like = new Like();
|
||||
$like = new Like;
|
||||
$like->url = 'https://twitter.com/jonnybarnes/status/1050823255123251200';
|
||||
$like->save();
|
||||
$id = $like->id;
|
||||
|
@ -264,7 +264,7 @@ class LikesTest extends TestCase
|
|||
->willReturn($info);
|
||||
$this->app->instance(Codebird::class, $codebirdMock);
|
||||
|
||||
$authorship = new Authorship();
|
||||
$authorship = new Authorship;
|
||||
|
||||
$job->handle($client, $authorship);
|
||||
|
||||
|
|
|
@ -291,7 +291,7 @@ class MicropubControllerTest extends TestCase
|
|||
*/
|
||||
public function micropubClientApiRequestCreatesNewNoteWithExistingPlaceInLocationData(): void
|
||||
{
|
||||
$place = new Place();
|
||||
$place = new Place;
|
||||
$place->name = 'Test Place';
|
||||
$place->latitude = 1.23;
|
||||
$place->longitude = 4.56;
|
||||
|
|
|
@ -10,6 +10,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase;
|
|||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
use Tests\TestToken;
|
||||
|
||||
|
@ -22,9 +23,7 @@ class MicropubMediaTest extends TestCase
|
|||
public function emptyResponseForLastUploadWhenNoneFound(): void
|
||||
{
|
||||
// Make sure there’s no media
|
||||
Media::all()->each(function ($media) {
|
||||
$media->delete();
|
||||
});
|
||||
$this->assertCount(0, Media::all());
|
||||
|
||||
$response = $this->get(
|
||||
'/api/media?q=last',
|
||||
|
@ -82,10 +81,8 @@ class MicropubMediaTest extends TestCase
|
|||
public function clientCanListLastUpload(): void
|
||||
{
|
||||
Queue::fake();
|
||||
Storage::fake('s3');
|
||||
$file = __DIR__ . '/../aaron.png';
|
||||
$token = $this->getToken();
|
||||
config(['filesystems.disks.s3.url' => 'https://s3.example.com']);
|
||||
|
||||
$response = $this->post(
|
||||
'/api/media',
|
||||
|
@ -95,12 +92,8 @@ class MicropubMediaTest extends TestCase
|
|||
['HTTP_Authorization' => 'Bearer ' . $token]
|
||||
);
|
||||
|
||||
$location = $response->headers->get('Location');
|
||||
|
||||
$this->assertStringStartsWith('https://s3.example.com/', $location);
|
||||
|
||||
$path = parse_url($response->headers->get('Location'), PHP_URL_PATH);
|
||||
$filename = substr($path, 7);
|
||||
$filename = Str::chopStart($path, '/media/');
|
||||
|
||||
$lastUploadResponse = $this->get(
|
||||
'/api/media?q=last',
|
||||
|
@ -109,14 +102,14 @@ class MicropubMediaTest extends TestCase
|
|||
$lastUploadResponse->assertJson(['url' => $response->headers->get('Location')]);
|
||||
|
||||
// now remove file
|
||||
unlink(storage_path('app/') . $filename);
|
||||
unlink(storage_path('app/media/') . $filename);
|
||||
$this->removeDirIfEmpty(storage_path('app/media'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function clientCanSourceUploads(): void
|
||||
{
|
||||
Queue::fake();
|
||||
Storage::fake('s3');
|
||||
$file = __DIR__ . '/../aaron.png';
|
||||
$token = $this->getToken();
|
||||
|
||||
|
@ -129,7 +122,7 @@ class MicropubMediaTest extends TestCase
|
|||
);
|
||||
|
||||
$path = parse_url($response->headers->get('Location'), PHP_URL_PATH);
|
||||
$filename = substr($path, 7);
|
||||
$filename = Str::chopStart($path, '/media/');
|
||||
|
||||
$sourceUploadResponse = $this->get(
|
||||
'/api/media?q=source',
|
||||
|
@ -141,14 +134,14 @@ class MicropubMediaTest extends TestCase
|
|||
]]]);
|
||||
|
||||
// now remove file
|
||||
unlink(storage_path('app/') . $filename);
|
||||
unlink(storage_path('app/media/') . $filename);
|
||||
$this->removeDirIfEmpty(storage_path('app/media'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function clientCanSourceUploadsWithLimit(): void
|
||||
{
|
||||
Queue::fake();
|
||||
Storage::fake('s3');
|
||||
$file = __DIR__ . '/../aaron.png';
|
||||
$token = $this->getToken();
|
||||
|
||||
|
@ -161,7 +154,7 @@ class MicropubMediaTest extends TestCase
|
|||
);
|
||||
|
||||
$path = parse_url($response->headers->get('Location'), PHP_URL_PATH);
|
||||
$filename = substr($path, 7);
|
||||
$filename = Str::chopStart($path, '/media/');
|
||||
|
||||
$sourceUploadResponse = $this->get(
|
||||
'/api/media?q=source&limit=1',
|
||||
|
@ -175,7 +168,8 @@ class MicropubMediaTest extends TestCase
|
|||
$this->assertCount(1, json_decode($sourceUploadResponse->getContent(), true)['items']);
|
||||
|
||||
// now remove file
|
||||
unlink(storage_path('app/') . $filename);
|
||||
unlink(storage_path('app/media/') . $filename);
|
||||
$this->removeDirIfEmpty(storage_path('app/media'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
|
@ -256,7 +250,6 @@ class MicropubMediaTest extends TestCase
|
|||
public function mediaEndpointUploadFile(): void
|
||||
{
|
||||
Queue::fake();
|
||||
Storage::fake('s3');
|
||||
$file = __DIR__ . '/../aaron.png';
|
||||
|
||||
$response = $this->post(
|
||||
|
@ -268,18 +261,18 @@ class MicropubMediaTest extends TestCase
|
|||
);
|
||||
|
||||
$path = parse_url($response->headers->get('Location'), PHP_URL_PATH);
|
||||
$filename = substr($path, 7);
|
||||
$filename = Str::chopStart($path, '/media/');
|
||||
Queue::assertPushed(ProcessMedia::class);
|
||||
Storage::disk('local')->assertExists($filename);
|
||||
Storage::disk('local')->assertExists($path);
|
||||
// now remove file
|
||||
unlink(storage_path('app/') . $filename);
|
||||
unlink(storage_path('app/media/') . $filename);
|
||||
$this->removeDirIfEmpty(storage_path('app/media'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function mediaEndpointUploadAudioFile(): void
|
||||
{
|
||||
Queue::fake();
|
||||
Storage::fake('s3');
|
||||
$file = __DIR__ . '/../audio.mp3';
|
||||
|
||||
$response = $this->post(
|
||||
|
@ -291,18 +284,18 @@ class MicropubMediaTest extends TestCase
|
|||
);
|
||||
|
||||
$path = parse_url($response->headers->get('Location'), PHP_URL_PATH);
|
||||
$filename = substr($path, 7);
|
||||
$filename = Str::chopStart($path, '/media/');
|
||||
Queue::assertPushed(ProcessMedia::class);
|
||||
Storage::disk('local')->assertExists($filename);
|
||||
Storage::disk('local')->assertExists($path);
|
||||
// now remove file
|
||||
unlink(storage_path('app/') . $filename);
|
||||
unlink(storage_path('app/media/') . $filename);
|
||||
$this->removeDirIfEmpty(storage_path('app/media'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function mediaEndpointUploadVideoFile(): void
|
||||
{
|
||||
Queue::fake();
|
||||
Storage::fake('s3');
|
||||
$file = __DIR__ . '/../video.ogv';
|
||||
|
||||
$response = $this->post(
|
||||
|
@ -314,18 +307,18 @@ class MicropubMediaTest extends TestCase
|
|||
);
|
||||
|
||||
$path = parse_url($response->headers->get('Location'), PHP_URL_PATH);
|
||||
$filename = substr($path, 7);
|
||||
$filename = Str::chopStart($path, '/media/');
|
||||
Queue::assertPushed(ProcessMedia::class);
|
||||
Storage::disk('local')->assertExists($filename);
|
||||
Storage::disk('local')->assertExists($path);
|
||||
// now remove file
|
||||
unlink(storage_path('app/') . $filename);
|
||||
unlink(storage_path('app/media/') . $filename);
|
||||
$this->removeDirIfEmpty(storage_path('app/media'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function mediaEndpointUploadDocumentFile(): void
|
||||
{
|
||||
Queue::fake();
|
||||
Storage::fake('s3');
|
||||
|
||||
$response = $this->post(
|
||||
'/api/media',
|
||||
|
@ -336,11 +329,12 @@ class MicropubMediaTest extends TestCase
|
|||
);
|
||||
|
||||
$path = parse_url($response->headers->get('Location'), PHP_URL_PATH);
|
||||
$filename = substr($path, 7);
|
||||
$filename = Str::chopStart($path, '/media/');
|
||||
Queue::assertPushed(ProcessMedia::class);
|
||||
Storage::disk('local')->assertExists($filename);
|
||||
Storage::disk('local')->assertExists($path);
|
||||
// now remove file
|
||||
unlink(storage_path('app/') . $filename);
|
||||
unlink(storage_path('app/media/') . $filename);
|
||||
$this->removeDirIfEmpty(storage_path('app/media'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
|
|
|
@ -60,7 +60,7 @@ class ParseCachedWebMentionsTest 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');
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ class TokenServiceTest extends TestCase
|
|||
*/
|
||||
public function tokenserviceCreatesAndValidatesTokens(): void
|
||||
{
|
||||
$tokenService = new TokenService();
|
||||
$tokenService = new TokenService;
|
||||
$data = [
|
||||
'me' => 'https://example.org',
|
||||
'client_id' => 'https://quill.p3k.io',
|
||||
|
@ -55,7 +55,7 @@ class TokenServiceTest extends TestCase
|
|||
$config = resolve(Configuration::class);
|
||||
|
||||
$token = $config->builder()
|
||||
->issuedAt(new DateTimeImmutable())
|
||||
->issuedAt(new DateTimeImmutable)
|
||||
->withClaim('client_id', $data['client_id'])
|
||||
->withClaim('me', $data['me'])
|
||||
->withClaim('scope', $data['scope'])
|
||||
|
@ -63,7 +63,7 @@ class TokenServiceTest extends TestCase
|
|||
->getToken($config->signer(), InMemory::plainText(random_bytes(32)))
|
||||
->toString();
|
||||
|
||||
$service = new TokenService();
|
||||
$service = new TokenService;
|
||||
$service->validateToken($token);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue