Skip to content

Commit f37dff5

Browse files
committed
s3 with b2
1 parent 1a6cd51 commit f37dff5

10 files changed

Lines changed: 326 additions & 38 deletions

File tree

‎.env.example‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ LOG_STACK=single
2121
LOG_DEPRECATIONS_CHANNEL=null
2222
LOG_LEVEL=debug
2323

24-
DB_CONNECTION=sqlite
24+
DB_CONNECTION=mysql
2525
DB_HOST=127.0.0.1
2626
DB_PORT=3306
2727
DB_DATABASE=computer_science_resources
@@ -48,20 +48,22 @@ REDIS_HOST=127.0.0.1
4848
REDIS_PASSWORD=null
4949
REDIS_PORT=6379
5050

51-
MAIL_MAILER=log
52-
MAIL_SCHEME=null
53-
MAIL_HOST=127.0.0.1
54-
MAIL_PORT=2525
51+
MAIL_MAILER=smtp
52+
MAIL_HOST=mailpit
53+
MAIL_PORT=1025
5554
MAIL_USERNAME=null
5655
MAIL_PASSWORD=null
57-
MAIL_FROM_ADDRESS="hello@example.com"
56+
MAIL_ENCRYPTION=null
57+
MAIL_FROM_ADDRESS="noreply@computerscienceresources.com"
5858
MAIL_FROM_NAME="${APP_NAME}"
5959

60-
AWS_ACCESS_KEY_ID=
61-
AWS_SECRET_ACCESS_KEY=
62-
AWS_DEFAULT_REGION=us-east-1
63-
AWS_BUCKET=
64-
AWS_USE_PATH_STYLE_ENDPOINT=false
60+
FILESYSTEM_PUBLIC_DRIVER="local"
61+
62+
B2_ACCESS_KEY_ID=
63+
B2_SECRET_ACCESS_KEY=
64+
B2_DEFAULT_REGION=
65+
B2_BUCKET=
66+
B2_ENDPOINT=
6567

6668
VITE_APP_NAME="${APP_NAME}"
6769

‎app/Http/Controllers/ComputerScienceResourceController.php‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Illuminate\Support\Facades\Log;
2020
use Inertia\Inertia;
2121
use Throwable;
22+
use Exception;
2223

2324
class ComputerScienceResourceController extends Controller
2425
{
@@ -65,16 +66,24 @@ public function create()
6566
public function store(StoreResourceRequest $request)
6667
{
6768
$validatedData = $request->validated();
68-
Log::debug('Called store resource with data '.json_encode($request));
6969

7070
DB::beginTransaction();
7171
try {
7272
// Store the image onto storage
7373
$path = null;
7474
if (array_key_exists('image_file', $validatedData) && $imageFile = $validatedData['image_file']) {
7575
$path = $imageFile->store('resource', 'public');
76+
if (!$path) {
77+
Log::error('Failed to store image file', [
78+
'user_id' => Auth::id(),
79+
'file_info' => $imageFile,
80+
]);
81+
82+
throw new Exception('Could not save the image.');
83+
}
7684
}
7785

86+
7887
$resource = ComputerScienceResource::create([
7988
'user_id' => Auth::id(),
8089
'name' => $validatedData['name'],

‎app/Http/Requests/ComputerScienceResource/StoreResourceRequest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function rules(): array
3535
'topic_tags.*' => ['required', 'distinct', 'string', 'max:50'],
3636

3737
// Optional, can just be omitted
38-
'image_file' => ['nullable', 'image', 'max:400'], // 400 kiloBytes
38+
'image_file' => ['nullable', 'image', 'max:500'], // 500 kiloBytes
3939
'general_tags' => ['array'],
4040
'general_tags.*' => ['required', 'distinct', 'string', 'max:50'],
4141
'programming_language_tags' => ['array'],

‎app/Http/Requests/ResourceEdit/StoreResourceEdit.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function rules(): array
3737
'proposed_changes.pricing' => ['nullable', 'string', Rule::in(config('computerScienceResource.pricings'))],
3838
'proposed_changes.topic_tags' => ['nullable', 'array', 'min:2'],
3939
'proposed_changes.topic_tags.*' => ['required', 'distinct', 'string', 'max:50'],
40-
'proposed_changes.image_file' => ['nullable', 'image', 'max:400'], // 400 kilobytes
40+
'proposed_changes.image_file' => ['nullable', 'image', 'max:500'], // 500 kilobytes
4141
'proposed_changes.general_tags' => ['nullable', 'array'],
4242
'proposed_changes.general_tags.*' => ['required', 'distinct', 'string', 'max:50'],
4343
'proposed_changes.programming_language_tags' => ['nullable', 'array'],

‎app/Models/ComputerScienceResource.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function user(): BelongsTo
6262
protected function imageUrl(): Attribute
6363
{
6464
return Attribute::make(
65-
get: fn () => $this->image_path ? Storage::url($this->image_path) : null,
65+
get: fn () => $this->image_path ? Storage::disk('public')->url($this->image_path) : null,
6666
);
6767
}
6868

‎app/Models/NewsPost.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class NewsPost extends Model
1818
protected function thumbnailUrl(): Attribute
1919
{
2020
return Attribute::make(
21-
get: fn () => Storage::url($this->thumbnail_path)
21+
get: fn () => Storage::disk('public')->url($this->thumbnail_path)
2222
);
2323
}
2424

‎app/Models/ResourceEdits.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ protected function proposedChanges(): Attribute
8383
if (array_key_exists('image_path', $changes)) {
8484
$changes['image_url'] = null;
8585
if ($changes['image_path']) {
86-
$changes['image_url'] = Storage::url($changes['image_path']);
86+
$changes['image_url'] = Storage::disk('public')->url($changes['image_path']);
8787
}
8888
}
8989

‎composer.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"license": "MIT",
88
"require": {
99
"php": "^8.2",
10+
"aws/aws-sdk-php": "3.336",
1011
"cviebrock/eloquent-sluggable": "^11.0",
1112
"filament/filament": "^3.3",
1213
"filament/tables": "^3.3",
@@ -17,6 +18,7 @@
1718
"laravel/jetstream": "^5.3",
1819
"laravel/sanctum": "^4.0",
1920
"laravel/tinker": "^2.9",
21+
"league/flysystem-aws-s3-v3": "^3.0",
2022
"shiftonelabs/laravel-cascade-deletes": "^2.0",
2123
"spatie/laravel-activitylog": "^4.10",
2224
"spatie/laravel-tags": "^4.9",

0 commit comments

Comments
 (0)