Skip to content

Commit

Permalink
* Finish Excel XML import/export. Fix #10.
Browse files Browse the repository at this point in the history
    curl -i -X PUT --data-binary @file.xlsx http://HOST/_/ID
    curl -i -X POST --data-binary @file.xlsx http://HOST/_
    curl http://HOST/ID.xlsx
  • Loading branch information
audreyt committed Dec 27, 2014
1 parent 670158d commit 9a58cae
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 28 deletions.
14 changes: 14 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ Takes a SocialCalc serialization format that contains the new spreadsheet's cont
+ Request (text/x-socialcalc)
+ Response 201

## Create from Excel XML [POST]

Takes a Excel XML file that contains the new spreadsheet's content.

+ Request (application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
+ Response 201

# Page [/_/{id}]

## Page Content [GET]
Expand All @@ -75,6 +82,13 @@ Replace the page with a serialization in SocialCalc save format.
+ Request (text/x-socialcalc)
+ Response 200

## Overwrite with Excel XML [PUT]

Replace the page with a serialization in Excel XML format.

+ Request (application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
+ Response 200

## Post Commands [POST]

Takes a JSON structure with a `command` field (either as a string
Expand Down
44 changes: 27 additions & 17 deletions main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 17 additions & 11 deletions src/main.ls
Original file line number Diff line number Diff line change
Expand Up @@ -137,24 +137,30 @@
if request.is \application/json
command = request.body?command
return cb command if command
buf = ''; request.setEncoding \utf8; request.on \data (chunk) ~> buf += chunk
cs = []; request.on \data (chunk) ~> cs ++= chunk
<~ request.on \end
return cb buf unless request.is \text/csv
save <~ SC.csv-to-save buf
save.=replace /\\/g "\\b" if ~save.index-of "\\"
save.=replace /:/g "\\c" if ~save.index-of ":"
save.=replace /\n/g "\\n" if ~save.index-of "\n"
cb "loadclipboard #save"
buf = Buffer.concat cs
return cb buf.toString(\utf8) if request.is \text/x-socialcalc
J = require \j
# TODO: Move to thread
for k, save of (J.utils.to_socialcalc(J.read buf) || {'': ''})
save.=replace /\\/g "\\b" if ~save.index-of "\\"
save.=replace /:/g "\\c" if ~save.index-of ":"
save.=replace /\n/g "\\n" if ~save.index-of "\n"
return cb "loadclipboard #save"

request-to-save = (request, cb) ->
if request.is \application/json
snapshot = request.body?snapshot
return cb snapshot if snapshot
buf = ''; request.setEncoding \utf8; request.on \data (chunk) ~> buf += chunk
cs = []; request.on \data (chunk) ~> cs ++= chunk
<~ request.on \end
return cb buf unless request.is \text/csv
save <~ SC.csv-to-save buf
cb """socialcalc:version:1.0\nMIME-Version: 1.0\nContent-Type: multipart/mixed; boundary=SocialCalcSpreadsheetControlSave\n--SocialCalcSpreadsheetControlSave\nContent-type: text/plain; charset=UTF-8\n\n# SocialCalc Spreadsheet Control Save\nversion:1.0\npart:sheet\npart:edit\npart:audit\n--SocialCalcSpreadsheetControlSave\nContent-type: text/plain; charset=UTF-8\n\n#save\n--SocialCalcSpreadsheetControlSave\nContent-type: text/plain; charset=UTF-8\n\n--SocialCalcSpreadsheetControlSave\nContent-type: text/plain; charset=UTF-8\n\n--SocialCalcSpreadsheetControlSave--\n"""
buf = Buffer.concat cs
return cb buf.toString(\utf8) if request.is \text/x-socialcalc
J = require \j
# TODO: Move to thread
for k, save of (J.utils.to_socialcalc(J.read buf) || {'': ''})
return cb save

@put '/_/:room': ->
@response.type Text
Expand Down

0 comments on commit 9a58cae

Please sign in to comment.