app.get('/arthur/videos/:day', async (c) => {
const filePath = `public/videos/arthur/${c.req.param('day')}.mp4`;
const file = Bun.file(filePath);
const stat = await file.stat();
const fileSize = stat.size;
const range = c.req.header('range');
if (range) {
const parts = range.replace(/bytes=/, '').split('-');
const start = parseInt(parts[0], 10);
const end = parts[1] ? parseInt(parts[1], 10) : fileSize - 1;
const chunkSize = end - start + 1;
const sliced = file.slice(start, end + 1);
return new Response(sliced, {
status: 206,
headers: {
'Content-Range': `bytes ${start}-${end}/${fileSize}`,
'Accept-Ranges': 'bytes',
'Content-Length': chunkSize.toString(),
'Content-Type': 'video/mp4',
},
});
} else {
return new Response(file, {
status: 200,
headers: {
'Content-Length': fileSize.toString(),
'Content-Type': 'video/mp4',
'Accept-Ranges': 'bytes',
},
});
}
})