15-share-notify.agi 845 B

1234567891011121314151617181920212223242526
  1. /*---
  2. title: Share a file and notify
  3. group: Data
  4. summary: Create a share link, schedule a task and send a desktop notification.
  5. ---*/
  6. requirelib("share");
  7. requirelib("scheduler");
  8. requirelib("notification");
  9. var file = "user:/Documents/scores.csv";
  10. var uuid = share.fileIsShared(file) ? share.getFileShareUUID(file) : share.shareFile(file, 0);
  11. console.log("Share id: " + uuid);
  12. // A task the user approves; it runs the script every hour.
  13. var task = "playground-report";
  14. if (!scheduler.registered(task, "Playground")) {
  15. scheduler.register(task, "Playground", 3600, "Rebuild the score report", "main.agi");
  16. }
  17. notification.send("Report shared", "scores.csv is now shared as " + uuid, notification.PRIORITY_MEDIUM);
  18. sendJSONResp({
  19. share: uuid,
  20. link: "/share/" + uuid,
  21. taskRegistered: scheduler.registered(task, "Playground")
  22. });