a fun bot for the hc slack
at v0.2.0 1.7 kB view raw
1import { handleApiError } from "../../../libs/apiError"; 2 3export default async function getVideo(url: URL): Promise<Response> { 4 try { 5 const params = new URLSearchParams(url.search); 6 const mediaSource = params.get("media"); 7 8 if (!mediaSource) { 9 return new Response( 10 JSON.stringify({ error: "No media source provided" }), 11 { 12 status: 400, 13 headers: { "Content-Type": "application/json" }, 14 }, 15 ); 16 } 17 18 return new Response( 19 `<!DOCTYPE html> 20 <html> 21 <head> 22 <title>Video Player</title> 23 <style> 24 body, html { 25 margin: 0; 26 padding: 0; 27 height: 100vh; 28 overflow: hidden; 29 } 30 .video-container { 31 position: fixed; 32 top: 0; 33 left: 0; 34 width: 100vw; 35 height: 100vh; 36 display: flex; 37 flex-direction: column; 38 justify-content: center; 39 background: linear-gradient(180deg, #000000 25%, #ffffff 50%, #000000 75%); 40 } 41 video { 42 width: 100vw; 43 height: 100vh; 44 object-fit: contain; 45 position: absolute; 46 bottom: 0; 47 } 48 </style> 49 </head> 50 <body> 51 <div class="video-container"> 52 <video autoplay controls> 53 <source src="${mediaSource}" type="video/mp4"> 54 Your browser does not support the video tag. 55 </video> 56 </div> 57 </body> 58 </html>`, 59 { 60 headers: { 61 "Content-Type": "text/html", 62 }, 63 }, 64 ); 65 } catch (error) { 66 return handleApiError(error, "getVideo"); 67 } 68}