content-item.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. class ContentItem {
  4. constructor(hashInPlaylist, hash, props) {
  5. this.data = props;
  6. this.hash = hash;
  7. this.hashInPlaylist = hashInPlaylist;
  8. this.type = props.type;
  9. this.title = props.title;
  10. this.text = props.text;
  11. this.creator = props.creator;
  12. this.file = props.file;
  13. this.thumb = props.thumb;
  14. if (props.date) {
  15. this.date = new Date(props.date);
  16. }
  17. else {
  18. this.date = new Date();
  19. }
  20. if (props.myTags) {
  21. this.myTagsWithoutAll = props.myTags.filter(x => x !== 'all');
  22. }
  23. else {
  24. this.myTagsWithoutAll = [];
  25. }
  26. if (props.price != null && !isNaN(Number(props.price))) {
  27. this.price = Number(props.price);
  28. this.priceFormatted = this.formatCents(this.price);
  29. }
  30. this.allLinks = props.links || [];
  31. this.userLinks = this.allLinks.filter(x => !x.rel.startsWith('.'));
  32. this.systemLinks = this.allLinks.filter(x => x.rel.startsWith('.'));
  33. this.fromTarget = this.allLinks.filter(x => x.rel === '.from').map(x => x.target)[0];
  34. this.toTarget = this.allLinks.filter(x => x.rel === '.to').map(x => x.target)[0];
  35. this.fromContactId = this.allLinks.filter(x => x.rel === '.from-contact-id').map(x => x.target)[0];
  36. this.toContactId = this.allLinks.filter(x => x.rel === '.to-contact-id').map(x => x.target)[0];
  37. this.media = this.allLinks.filter(x => x.rel === '.media').map(x => x.target)[0];
  38. this.relTarget = this.allLinks.reduce((accum, link) => {
  39. accum[link.rel] = link.target;
  40. return accum;
  41. }, {});
  42. if (this.fromTarget && this.toTarget && this.media) {
  43. this.repliable = true;
  44. }
  45. else {
  46. this.repliable = false;
  47. }
  48. }
  49. formatCents(price) {
  50. if (price == null || price === 0) {
  51. return 'free';
  52. }
  53. let dollars = `${price / 100}`;
  54. if (dollars.match(/\..$/)) {
  55. dollars += '0';
  56. }
  57. return '$' + dollars;
  58. }
  59. }
  60. exports.ContentItem = ContentItem;
  61. //# sourceMappingURL=content-item.js.map