website/public/API/queries/skills.php

39 lines
1.6 KiB
PHP
Raw Normal View History

2022-03-08 10:04:11 +01:00
<?php
function getSkills() {
2022-03-08 15:11:10 +01:00
require "./lib/config.php";
2022-03-08 10:04:11 +01:00
$s3Client = new Aws\S3\S3Client([
'version' => 'latest',
'region' => 'us-east-1',
'endpoint' => $S3Server,
'use_path_style_endpoint' => true,
'credentials' => [
'key' => $S3AccessKey,
'secret' => $S3SecretKey,
],
]);
$result = $s3Client->ListObjects(['Bucket' => $S3BucketName, 'Delimiter'=>'/', 'Prefix' => 'skills/']);
$response = [];
foreach ($result["Contents"] as $skill){
2022-04-16 23:11:42 +02:00
// 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();
2022-04-16 23:34:35 +02:00
$encodedUrl = rtrim(strtr(base64_encode($downloadURL), '+/', '-_'), '=');
2022-05-01 13:13:10 +02:00
$path = "/rs:fit:0:$defaultSkillsWidth:1/g:no/{$encodedUrl}.webp";
2022-04-16 23:34:35 +02:00
$signature = rtrim(strtr(base64_encode(hash_hmac('sha256', $imgProxySalt.$path, $imgProxyKey, true)), '+/', '-_'), '=');
array_push($response, $imgProxyUrl . "/" . $signature . $path);
2022-03-08 10:04:11 +01:00
}
return $response;
2022-03-16 10:18:46 +01:00
}