Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ jobs:
with:
node-version: latest

- name: Setup pnpm
uses: pnpm/action-setup@v5
with:
version: latest

- name: Get composer cache directory
id: composer-cache
run: |
Expand All @@ -66,8 +71,8 @@ jobs:

- name: Generate vite manifest
run: |
npm ci
npm run build
pnpm install
pnpm run build

- name: Prepare the application
run: |
Expand Down
8 changes: 4 additions & 4 deletions app/Http/Controllers/Api/UploadImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public function __construct(
*/
public function __invoke(UploadImageRequest $request): JsonResponse
{
$file = $request->file('upload');
$imageName = $this->fileService->generateFileName($file->getClientOriginalExtension());
Storage::disk()->put('images/'.$imageName, $file->getContent());
$url = Storage::disk()->url('images/'.$imageName);
$image = $request->image('upload')->toWebp();
$name = $this->fileService->generateFileName();
$image->storeAs(path: 'images', name: "$name.{$image->extension()}", disk: config('filesystems.default'));
$url = Storage::disk()->url('images/'."$name.{$image->extension()}");

return response()->json(['url' => $url]);
}
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/Post/ShowDefaultPreviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function __invoke(Request $request, Post $post)
$image = new Generator()
->size(Size::OpenGraph)
->format($format)
->quality(100)
->background(new Gradient(from: '#00d5be', to: '#00d3f2', direction: GradientDirection::Diagonal))
->title(new TextBlock(
text: $post->title,
Expand Down
9 changes: 8 additions & 1 deletion app/Models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@ class Category extends Model
public $timestamps = false;

protected $fillable = [
'name', 'icon', 'description',
'name', 'icon', 'description', 'is_default',
];

protected function casts(): array
{
return [
'is_default' => 'boolean',
];
}

public function posts(): HasMany
{
return $this->hasMany(Post::class);
Expand Down
6 changes: 3 additions & 3 deletions app/Services/FileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ class FileService
/**
* @throws RandomException
*/
public static function generateFileName(string $fileExtension): string
public static function generateFileName(): string
{
$bytes = random_bytes(6);
$randomString = bin2hex($bytes);

// format: 2023_01_01_10_18_21_63b0ed6d06d5.jpg
return date('Y_m_d_H_i_s').'_'.$randomString.'.'.strtolower($fileExtension);
// format: 2023_01_01_10_18_21_63b0ed6d06d5
return date('Y_m_d_H_i_s').'_'.$randomString;
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"bref/bref": "^3.0",
"bref/laravel-bridge": "^3.0",
"guzzlehttp/guzzle": "^7.2",
"intervention/image": "^4.0",
"laravel/framework": "^13.0",
"laravel/octane": "^2.3",
"laravel/sanctum": "^4.0",
Expand Down
Loading
Loading