filesaver.js 604 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. FileSaver.js
  3. Author: tobychui
  4. This file save the notebook files to server side
  5. Required POST paramters:
  6. filepath
  7. content
  8. */
  9. function error(message){
  10. sendJSONResp(JSON.stringify({
  11. "error": message
  12. }));
  13. }
  14. function main(){
  15. //Require libraries
  16. if (!requirelib("filelib")){
  17. error("Unable to request filelib");
  18. return
  19. }
  20. //Write to the file
  21. var succ = filelib.writeFile(filepath, content);
  22. if (!succ){
  23. error("Unable to save file");
  24. return
  25. }else{
  26. sendResp("OK");
  27. return
  28. }
  29. }
  30. main();