Skip to content

Commit

Permalink
Merge pull request #115 from EscolaLMS/bugfix/fix-screen-directory
Browse files Browse the repository at this point in the history
Fix screen directory
  • Loading branch information
daVitekPL authored Oct 29, 2024
2 parents cf6cbf9 + c13c64e commit 75376c3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/Dto/ConsultationDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function toArray($filters = false): array
public function getImagePath()
{
if ($this->imagePath !== false) {
return $this->imagePath === null ? '' : Str::after($this->imagePath, env('AWS_ACCESS_KEY_ID') . '/');
return $this->imagePath === null ? '' : Str::after($this->imagePath, Str::after(env('AWS_URL'), 'https://') . '/');
}
return false;
}
Expand All @@ -47,7 +47,7 @@ public function getLogotypePath()
{
if ($this->logotypePath !== false) {
if ($this->logotypePath) {
$logotypePath = Str::after($this->logotypePath, env('AWS_ACCESS_KEY_ID') . '/');
$logotypePath = Str::after($this->logotypePath, Str::after(env('AWS_URL'), 'https://') . '/');
return Str::startsWith($logotypePath, ConstantEnum::DIRECTORY) ? $logotypePath : ConstantEnum::DIRECTORY . '/' .$logotypePath;
}
return '';
Expand All @@ -60,7 +60,8 @@ protected function setProposedTerms(array $proposedTerms): void
$result = [];
foreach ($proposedTerms as $term) {
if (is_int($term)) {
$date = Carbon::parse((string) ($term/1000));
// @phpstan-ignore-next-line
$date = Carbon::parse($term / 1000);
} else {
$date = Carbon::parse($term);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Services/ConsultationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ public function saveScreen(ConsultationSaveScreenDto $dto): void

$termin = Carbon::make($consultationUser->executed_at);
// consultation_id/term_start_timestamp/user_id/timestamp.jpg
$folder = "consultations/{$dto->getConsultationId()}/{$termin->getTimestamp()}/{$user->getKey()}";
$folder = ConstantEnum::DIRECTORY . "/{$dto->getConsultationId()}/{$termin->getTimestamp()}/{$user->getKey()}";

$extension = $dto->getFile() instanceof UploadedFile ? $dto->getFile()->getClientOriginalExtension() : Str::between($dto->getFile(), 'data:image/', ';base64');
Storage::putFileAs($folder, $dto->getFile(), Carbon::make($dto->getTimestamp())->getTimestamp() . '.' . $extension);
Expand Down
3 changes: 2 additions & 1 deletion tests/APIs/ConsultationApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use EscolaLms\Auth\Services\Contracts\UserServiceContract;
use EscolaLms\Categories\Models\Category;
use EscolaLms\Consultations\Database\Seeders\ConsultationsPermissionSeeder;
use EscolaLms\Consultations\Enum\ConstantEnum;
use EscolaLms\Consultations\Enum\ConsultationsPermissionsEnum;
use EscolaLms\Consultations\Enum\ConsultationStatusEnum;
use EscolaLms\Consultations\Enum\ConsultationTermStatusEnum;
Expand Down Expand Up @@ -241,7 +242,7 @@ public function testConsultationSaveScreen(): void

$term = Carbon::make($consultationUser->executed_at);
// consultation_id/term_start_timestamp/user_id/timestamp.jpg
Storage::assertExists("consultations/{$consultation->getKey()}/{$term->getTimestamp()}/{$student->getKey()}/{$time->getTimestamp()}.jpg");
Storage::assertExists(ConstantEnum::DIRECTORY . "/{$consultation->getKey()}/{$term->getTimestamp()}/{$student->getKey()}/{$time->getTimestamp()}.jpg");

$this->response = $this->json('POST', '/api/consultations/save-screen', [
'consultation_id' => $consultation->getKey(),
Expand Down

0 comments on commit 75376c3

Please sign in to comment.