Skip to content

Instantly share code, notes, and snippets.

@anacrolix
Created July 14, 2012 02:13
Show Gist options
  • Save anacrolix/3108837 to your computer and use it in GitHub Desktop.
Save anacrolix/3108837 to your computer and use it in GitHub Desktop.
ew: js, node and the web stack fucking suck
#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
@0x4139
Copy link

0x4139 commented Jan 15, 2016

yep, that's why i switched to go :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment