a fun bot for the hc slack
at v0.0.1 1.8 kB view raw
1import { db } from "../libs/db"; 2import { takes as takesTable } from "../libs/schema"; 3import { eq, and } from "drizzle-orm"; 4 5export async function getVideo(url: URL): Promise<Response> { 6 const videoId = url.pathname.split("/")[2]; 7 8 if (!videoId) { 9 return new Response("Invalid video id", { status: 400 }); 10 } 11 12 const video = await db 13 .select() 14 .from(takesTable) 15 .where(eq(takesTable.id, videoId)); 16 17 if (video.length === 0) { 18 return new Response("Video not found", { status: 404 }); 19 } 20 21 const videoData = video[0]; 22 23 return new Response( 24 `<!DOCTYPE html> 25 <html> 26 <head> 27 <title>Video Player</title> 28 <style> 29 body, html { 30 margin: 0; 31 padding: 0; 32 height: 100vh; 33 overflow: hidden; 34 } 35 .video-container { 36 position: fixed; 37 top: 0; 38 left: 0; 39 width: 100vw; 40 height: 100vh; 41 display: flex; 42 flex-direction: column; 43 justify-content: center; 44 background: linear-gradient(180deg, #000000 25%, #ffffff 50%, #000000 75%); 45 } 46 video { 47 width: 100vw; 48 height: 100vh; 49 object-fit: contain; 50 position: absolute; 51 bottom: 0; 52 } 53 </style> 54 </head> 55 <body> 56 <div class="video-container"> 57 <video autoplay controls> 58 <source src="${videoData?.takeUrl}" type="video/mp4"> 59 Your browser does not support the video tag. 60 </video> 61 </div> 62 </body> 63 </html>`, 64 { 65 headers: { 66 "Content-Type": "text/html", 67 }, 68 }, 69 ); 70}