Created
July 14, 2012 02:13
-
-
Save anacrolix/3108837 to your computer and use it in GitHub Desktop.
ew: js, node and the web stack fucking suck
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#process = require 'process' | |
http = require 'http' | |
url = require 'url' | |
mime = require 'mime' | |
querystring = require 'querystring' | |
path = require 'path' | |
fs = require 'fs' | |
cp = require 'child_process' | |
constants = require 'constants' | |
sendError = (res, err) -> | |
res.writeHead 500 | |
res.end String err | |
http.createServer (req, res) -> | |
pn = querystring.unescape url.parse(req.url).pathname[1..] | |
p = path.join '/media/data/towatch', pn | |
sendFile = -> | |
tc = cp.spawn 'ffmpeg', [ | |
'-threads', '4', | |
'-i', p, | |
'-s', 'qvga', | |
'-f', 'webm', | |
'pipe:',], | |
stdio: ['ignore', 'pipe', process.stderr] | |
res.writeHead 200, | |
'content-type': 'video/webm' | |
tc.stdout.pipe res | |
fs.readdir p, (err, files) -> | |
if err | |
switch err.code | |
when 'ENOTDIR' | |
sendFile() | |
else | |
sendError res, err | |
return | |
res.writeHead 200 | |
for f in files | |
href = querystring.escape path.join(pn, f) | |
res.write "<a href=\"#{href}\">#{f}</a><br/>" | |
res.end() | |
.listen 17022 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
yep, that's why i switched to go :D