Working state
This commit is contained in:
@@ -103,12 +103,10 @@ final class MediaController
|
|||||||
return $this->jsonError($res, $e->getMessage(), 500);
|
return $this->jsonError($res, $e->getMessage(), 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
$res->getBody()->write(json_encode([
|
return $this->jsonOk($res, [
|
||||||
'success' => true,
|
|
||||||
'url' => $url,
|
'url' => $url,
|
||||||
], JSON_THROW_ON_ERROR));
|
'file' => $url,
|
||||||
|
]);
|
||||||
return $res->withHeader('Content-Type', 'application/json')->withStatus(200);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -150,21 +148,21 @@ final class MediaController
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retourne une réponse JSON de succès avec l'URL du fichier uploadé.
|
* Retourne une réponse JSON de succès.
|
||||||
*
|
*
|
||||||
* @param Response $res La réponse HTTP
|
* @param Response $res La réponse HTTP
|
||||||
* @param string $fileUrl L'URL publique du fichier
|
* @param array<string, mixed> $data Données supplémentaires à fusionner
|
||||||
*
|
*
|
||||||
* @return Response La réponse JSON {"success": true, "file": "..."}
|
* @return Response La réponse JSON {"success": true, ...}
|
||||||
*/
|
*/
|
||||||
private function jsonSuccess(Response $res, string $fileUrl): Response
|
private function jsonOk(Response $res, array $data = []): Response
|
||||||
{
|
{
|
||||||
$res->getBody()->write(json_encode([
|
$payload = json_encode(array_merge(['success' => true], $data), JSON_THROW_ON_ERROR);
|
||||||
'success' => true,
|
$res->getBody()->write($payload);
|
||||||
'file' => $fileUrl,
|
|
||||||
], JSON_THROW_ON_ERROR));
|
|
||||||
|
|
||||||
return $res->withHeader('Content-Type', 'application/json')->withStatus(200);
|
return $res
|
||||||
|
->withHeader('Content-Type', 'application/json')
|
||||||
|
->withStatus(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user