filesaver.agi 695 B

123456789101112131415161718192021222324252627282930
  1. /*
  2. Text - FileSaver backend
  3. Writes the editor content to a file on the server.
  4. Required POST parameters:
  5. filepath - virtual path to the target file
  6. content - text content to write
  7. */
  8. function main(){
  9. if (!requirelib("filelib")){
  10. sendJSONResp(JSON.stringify({ error: "filelib unavailable" }));
  11. return;
  12. }
  13. if (!filepath || filepath.trim() === ""){
  14. sendJSONResp(JSON.stringify({ error: "filepath is required" }));
  15. return;
  16. }
  17. var ok = filelib.writeFile(filepath, content);
  18. if (!ok){
  19. sendJSONResp(JSON.stringify({ error: "unable to write file" }));
  20. return;
  21. }
  22. sendResp("OK");
  23. }
  24. main();