[Nom de la Configuration Cloudflare Stream]
Type de ressource : Configuration Cloudflare Stream (Direct Upload / Lecture / Métadonnées)
Fichier source :services/media-upload/src/index.tsou configuration associée
Statut : [Actif / Déprécié / En développement]
Slice : [Numéro de la tranche verticale]
Version : 1.0
1. Vue dâensemble (DOC)
Section titled â1. Vue dâensemble (DOC)â1.1. Description
Section titled â1.1. Descriptionâ[Description concise du rĂŽle de cette configuration Stream dans lâarchitecture du site]
1.2. Objectif
Section titled â1.2. Objectifâ- [Objectif principal : ex. hĂ©berger les vidĂ©os du portfolio avec transcoding automatique]
- [BĂ©nĂ©fice pour lâarchitecture : ex. adaptive bitrate sans gestion serveur]
1.3. PérimÚtre concerné
Section titled â1.3. PĂ©rimĂštre concernĂ©â| Type de contenu | Statut |
|---|---|
| Portfolio | [â /â] |
| Blog | [â /â] |
| Pages vitrine | [â /â] |
| Format source | Statut |
|---|---|
| MP4 | [â /â] |
| MOV | [â /â] |
| WebM | [â /â] |
| AccĂšs | Statut |
|---|---|
| Public | [â /â] |
| PrivĂ© | [â /â] |
| SignĂ© | [â /â] |
2. Architecture et flux (DOC)
Section titled â2. Architecture et flux (DOC)â2.1. Diagramme de flux
Section titled â2.1. Diagramme de fluxâ[Sanity Studio] â (demande d'upload vidĂ©o) âŒ[Worker media-upload (L3)] â âą GĂ©nĂ©ration Direct Upload Token âŒ[Sanity Studio] â âą Upload direct vers Cloudflare Stream â âą Stocke l'uid dans le document âŒ[Cloudflare Stream] â âą Transcoding automatique â âą GĂ©nĂ©ration des thumbnails âŒ[Astro / Site] â âą Iframe ou SDK Stream âŒ[Utilisateur final]2.2. Composants impliquĂ©s
Section titled â2.2. Composants impliquĂ©sâ| Composant | RĂŽle | Couche |
|---|---|---|
| BibliothĂšque Stream | Stockage + transcoding | Infrastructure |
Worker media-upload |
Génération de tokens | L3 |
| Sanity | Stockage de lâUID Stream | L1 |
| Astro | Intégration du player | L2 |
3. Configuration (CODE)
Section titled â3. Configuration (CODE)â3.1. Variables dâenvironnement
Section titled â3.1. Variables dâenvironnementâ| Variable | Description | Obligatoire | Valeur par dĂ©faut |
|---|---|---|---|
CLOUDFLARE_ACCOUNT_ID |
ID du compte Cloudflare | â | - |
CLOUDFLARE_STREAM_API_TOKEN |
Token API Stream | â | - |
STREAM_PUBLIC_DOMAIN |
Domaine public | â | iframe.videodelivery.net |
3.2. Configuration du token API
Section titled â3.2. Configuration du token APIâDans le Dashboard Cloudflare :
- My Profile â API Tokens â Create Token
- Template : âCreate Custom Tokenâ
- Permissions : Account â Cloudflare Stream â Edit
wrangler secret put CLOUDFLARE_STREAM_API_TOKEN --env production3.3. Génération du Direct Upload Token
Section titled â3.3. GĂ©nĂ©ration du Direct Upload Tokenâexport default { async fetch(request: Request, env: Env): Promise<Response> { const response = await fetch( `https://api.cloudflare.com/client/v4/accounts/${env.CLOUDFLARE_ACCOUNT_ID}/stream/direct_upload`, { method: 'POST', headers: { 'Authorization': `Bearer ${env.CLOUDFLARE_STREAM_API_TOKEN}`, 'Content-Type': 'application/json', }, body: JSON.stringify({ maxDurationSeconds: 3600, requiredSignedURLs: false, }), } );
const data = await response.json(); return new Response(JSON.stringify(data), { headers: { 'Content-Type': 'application/json' }, }); },};4. Contrats dâEntrĂ©e/Sortie (SPEC)
Section titled â4. Contrats dâEntrĂ©e/Sortie (SPEC)â4.1. Inputs (Demande de token)
Section titled â4.1. Inputs (Demande de token)â| ParamĂštre | Type | Validation |
|---|---|---|
maxDurationSeconds |
number |
†3600 |
4.2. Outputs (Token + URL)
Section titled â4.2. Outputs (Token + URL)â| ĂlĂ©ment | Type | Description |
|---|---|---|
uploadURL |
string |
URL dâupload |
uid |
string |
UID de la vidéo |
5. Tests attendus (TEST)
Section titled â5. Tests attendus (TEST)â5.1. Tests unitaires
Section titled â5.1. Tests unitairesâ| ScĂ©nario | Description | RĂ©sultat attendu |
|---|---|---|
| GĂ©nĂ©ration token | RequĂȘte valide | Token gĂ©nĂ©rĂ© |
| Upload vidéo | Token valide | Vidéo uploadée |
5.2. Tests dâintĂ©gration
Section titled â5.2. Tests dâintĂ©grationâ| ScĂ©nario | DĂ©pendances | Description | RĂ©sultat attendu |
|---|---|---|---|
| Flux upload | Worker + Stream | Token â Upload | VidĂ©o stockĂ©e |
6. IntĂ©gration (INTĂG)
Section titled â6. IntĂ©gration (INTĂG)â6.1. IntĂ©gration avec les composants
Section titled â6.1. IntĂ©gration avec les composantsâ| Composant | Type | RĂŽle | MĂ©thode dâintĂ©gration |
|---|---|---|---|
| Sanity | L1 | Stockage UID | Champ videoUid |
| Astro | L2 | Player | Iframe ou SDK |
6.2. Points dâattention
Section titled â6.2. Points dâattentionâ- Le token doit ĂȘtre gĂ©nĂ©rĂ© cĂŽtĂ© serveur
- LâUID doit ĂȘtre stockĂ© dans Sanity
- Le player doit ĂȘtre configurĂ© correctement
6.3. Vérification de cohérence
Section titled â6.3. VĂ©rification de cohĂ©renceâ- Le token est gĂ©nĂ©rĂ©
- Lâupload fonctionne
- Le transcoding est automatique
- Le player affiche la vidéo
7. Sécurité
Section titled â7. SĂ©curitĂ©â7.1. MĂ©canismes de sĂ©curitĂ©
Section titled â7.1. MĂ©canismes de sĂ©curitĂ©â- â Token API injectĂ© via secret
- â HTTPS forcĂ©
- â Validation des durĂ©es
7.2. RÚgles de sécurité
Section titled â7.2. RĂšgles de sĂ©curitĂ©â- â Ne jamais exposer le token API
- â Limiter la durĂ©e des vidĂ©os
- â Configurer les permissions correctement
8. Performance et limites
Section titled â8. Performance et limitesâ8.1. Limites Stream
Section titled â8.1. Limites Streamâ| Limite | Valeur |
|---|---|
| Durée max vidéo | 3600s (1h) |
| Taille max fichier | 10 GB |
| Vidéos par compte | Illimité (facturé) |
8.2. Optimisations
Section titled â8.2. Optimisationsâ- â Transcoding automatique
- â Adaptive bitrate
- â CDN global
9. Débogage et troubleshooting
Section titled â9. DĂ©bogage et troubleshootingâ9.1. ProblĂšmes courants
Section titled â9.1. ProblĂšmes courantsâ| SymptĂŽme | Cause probable | Solution |
|---|---|---|
| Token invalide | Token expiré | Régénérer le token |
| Upload échoue | Format non supporté | Vérifier le format |
9.2. Commandes de debug
Section titled â9.2. Commandes de debugâ# Lister les vidĂ©oswrangler stream list10. Bonnes pratiques
Section titled â10. Bonnes pratiquesâ10.1. Architecture
Section titled â10.1. Architectureâ- â Utiliser le Direct Upload Token
- â Stocker lâUID dans Sanity
- â Utiliser le player iframe ou SDK
10.2. Maintenance
Section titled â10.2. Maintenanceâ- â Surveiller lâutilisation
- â Nettoyer les vidĂ©os obsolĂštes
11. Ăvolutions et roadmap
Section titled â11. Ăvolutions et roadmapâ11.1. AmĂ©liorations planifiĂ©es
Section titled â11.1. AmĂ©liorations planifiĂ©esâ- [Ăvolution 1]
- [Ăvolution 2]
11.2. Limitations connues
Section titled â11.2. Limitations connuesâ- â [Limitation 1]
- â [Limitation 2]
12. Ressources liées
Section titled â12. Ressources liĂ©esâ- Documentation Cloudflare : Stream
13. Historique des modifications
Section titled â13. Historique des modificationsâ| Date | Version | Description | Auteur |
|---|---|---|---|
| YYYY-MM-DD | 1.0 | Création initiale | [Nom] |