 fs = require 'fs'
 path = require 'path'
 q = require 'q'
-
+auth = require 'http-auth'
+secret = require '/home/sacha/.secret.js'
+
+basic = auth.basic({realm: "Sketches"}, (username, password, callback) ->
+  callback(username == secret.auth.user && password == secret.auth.password)
+)
 ################################################################################
 # Utility functions
 getSketches = (dir) ->


express = require 'express'
app = express()
app.get '/random', serveRandomImage
app.get '/id/:id', serveImageByID
app.get '/image/:filename', serveImageByName

  getSketches(SKETCH_DIR).then (sketches) ->
    q(getSketchesByTags(sketches, tag)).then (list) ->
      res.send header + formatList(list) + footer

showSketchesByRange = (req, res) ->
  start = req.query.start
  end = req.query.end
  getSketches(SKETCH_DIR).then (sketches) ->
    inRange = sketches.filter (x) ->
      return x >= start && (!end || x <= end)
    res.send header + formatList(inRange) + footer

serveImagesByDate = (req, res) ->
  getSketches(SKETCH_DIR).then (sketches) ->
