Skip to content

Commit 73928e2

Browse files
authored
Merge pull request #11 from IFRCGo/feature/WN-257
WN-257
2 parents ff6a992 + 3645db1 commit 73928e2

15 files changed

Lines changed: 427 additions & 137 deletions

File tree

.env.example

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ MAIL_USERNAME=null
3030
MAIL_PASSWORD=null
3131
MAIL_ENCRYPTION=null
3232

33-
AWS_ACCESS_KEY_ID=
34-
AWS_SECRET_ACCESS_KEY=
35-
AWS_DEFAULT_REGION=us-east-1
36-
AWS_BUCKET=
33+
AZURE_STORAGE_DOMAIN=azure_domain
34+
AZURE_STORAGE_NAME=your_storage_name
35+
AZURE_STORAGE_KEY=your_storage_key
36+
AZURE_STORAGE_CONTAINER=your_container_name
37+
AZURE_STORAGE_CONNECTION_STRING=DefaultEndpointsProtocol=<protocol>;AccountName=<account_name>;AccountKey=<account_key>;EndpointSuffix=<endpoint_suffix>
3738

3839
PUSHER_APP_ID=
3940
PUSHER_APP_KEY=

app/Classes/Repositories/OrganisationRepository.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public function updateDetailsWithInput(Organisation $org, array $input)
8181
if (array_key_exists('url', $input)) {
8282
$org->update([
8383
'attribution_url' => $input['url'],
84+
'attribution_file_name' => $input['imageUrl'],
8485
]);
8586
}
8687

app/Classes/Transformers/OrganisationTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function transform(Organisation $model)
6363
return [
6464
'id' => $contributor->id,
6565
'name' => $contributor->name,
66-
'logo' => $contributor->logo,
66+
'logo' => $contributor->logo ? $contributor->getLogoImageUrl() : null,
6767
];
6868
});
6969
}

app/Classes/Transformers/WhatNowEntityTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function transform(WhatNowEntity $model)
9393
return [
9494
'id' => $contributor->id,
9595
'name' => $contributor->name,
96-
'logo' => $contributor->logo,
96+
'logo' => $contributor->logo ? $contributor->getLogoImageUrl() : null,
9797
];
9898
});
9999
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
use Illuminate\Support\Facades\Storage;
7+
8+
class FileUploadController extends Controller
9+
{
10+
public function upload(Request $request)
11+
{
12+
try {
13+
14+
$request->validate([
15+
'file' => 'required|file|mimes:jpg,png|max:10240',
16+
]);
17+
18+
19+
$file = $request->file('file');
20+
21+
22+
$fileName = $file->getClientOriginalName();
23+
24+
25+
$path = Storage::disk('azure')->putFileAs('', $file, $fileName);
26+
27+
return response()->json(['path' => $path], 200);
28+
} catch (\Illuminate\Validation\ValidationException $e) {
29+
return response()->json(['errors' => $e->errors()], 422);
30+
}
31+
}
32+
}

app/Models/Contributor.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,22 @@ public function organisation()
7272
return $this->belongsTo(OrganisationDetails::class, 'org_detail_id');
7373
}
7474

75+
public function getLogoPath()
76+
{
77+
return '/' . $this->logo;
78+
}
79+
80+
public function getLogoImageUrl()
81+
{
82+
$filepath = $this->getLogoPath();
83+
84+
if (app()->environment('production')) {
85+
86+
//return valid url
87+
return url(('https://'). config('app.bucket_name') . '.' . config('app.bucket_domain') . '/' . config('app.bucket_container') . $filepath);
88+
}
89+
//TODO configure for QA environment
90+
return url(('https://'). config('app.bucket_name') . '.' . config('app.bucket_domain') . '/' . config('app.bucket_container') . $filepath);
91+
}
92+
7593
}

app/Models/Organisation.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function regions()
4444

4545
public function getAttributionFilePath()
4646
{
47-
return '/attribution_images/' . $this->attribution_file_name;
47+
return '/' . $this->attribution_file_name;
4848
}
4949

5050
public function getAttributionImageUrl()
@@ -54,10 +54,10 @@ public function getAttributionImageUrl()
5454
if (app()->environment('production')) {
5555

5656
//return valid url
57-
return url(config('app.cdn_host') . config('app.cdn_asset_path') . $filepath);
57+
return url(('https://'). config('app.bucket_name') . '.' . config('app.bucket_domain') . '/' . config('app.bucket_container') . $filepath);
5858
}
59-
60-
return url(config('app.url') . config('app.cdn_asset_path') . $filepath);
59+
//TODO configure for QA environment
60+
return url(('https://'). config('app.bucket_name') . '.' . config('app.bucket_domain') . '/' . config('app.bucket_container') . $filepath);
6161
}
6262
}
6363

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace App\Providers;
4+
5+
use Illuminate\Support\ServiceProvider;
6+
use League\Flysystem\Filesystem;
7+
use MicrosoftAzure\Storage\Blob\BlobRestProxy;
8+
use League\Flysystem\AzureBlobStorage\AzureBlobStorageAdapter;
9+
10+
class AzureStorageServiceProvider extends ServiceProvider
11+
{
12+
public function boot()
13+
{
14+
\Storage::extend('azure', function($app, $config) {
15+
// Usar BlobRestProxy para crear el cliente de Blob Storage
16+
$client = BlobRestProxy::createBlobService($config['connection_string']);
17+
18+
// Crear el adaptador para Azure Blob Storage
19+
$adapter = new AzureBlobStorageAdapter(
20+
$client,
21+
$config['container']
22+
);
23+
24+
return new Filesystem($adapter);
25+
});
26+
}
27+
28+
public function register()
29+
{
30+
//
31+
}
32+
}

bootstrap/cache/.gitignore

100644100755
File mode changed.

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
"laravel/vapor-ui": "^1.6",
1919
"league/csv": "^9.8",
2020
"league/flysystem-aws-s3-v3": "^1.0",
21+
"league/flysystem-azure": "^1.0",
22+
"league/flysystem-azure-blob-storage": "^0.1.4",
2123
"league/fractal": "^0.20.0",
2224
"maxbanton/cwh": "^2.0",
25+
"microsoft/azure-storage-blob": "^1.0",
2326
"psr/log": "1.1.4"
2427
},
2528
"require-dev": {

0 commit comments

Comments
 (0)