clearIndex.js 942 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. Movie App - Clear Library Index
  3. Deletes the cached scan result so the next scan starts from scratch.
  4. Only removes the index file — no user media is touched.
  5. Returns JSON: { ok: true, removed: bool } or { error: "..." }
  6. */
  7. includes("common.js");
  8. requirelib("filelib");
  9. var CACHE_FILE = "user:/.appdata/Movie/library_cache.json";
  10. function main() {
  11. if (!filelib.fileExists(CACHE_FILE)) {
  12. // Nothing to remove is a success from the caller's point of view
  13. sendJSONResp(JSON.stringify({ ok: true, removed: false }));
  14. return;
  15. }
  16. try {
  17. filelib.deleteFile(CACHE_FILE);
  18. } catch (e) {
  19. sendJSONResp(JSON.stringify({ error: "delete_failed" }));
  20. return;
  21. }
  22. if (filelib.fileExists(CACHE_FILE)) {
  23. sendJSONResp(JSON.stringify({ error: "delete_failed" }));
  24. return;
  25. }
  26. sendJSONResp(JSON.stringify({ ok: true, removed: true }));
  27. }
  28. main();