Skip to content

Commit cedee53

Browse files
authored
feat: add host url to curl calls (#170)
1 parent 2010ca8 commit cedee53

6 files changed

Lines changed: 24 additions & 13 deletions

File tree

.php-cs-fixer.dist.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public function getRules(array $rules = []): array
3030
->ignoreVCSIgnored(true)
3131
->notPath('dev-environment')
3232
->notPath('build')
33+
->notPath('css')
34+
->notPath('js')
3335
->notPath('l10n')
3436
->notPath('src')
3537
->notPath('vendor')

docker-compose.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ services:
106106
- backend
107107

108108
rsync:
109+
profiles: [ development ]
109110
build:
110111
context: ./docker/rsync
111112
dockerfile: Dockerfile
@@ -123,8 +124,7 @@ services:
123124
- backend
124125

125126
adminer:
126-
profiles:
127-
- development
127+
profiles: [ development ]
128128
# visit https://adminer.hejbit.local/?pgsql=postgres&username=swarmbox&db=swarmbox
129129
image: adminer:latest
130130
restart: unless-stopped
@@ -145,8 +145,7 @@ services:
145145
ADMINER_DEFAULT_SERVER: postgres
146146

147147
flagd:
148-
profiles:
149-
- feature
148+
profiles: [ feature ]
150149
image: ghcr.io/open-feature/flagd:latest
151150
restart: unless-stopped
152151
command: 'start --uri file:/etc/flagd/hejbit.flagd.json --cors-origin *'
@@ -164,8 +163,7 @@ services:
164163
condition: service_healthy
165164

166165
onlyoffice:
167-
profiles:
168-
- onlyoffice
166+
profiles: [ onlyoffice ]
169167
image: onlyoffice/documentserver
170168
environment:
171169
JWT_ENABLED: true

lib/Contract/Enum/ApiEndpoints.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace OCA\Files_External_Ethswarm\Contract\Enum;
4+
5+
enum ApiEndpoints: string {
6+
case DOWNLOAD = '/api/download';
7+
case UPLOAD = '/api/upload';
8+
case READINESS = '/api/readiness';
9+
}

lib/Storage/BeeSwarmTrait.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use CURLFile;
2525
use OCA\Files_External_Ethswarm\Auth\AccessKey;
2626
use OCA\Files_External_Ethswarm\Backend\BeeSwarm;
27+
use OCA\Files_External_Ethswarm\Contract\Enum\ApiEndpoints;
2728
use OCA\Files_External_Ethswarm\Dto\LinkDto;
2829
use OCA\Files_External_Ethswarm\Exception\CurlException;
2930
use OCA\Files_External_Ethswarm\Exception\HejBitException;
@@ -80,8 +81,8 @@ private function validateParams(array &$params): void {
8081
/**
8182
* @throws CurlException|HejBitException
8283
*/
83-
private function getLink(string $endpoint): LinkDto {
84-
$endpoint = $this->api_url.$endpoint;
84+
private function getLink(ApiEndpoints $endpoint): LinkDto {
85+
$endpoint = $this->api_url.$endpoint->value;
8586
$request = new Curl($endpoint, headers: [
8687
'accept: application/json',
8788
], authorization: $this->access_key);
@@ -102,7 +103,7 @@ private function uploadSwarm(string $path, string $tempFile, string $mimetype):
102103
return $this->uploadSwarmV1($path, $tempFile, $mimetype);
103104
}
104105

105-
$link = $this->getLink('/api/upload');
106+
$link = $this->getLink(ApiEndpoints::UPLOAD);
106107
$request = new Curl($link->url, authorization: $link->token);
107108
$response = $request->post([
108109
'file' => new CURLFile($tempFile, $mimetype, basename($path)),
@@ -126,7 +127,7 @@ private function downloadSwarm(string $reference) {
126127
return $this->downloadSwarmV1($reference);
127128
}
128129

129-
$link = $this->getLink('/api/download');
130+
$link = $this->getLink(ApiEndpoints::DOWNLOAD);
130131
$request = new Curl($link->url."/{$reference}", authorization: $link->token);
131132
$response = $request->get();
132133

@@ -151,7 +152,7 @@ private function checkConnection(): bool {
151152
return $this->checkConnectionV1();
152153
}
153154

154-
$endpoint = $this->api_url.'/api/readiness';
155+
$endpoint = $this->api_url.ApiEndpoints::READINESS->value;
155156

156157
$request = new Curl($endpoint, authorization: $this->access_key);
157158
$request->get();

lib/Utils/Curl.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ private function setOptions(array $options = []): void {
130130

131131
private function setHeaders(array $headers = []): void {
132132
$headers = $this->headers + $headers;
133+
$headers[] = 'X-NextCloud-Host: '.$_SERVER['HTTP_HOST'];
133134
if ($this->authorization) {
134135
$headers[] = match ($this->authorizationType) {
135136
CURLAUTH_BEARER => 'Authorization: Bearer '.$this->authorization,

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
"lint:fix": "biome lint --write src styles",
2525
"format": "biome format .",
2626
"format:fix": "biome format --write .",
27-
"backend:format": "PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --dry-run",
28-
"backend:format:fix": "PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix",
27+
"backend:format": "PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php --dry-run",
28+
"backend:format:fix": "PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php --path-mode=intersection --using-cache=no",
2929
"typecheck": "vue-tsc --noEmit"
3030
},
3131
"dependencies": {

0 commit comments

Comments
 (0)