Skip to content

Commit

Permalink
* Implemented /:room/edit endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
audreyt committed Apr 20, 2012
1 parent b367f76 commit d1247bb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
<script src="/zappa/zappa.js"></script>
<script src="/player.js"></script>

<link rel="stylesheet" type="text/css" href="static/socialcalc.css">
<link rel="stylesheet" type="text/css" href="static/index.css">
<link rel="stylesheet" type="text/css" href="/static/socialcalc.css">
<link rel="stylesheet" type="text/css" href="/static/index.css">
<style>
body
{font-family:verdana,helvetica,sans-serif;font-size:small;}
.testclass {border:2px dotted red;}
.testclass2 {background-image:url(images/sc-logo.gif);}
.testclass2 {background-image:url(/images/sc-logo.gif);}
.smaller {font-size:smaller;}
.hide {display:none;}
</style>
Expand Down
22 changes: 18 additions & 4 deletions main.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@include = ->
# console.log @KEY
@enable 'serve jquery'
@use 'bodyParser', @app.router, @express.static __dirname
@include 'dotcloud'
Expand All @@ -13,11 +12,21 @@
@response.contentType 'text/html'
@response.sendfile "#{RealBin}/#{file}"

KEY = @KEY
hmac = if !KEY then (x) -> (x) else (x) ->
encoder = require('crypto').createHmac('sha256', KEY)
encoder.update x.toString()
encoder.digest('hex')

@get '/': sendFile "index.html"
@get '/_new': -> @response.redirect '/' + require("uuid-pure").newId(10, 36).toLowerCase()
@get '/_new': ->
room = require("uuid-pure").newId(10, 36).toLowerCase()
@response.redirect if KEY then "/#{ room }/edit" else "/#{ room }"
@get '/_start': sendFile "start.html"
@get '/:room': sendFile "index.html"

@get '/:room/edit': ->
room = @params.room
@response.redirect "/#{ room }?auth=#{ hmac(room) }"
@get '/_/:room': ->
SC._get @params.room, null, ({ log, snapshot }) =>
@response.send '', { 'Content-Type': 'text/plain' }, 404 unless snapshot
Expand All @@ -36,7 +45,7 @@
@response.send 'OK', { 'Content-Type': 'text/plain' }, 201

@on data: ->
{room, msg, user, ecell, cmdstr, type} = @data
{room, msg, user, ecell, cmdstr, type, auth} = @data
room = room.replace(/^_+/, '') # preceding underscore is reserved
reply = (data) => @emit { data }
broadcast = (data) =>
Expand All @@ -54,6 +63,7 @@
when 'my.ecell'
DB.hset "ecell-#{room}", user, ecell
when 'execute'
return if KEY and hmac(room) isnt auth
DB.multi()
.rpush("log-#{room}", cmdstr)
.bgsave().exec =>
Expand All @@ -74,11 +84,15 @@
SC._get room, @io, ({ log, snapshot }) =>
reply { type: 'recalc', room, log, snapshot }
when 'stopHuddle'
return if @KEY and KEY isnt @KEY
DB.del [
"log-#{room}"
"chat-#{room}"
"ecell-#{room}"
"snapshot-#{room}"
], => delete SC[room]; broadcast @data
when 'ecell'
return if KEY and hmac(room) isnt auth
broadcast @data
else broadcast @data
return
23 changes: 14 additions & 9 deletions player.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
SocialCalc._username = Math.random().toString()
SocialCalc.isConnected = true
SocialCalc.hadSnapshot = false
SocialCalc._auth = window.location.search?.replace(/\??auth=/, '')
SocialCalc._room ?= window.location.hash.replace('#', '')
SocialCalc._room = SocialCalc._room.replace(/^_+/, '')
SocialCalc._room = SocialCalc._room.replace(/^_+/, '').replace(/\?.*/, '')
unless SocialCalc._room
window.location = '/_start'
return

try window.history.pushState {}, '', '/'+SocialCalc._room
try window.history.pushState {}, '', "/#{
SocialCalc._room
}" + if SocialCalc._auth then "/edit" else ""
@connect()

emit = (data) => @emit { data }
Expand All @@ -19,6 +22,7 @@
data.user = SocialCalc._username
data.room = SocialCalc._room
data.type = type
data.auth = SocialCalc._auth if SocialCalc._auth
emit data

SocialCalc.isConnected = true
Expand Down Expand Up @@ -106,13 +110,13 @@
SocialCalc.CurrentSpreadsheetControlObject.context.sheetobj.ScheduleSheetCommands @data.cmdstr, @data.saveundo, true
return

window.doresize = -> spreadsheet.DoOnResize()
window.doresize = -> window.spreadsheet?.DoOnResize()
scc = SocialCalc.Constants
b1 = window.location.search.charAt(1) or "4"
b2 = window.location.search.charAt(2) or "C"
b3 = window.location.search.charAt(3) or "8"
b4 = window.location.search.charAt(4) or "9"
b5 = window.location.search.charAt(5) or "8"
b1 = if window.location.search then 'A' else '4'
b2 = 'C'
b3 = '8'
b4 = '9'
b5 = '8'
scc.SCToolbarbackground = "background-color:#4040" + b1 + "0;"
scc.SCTabbackground = "background-color:#CC" + b2 + ";"
scc.SCTabselectedCSS = "font-size:small;padding:6px 30px 6px 8px;color:#FFF;background-color:#4040" + b1 + "0;cursor:default;border-right:1px solid #CC" + b2 + ";"
Expand All @@ -122,9 +126,10 @@
scc.ISCButtonBorderHover = "#99" + b4 + ""
scc.ISCButtonBorderDown = "#FFF"
scc.ISCButtonDownBackground = "#88" + b5 + ""
scc.defaultImagePrefix = "/images/sc-"
SocialCalc.Popup.LocalizeString = SocialCalc.LocalizeString
$ ->
spreadsheet = new SocialCalc.SpreadsheetControl()
window.spreadsheet = spreadsheet = new SocialCalc.SpreadsheetControl()
document.getElementById("msgtext").value = ""
savestr = document.getElementById("savestr")
spreadsheet.InitializeSpreadsheetControl "tableeditor", 0, 0, 0
Expand Down

0 comments on commit d1247bb

Please sign in to comment.