writeFile.agi 702 B

12345678910111213141516171819202122232425
  1. //Code Studio File writing API
  2. //Required paramters: filepath, content
  3. var success = requirelib("filelib");
  4. if (!success){
  5. sendJSONResp(JSON.stringify({
  6. error: "Unable to access filelib"
  7. }));
  8. }else{
  9. if (typeof filepath == "undefined" || typeof content == "undefined"){
  10. //Missing paramters
  11. sendJSONResp(JSON.stringify({
  12. error: "Invalid filename or contents"
  13. }));
  14. }else{
  15. //OK. Write to target directory
  16. if (filelib.writeFile(filepath, content)){
  17. sendResp("OK");
  18. }else{
  19. sendJSONResp(JSON.stringify({
  20. error: "Unable to write to file: " + filepath
  21. }));
  22. }
  23. }
  24. }