Skip to content

Commit

Permalink
Fix images and cache
Browse files Browse the repository at this point in the history
  • Loading branch information
daVitekPL committed Oct 3, 2024
1 parent c9db206 commit 3a33248
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
2 changes: 1 addition & 1 deletion config/responsecache.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* You can provide your own class given that it implements the
* CacheProfile interface.
*/
'cache_profile' => Spatie\ResponseCache\CacheProfiles\CacheAllSuccessfulGetRequests::class,
'cache_profile' => \EscolaLms\Courses\Services\CacheGetRequestService::class,

/*
* When using the default CacheRequestFilter this setting controls the
Expand Down
18 changes: 9 additions & 9 deletions database/factories/CourseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ public function configure()
//
$id = $course->id;
$word = $this->faker->word;
$filename_image = "course/$id/" . $word . ".jpg";
$filename_video = "course/$id/" . $word . ".mp4";
$filename_poster = "course/$id/" . $word . "poster.jpg";
$filename_image = $word . ".jpg";
$filename_video = $word . ".mp4";
$filename_poster = $word . "poster.jpg";

Storage::putFileAs("course/{$id}", new File(__DIR__ . '/../mocks/1.jpg'), $filename_image);
Storage::putFileAs("course/{$id}", new File(__DIR__ . '/../mocks/1.mp4'), $filename_video);
Storage::putFileAs("course/{$id}", new File(__DIR__ . '/../mocks/poster.jpg'), $filename_poster);
Storage::putFileAs("course/{$id}/images", new File(__DIR__ . '/../mocks/1.jpg'), $filename_image);
Storage::putFileAs("course/{$id}/videos", new File(__DIR__ . '/../mocks/1.mp4'), $filename_video);
Storage::putFileAs("course/{$id}/posters", new File(__DIR__ . '/../mocks/poster.jpg'), $filename_poster);

$course->update([
'image_path' => $filename_image,
'video_path' => $filename_video,
'poster_path' => $filename_poster,
'image_path' => "course/{$id}/images/" . $filename_image,
'video_path' => "course/{$id}/videos/" . $filename_video,
'poster_path' => "course/{$id}/posters/" . $filename_poster,
]);
});
}
Expand Down
13 changes: 13 additions & 0 deletions src/Repositories/CourseRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;

/**
* Class CourseRepository
Expand Down Expand Up @@ -219,6 +220,18 @@ public function update(array $input, int $id): Model

$isActive = $model->is_active;

if (isset($input['video_path'])) {
$input['video_path'] = Str::after($input['video_path'], env('AWS_ACCESS_KEY_ID') . '/');
}

if (isset($input['image_path'])) {
$input['image_path'] = Str::after($input['image_path'], env('AWS_ACCESS_KEY_ID') . '/');
}

if (isset($input['poster_path'])) {
$input['poster_path'] = Str::after($input['poster_path'], env('AWS_ACCESS_KEY_ID') . '/');
}

if (isset($input['video'])) {
$input['video_path'] = FileHelper::getFilePath($input['video'], "course/$id/videos");
}
Expand Down
14 changes: 14 additions & 0 deletions src/Services/CacheGetRequestService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace EscolaLms\Courses\Services;

use Illuminate\Http\Request;
use Spatie\ResponseCache\CacheProfiles\CacheAllSuccessfulGetRequests;

class CacheGetRequestService extends CacheAllSuccessfulGetRequests
{
public function useCacheNameSuffix(Request $request): string
{
return $_SERVER['SERVER_NAME'] . '_' . parent::useCacheNameSuffix($request);
}
}

0 comments on commit 3a33248

Please sign in to comment.