listPosts.js 968 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. ListPost.js
  3. Author: tobychui
  4. This script list all the post within the system
  5. */
  6. //Require the file library
  7. requirelib("filelib");
  8. //Require the internal library for handling the path of blog posting
  9. includes("config.js");
  10. var blogPostStorage = getBlogPostStore();
  11. function main(){
  12. //Create a directory in user:/Document/ for storing Blog stuffs
  13. if (blogPostStorage == ""){
  14. //The blog post storage is not set. Use default
  15. blogPostStorage = "user:/Document/Blog/Posts/";
  16. }
  17. //Filter out the last / if exists
  18. if (blogPostStorage.substr(blogPostStorage.length - 1, 1) == "/"){
  19. blogPostStorage = blogPostStorage.substr(0, blogPostStorage.length - 1);
  20. }
  21. //If it doesn't exists
  22. filelib.mkdir(blogPostStorage);
  23. //List all the created post
  24. var allPosts = filelib.aglob(blogPostStorage + "/*.json");
  25. //Return the value of the posts
  26. sendJSONResp(JSON.stringify(allPosts));
  27. }
  28. main();