Skip to content

Commit

Permalink
fix: modifie façon d'envoyer les annexes (pb à cause de FormData)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocruze committed Nov 23, 2023
1 parent 4347504 commit 5fcf994
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions src/Services/EntrepotApi/AnnexeApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,43 @@ public function get(string $datastoreId, string $annexeId): array
* @param array<string> $paths
* @param array<string> $labels
*/
public function add(string $datastoreId, string $annexeFilePath, array $paths, array $labels = []): array
public function add(string $datastoreId, string $annexeFilePath, array $paths, array $labels = null, bool $published = true): array
{
$response = $this->sendFile('POST', "datastores/$datastoreId/annexes", $annexeFilePath, [
'published' => 'true',
'paths' => $paths,
'labels' => $labels,
'published' => true === $published ? 'true' : 'false',
'paths' => join(',', $paths), // ici on fait un join parce que c'est un FormData, qui ne gère pas bien les virgules
]);

$response = $this->modify($datastoreId, $response['_id'], null, $labels, null);

$this->filesystem->remove($annexeFilePath);

return $response;
}

/**
* @param array<string> $paths
* @param array<string> $labels
*/
public function modify(string $datastoreId, string $annexeId, array $paths = null, array $labels = null, bool $published = null): array
{
$body = [];

if ($paths) {
$body['paths'] = $paths;
}

if ($labels) {
$body['labels'] = $labels;
}

if (null !== $published) {
$body['published'] = true === $published ? 'true' : 'false';
}

return $this->request('PATCH', "datastores/$datastoreId/annexes/$annexeId", $body);
}

public function replaceFile(string $datastoreId, string $annexeId, string $annexeFilePath): array
{
$response = $this->sendFile('PUT', "datastores/$datastoreId/annexes/$annexeId", $annexeFilePath);
Expand Down

0 comments on commit 5fcf994

Please sign in to comment.