mediaItem.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. const DatabaseModel = require("./DatabaseModel.js").DatabaseModel;
  2. function MediaFileModel() {
  3. DatabaseModel.call(this);
  4. this.path = "";
  5. this.md5sum = "";
  6. this.fixedSum = "";
  7. this.date = null;
  8. this.version = 0;
  9. this.updateVersion();
  10. }
  11. MediaFileModel.prototype = Object.create(DatabaseModel.prototype);
  12. MediaFileModel.prototype.getTableName = function() {
  13. return "mediaFile";
  14. }
  15. MediaFileModel.prototype.createOrUpdateBase = async function(dbHelper) {
  16. await dbHelper.runSql(`CREATE TABLE IF NOT EXISTS 'mediaFile' (
  17. path STRING NOT NULL,
  18. md5sum varchar(32) NOT NULL,
  19. fixedSum varchar(32) NOT NULL,
  20. date DateTime NOT NULL,
  21. version integer NOT NULL,
  22. PRIMARY KEY (path, md5sum))`);
  23. }
  24. MediaFileModel.prototype.describe = function() {
  25. return {
  26. "path": this.path,
  27. "md5sum": this.md5sum,
  28. "fixedSum": this.fixedSum,
  29. "date": this.date?.getTime(),
  30. "version": this.version
  31. };
  32. }
  33. MediaFileModel.prototype.versionColumn = function() { return ""; }
  34. MediaFileModel.prototype.fromDb = function(dbObj) {
  35. this.path = dbObj["path"];
  36. this.md5sum = dbObj["md5sum"];
  37. this.fixedSum = dbObj["fixedSum"];
  38. this.date = new Date(dbObj["date"]);
  39. this.version = dbObj["fixedSum"];
  40. }
  41. MediaFileModel.prototype.updateVersion = function() {
  42. this.version = Date.now();
  43. }
  44. module.exports.MediaFileModel = MediaFileModel;