Point de terminaison de l'API
L’API de stockage expose des points de terminaison accessibles via des requêtes HTTP. Les sections suivantes décrivent les points de terminaison disponibles et leur utilisation.
Les points de terminaison de l’API de stockage utilisent la fonctionnalité locals d’Astro, propagée par le middleware, pour gérer l’autorisation. Assurez-vous que le navigateur ou le client effectuant les requêtes provient d’un utilisateur StudioCMS connecté et disposant des autorisations nécessaires pour effectuer des opérations de stockage.
Méthode : PUT
Section intitulée « Méthode : PUT »Pour télécharger ou mettre à jour un fichier dans le système de stockage, vous pouvez utiliser la méthode PUT dans le point de terminaison /studiocms_api/storage/manager.
PUT /studiocms_api/storage/manager HTTP/1.1Host: example.comContent-Type: application/octet-streamAccept: application/jsonHeaders: x-storage-key: my-file.txt
<file-content>Réponse de succès
Section intitulée « Réponse de succès »HTTP/1.1 200 OKContent-Type: application/json
{ "message": "string", "key": "string"}Réponse d’erreur
Section intitulée « Réponse d’erreur »HTTP/1.1 4XX/5XX ErrorContent-Type: application/json
{ "error": "string"}Méthode : POST
Section intitulée « Méthode : POST »POST /studiocms_api/storage/manager HTTP/1.1Host: example.comContent-Type: application/jsonAccept: application/json
{ "action": "resolveUrl | publicUrl | upload | list | delete | rename | download | cleanup | mappings | test", ...paramètres supplémentaires reposant sur l'action...}resolveUrl- Paramètres :
{ identifier: string } - Réponse :
UrlMetadata
- Paramètres :
publicUrl- Paramètres :
{ key: string } - Réponse :
UrlMetadata& { identifier: string }
- Paramètres :
upload- Paramètres :
{ key: string, contentType: string } - Réponse :
{ url: string, key: string }
- Paramètres :
list- Paramètres :
{ prefix?: string, key?: string } - Réponse :
{ files:File[]}
- Paramètres :
delete- Paramètres :
{ key: string } - Réponse :
{ success: boolean }
- Paramètres :
rename- Paramètres :
{ key: string, newKey: string } - Réponse :
{ success: boolean, newKey: string }
- Paramètres :
download- Paramètres :
{ key: string } - Réponse :
{ url: string }
- Paramètres :
cleanup- Paramètres :
N/A - Réponse :
{ deletedCount: number }
- Paramètres :
mappings- Paramètres :
N/A - Réponse :
{ mappings:UrlMetadata[]}
- Paramètres :
test- Paramètres :
N/A - Réponse :
{ success: boolean, message: string, provider: string }
- Paramètres :
Réponse d’erreur
Section intitulée « Réponse d’erreur »HTTP/1.1 4XX/5XX ErrorContent-Type: application/json
{ "error": "string"}UrlMetadata
Section intitulée « UrlMetadata »export interface UrlMetadata { url: string; isPermanent: boolean; expiresAt?: number; // Horodatage Unix en ms}export interface File { key: string | undefined; size: number | undefined; lastModified: Date | undefined;}