Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
SethSharp committed Feb 10, 2024
1 parent f55698d commit d1cead6
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 8 deletions.
6 changes: 5 additions & 1 deletion app/Domain/File/Actions/DestroyFileAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ class DestroyFileAction
public function __invoke(File $file): bool
{
try {
Storage::disk('s3')->delete($file->path);
Storage::disk(app()->environment('local')
? 'public'
: config('filesystems.default'))
->delete($file->path);

return true;
} catch (Exception $e) {
return false;
Expand Down
7 changes: 5 additions & 2 deletions app/Domain/File/Actions/StoreFileAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ public function __invoke(UploadedFile $file): string
{
$structure = app()->environment('local') ? 'testing/' : 'production/';

$dir = $structure . 'blogs/images';
$dir = $structure . 'blogs';

return Storage::disk('s3')->put($dir, $file);
return Storage::disk(app()->environment('local')
? 'public'
: config('filesystems.default'))
->put($dir, $file);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class StoreBlogImageController extends Controller
public function __invoke(StoreBlogImageRequest $request, StoreFileAction $action): JsonResponse
{
$path = $action($request->file('file'));
$url = Storage::disk('s3')->url($path);
$url = app()->environment('local')
? $path
: Storage::url($path);

$fileId = intval($request->input('fileId'));
$blogId = intval($request->input('blogId')) ?: null;
Expand Down
6 changes: 3 additions & 3 deletions resources/js/Components/Editor/Nodes/Image/View.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ export default {
<script setup>
import { ref } from 'vue'
import { NodeViewWrapper, nodeViewProps } from '@tiptap/vue-3'
import { PhotoIcon, XMarkIcon } from '@heroicons/vue/24/solid'
import { PhotoIcon } from '@heroicons/vue/24/solid'
import EditableNode from '../../Components/EditableNodeWrapper.vue'
import EditImage from '@/Components/Editor/Components/Modals/EditImage.vue'
import SecondaryButton from '@/Components/Buttons/SecondaryButton.vue'
import breakdownNodeViewProps from '@/Helpers/breakdownNodeViewProps'
import EditImage from '@/Components/Editor/Components/Modals/EditImage.vue'
const props = defineProps({
...nodeViewProps,
Expand Down Expand Up @@ -42,6 +41,7 @@ let { fileId, blogId, src, alt, height } = breakdownNodeViewProps(props)
<div class="flex w-full justify-center">
<div class="flex-col w-full">
<div v-if="src" class="flex mb-4 w-full">
{{ src }}
<img :src="src" />
</div>

Expand Down
2 changes: 1 addition & 1 deletion resources/views/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<!-- Scripts -->
@routes
@vite(['resources/js/app.js', "resources/js/Pages/{$page['component']}.vue"])
@vite('resources/js/app.js')
@inertiaHead
</head>
<body class="font-sans antialiased">
Expand Down
23 changes: 23 additions & 0 deletions tests/Domain/File/Actions/StoreFileActionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Tests\Domain\File\Actions;

use Tests\TestCase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use App\Domain\File\Actions\StoreFileAction;

class StoreFileActionTest extends TestCase
{
/** @test */
public function can_store_file()
{
Storage::fake();

$file = UploadedFile::fake()->image('file.jpg');

app(StoreFileAction::class)($file);

Storage::assertExists($file->hashName('testing/blogs'));
}
}

0 comments on commit d1cead6

Please sign in to comment.