Cloudflare Worker API Documentation

This Cloudflare Worker handles M3U playlist creation and serving. Below are visual workflows for the two main endpoints.

POST /upload-playlist Endpoint

This endpoint accepts a JSON payload with playlist_id and m3u_content, stores it in Cloudflare KV with a 24-hour TTL, and returns the playlist URL.

graph TD A[Client POST /upload-playlist JSON: playlist_id, m3u_content] --> B[Worker validates payload] B --> C[Sanitize Filename: playlist_id] C --> D[Store in PLAYLIST_KV TTL: 86400s] D --> E[Return playlist URL /playlists/sanitized-id] B --> F[Error: Missing fields] F --> E

Flow Description: The client sends a POST request with playlist data. The worker validates the input, sanitizes the ID, stores the content in KV storage with automatic expiration, and returns the access URL.

GET /playlists/{id} Endpoint

This endpoint retrieves and serves M3U playlist content from Cloudflare KV storage with proper MIME type headers.

graph TD A[Client GET /playlists/id] --> B[Worker extracts playlistId] B --> C[sanitizeFilename: playlistId] C --> D(Retrieve from PLAYLIST_KV) D --> E{M3U found?} E -->|Yes| F(Return M3U content\nContent-Type: audio/mpegurl) E -->|No| G(Return 404: Playlist not found)

Flow Description: The client requests a specific playlist by ID. The worker sanitizes the ID, fetches the content from KV storage, and serves it as an M3U file if found.