From d465f5ecb809d68dd445583b5aeaa4ce567aba88 Mon Sep 17 00:00:00 2001
From: Jonas Leder <jonas@jonasled.de>
Date: Sat, 16 Apr 2022 23:11:42 +0200
Subject: [PATCH] get skills directly from s3 server

---
 js/customElements/skills.js   |  2 +-
 public/API/queries/skills.php | 13 ++++++++++++-
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/js/customElements/skills.js b/js/customElements/skills.js
index 383952a..60e3068 100644
--- a/js/customElements/skills.js
+++ b/js/customElements/skills.js
@@ -18,7 +18,7 @@ class Skill extends HTMLElement {
         skills.forEach(skill => {
             const image = document.createElement("img");
             image.classList.add("skills");
-            image.src = "/API/getFile.php?filename=" + skill;
+            image.src = skill;
             this.appendChild(image);
         });
 
diff --git a/public/API/queries/skills.php b/public/API/queries/skills.php
index 5bd97da..93b00de 100644
--- a/public/API/queries/skills.php
+++ b/public/API/queries/skills.php
@@ -17,7 +17,18 @@ function getSkills() {
 
         $response = [];
         foreach ($result["Contents"] as $skill){
-                array_push($response, $skill["Key"]);
+                // Get a command object from the client
+                $command = $s3Client->getCommand('GetObject', [
+                    'Bucket' => $S3BucketName,
+                    'Key'    => $skill["Key"]
+                ]);
+                
+                // Create a pre-signed URL for a request with duration of 10 miniutes
+                $presignedRequest = $s3Client->createPresignedRequest($command, '60 minutes');
+                
+                // Get the actual presigned-url
+                $downloadURL =  (string)  $presignedRequest->getUri();
+                array_push($response, $downloadURL);
         }
         return $response;
 }
-- 
GitLab