Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use presigned urls for s3 #93

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions app/Http/Controllers/PortalsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ public function importUsers(Request $request)
$person->course = $abbreviation;
}

// import image
$person->img = (!empty($user['avatarUrl']) ? $user['avatarUrl'] : '');
// import image path
$person->img = $user['avatar'];

// cheeck roles
// check roles
$roles = $user['roles'];

// loop through roles
Expand Down
11 changes: 9 additions & 2 deletions app/Models/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Storage;
use NotificationChannels\Telegram\TelegramMessage;

class Person extends Model
Expand Down Expand Up @@ -47,9 +48,15 @@ class Person extends Model
*/
public function getImageAttribute()
{
if (!empty($this->img)) {
return $this->img;
// check if image is set and file exists
if (!empty($this->img) && Storage::disk('s3')->exists($this->img)) {
// generate presigned url for s3 with path stored in "img"
return Storage::disk('s3')->temporaryUrl(
$this->img,
now()->addMinutes(60)
);
} else {
// no image is set, return default image
return '/images/default.jpg';
}
}
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"laravel/octane": "*",
"laravel/sanctum": "^2.11",
"laravel/tinker": "^2.5",
"league/flysystem-aws-s3-v3": "^1.0",
"spiral/roadrunner": "^2.0"
},
"require-dev": {
Expand Down
Loading
Loading