|
| 1 | +--- |
| 2 | +i18nReady: true |
| 3 | +title: Point de terminaison de l'API |
| 4 | +description: Découvrez les points de terminaison de l'API disponibles dans l'API de stockage de StudioCMS. |
| 5 | +tableOfContents: |
| 6 | + minHeadingLevel: 2 |
| 7 | + maxHeadingLevel: 4 |
| 8 | +sidebar: |
| 9 | + order: 3 |
| 10 | + badge: |
| 11 | + text: NOUVEAU |
| 12 | + variant: success |
| 13 | +--- |
| 14 | + |
| 15 | +import ReadMore from '~/components/ReadMore.astro'; |
| 16 | +import { Aside } from '@astrojs/starlight/components'; |
| 17 | + |
| 18 | +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. |
| 19 | + |
| 20 | +<Aside type="note" title="Utilise locals pour l'autorisation"> |
| 21 | +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. |
| 22 | +</Aside> |
| 23 | + |
| 24 | +### Méthode : PUT |
| 25 | + |
| 26 | +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`. |
| 27 | + |
| 28 | +```http title="API de stockage - PUT /studiocms_api/storage/manager" |
| 29 | +PUT /studiocms_api/storage/manager HTTP/1.1 |
| 30 | +Host: example.com |
| 31 | +Content-Type: application/octet-stream |
| 32 | +Accept: application/json |
| 33 | +Headers: |
| 34 | + x-storage-key: my-file.txt |
| 35 | +
|
| 36 | +<file-content> |
| 37 | +``` |
| 38 | + |
| 39 | +#### Réponse de succès |
| 40 | + |
| 41 | +```http title="API de stockage - PUT Réponse de succès" |
| 42 | +HTTP/1.1 200 OK |
| 43 | +Content-Type: application/json |
| 44 | +
|
| 45 | +{ |
| 46 | + "message": "string", |
| 47 | + "key": "string" |
| 48 | +} |
| 49 | +``` |
| 50 | + |
| 51 | +#### Réponse d'erreur |
| 52 | + |
| 53 | +```http title="API de stockage - PUT Réponse d'erreur" |
| 54 | +HTTP/1.1 4XX/5XX Error |
| 55 | +Content-Type: application/json |
| 56 | +
|
| 57 | +{ |
| 58 | + "error": "string" |
| 59 | +} |
| 60 | +``` |
| 61 | + |
| 62 | +### Méthode : POST |
| 63 | + |
| 64 | +```http title="API de stockage - POST /studiocms_api/storage/manager" |
| 65 | +POST /studiocms_api/storage/manager HTTP/1.1 |
| 66 | +Host: example.com |
| 67 | +Content-Type: application/json |
| 68 | +Accept: application/json |
| 69 | +
|
| 70 | +{ |
| 71 | + "action": "resolveUrl | publicUrl | upload | list | delete | rename | download | cleanup | mappings | test", |
| 72 | + ...paramètres supplémentaires reposant sur l'action... |
| 73 | +} |
| 74 | +``` |
| 75 | + |
| 76 | +#### Actions |
| 77 | + |
| 78 | +- `resolveUrl` |
| 79 | + - **Paramètres :** `{ identifier: string }` |
| 80 | + - **Réponse :** [`UrlMetadata`](#urlmetadata) |
| 81 | +- `publicUrl` |
| 82 | + - **Paramètres :** `{ key: string }` |
| 83 | + - **Réponse :** [`UrlMetadata`](#urlmetadata) `& { identifier: string }` |
| 84 | +- `upload` |
| 85 | + - **Paramètres :** `{ key: string, contentType: string }` |
| 86 | + - **Réponse :** `{ url: string, key: string }` |
| 87 | +- `list` |
| 88 | + - **Paramètres :** `{ prefix?: string, key?: string }` |
| 89 | + - **Réponse :** `{ files:` [`File[]`](#file) `}` |
| 90 | +- `delete` |
| 91 | + - **Paramètres :** `{ key: string }` |
| 92 | + - **Réponse :** `{ success: boolean }` |
| 93 | +- `rename` |
| 94 | + - **Paramètres :** `{ key: string, newKey: string }` |
| 95 | + - **Réponse :** `{ success: boolean, newKey: string }` |
| 96 | +- `download` |
| 97 | + - **Paramètres :** `{ key: string }` |
| 98 | + - **Réponse :** `{ url: string }` |
| 99 | +- `cleanup` |
| 100 | + - **Paramètres :** `N/A` |
| 101 | + - **Réponse :** `{ deletedCount: number }` |
| 102 | +- `mappings` |
| 103 | + - **Paramètres :** `N/A` |
| 104 | + - **Réponse :** `{ mappings:` [`UrlMetadata[]`](#urlmetadata) `}` |
| 105 | +- `test` |
| 106 | + - **Paramètres :** `N/A` |
| 107 | + - **Réponse :** `{ success: boolean, message: string, provider: string }` |
| 108 | + |
| 109 | +#### Réponse d'erreur |
| 110 | + |
| 111 | +```http title="Storage API - POST Réponse d'erreur" |
| 112 | +HTTP/1.1 4XX/5XX Error |
| 113 | +Content-Type: application/json |
| 114 | +
|
| 115 | +{ |
| 116 | + "error": "string" |
| 117 | +} |
| 118 | +``` |
| 119 | + |
| 120 | +## Types |
| 121 | + |
| 122 | +### UrlMetadata |
| 123 | + |
| 124 | +```ts |
| 125 | +export interface UrlMetadata { |
| 126 | + url: string; |
| 127 | + isPermanent: boolean; |
| 128 | + expiresAt?: number; // Horodatage Unix en ms |
| 129 | +} |
| 130 | +``` |
| 131 | + |
| 132 | +### File |
| 133 | + |
| 134 | +```ts |
| 135 | +export interface File { |
| 136 | + key: string | undefined; |
| 137 | + size: number | undefined; |
| 138 | + lastModified: Date | undefined; |
| 139 | +} |
| 140 | +``` |
0 commit comments