libraryManager.js 986 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. const CONFIG = require('./config.js');
  2. const Library = require('./library.js').Library;
  3. const Path = require('path');
  4. function LibraryManager() {
  5. this.libraries = [];
  6. this.updating = false;
  7. for (let i of CONFIG.photoLibraries)
  8. this.push(i);
  9. }
  10. LibraryManager.prototype.push = function(path) {
  11. this.libraries.push(new Library(path));
  12. }
  13. LibraryManager.prototype.updateLibraries = async function(dbHelper) {
  14. if (this.updating)
  15. return;
  16. this.updating = true;
  17. await Promise.allSettled(this.libraries.map(i => i.updateLibrary(dbHelper)));
  18. this.updating = false;
  19. }
  20. LibraryManager.prototype.isUpdating = function()
  21. { return this.updating; }
  22. LibraryManager.prototype.findMedia = async function(path) {
  23. path = Path.normalize(path);
  24. for (let i of this.libraries) {
  25. let media = await i.findMedia(path);
  26. if (media)
  27. return media;
  28. }
  29. return null;
  30. }
  31. module.exports.LibraryManager = new LibraryManager();