content-item.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. if (props.date) {
  13. this.date = new Date(props.date);
  14. }
  15. else {
  16. this.date = new Date();
  17. }
  18. if (props.myTags) {
  19. this.myTagsWithoutAll = props.myTags.filter(x => x !== 'all');
  20. }
  21. else {
  22. this.myTagsWithoutAll = [];
  23. }
  24. if (props.price != null && !isNaN(Number(props.price))) {
  25. this.price = Number(props.price);
  26. this.priceFormatted = this.formatCents(this.price);
  27. }
  28. this.allLinks = props.links || [];
  29. this.userLinks = this.allLinks.filter(x => !x.rel.startsWith('.'));
  30. this.systemLinks = this.allLinks.filter(x => x.rel.startsWith('.'));
  31. this.fromTarget = this.allLinks.filter(x => x.rel === '.from').map(x => x.target)[0];
  32. this.toTarget = this.allLinks.filter(x => x.rel === '.to').map(x => x.target)[0];
  33. this.fromContactId = this.allLinks.filter(x => x.rel === '.from-contact-id').map(x => x.target)[0];
  34. this.toContactId = this.allLinks.filter(x => x.rel === '.to-contact-id').map(x => x.target)[0];
  35. this.media = this.allLinks.filter(x => x.rel === '.media').map(x => x.target)[0];
  36. this.relTarget = this.allLinks.reduce((accum, link) => {
  37. accum[link.rel] = link.target;
  38. return accum;
  39. }, {});
  40. if (this.fromTarget && this.toTarget && this.media) {
  41. this.repliable = true;
  42. }
  43. else {
  44. this.repliable = false;
  45. }
  46. }
  47. formatCents(price) {
  48. if (price == null || price === 0) {
  49. return 'free';
  50. }
  51. let dollars = `${price / 100}`;
  52. if (dollars.match(/\..$/)) {
  53. dollars += '0';
  54. }
  55. return '$' + dollars;
  56. }
  57. }
  58. exports.ContentItem = ContentItem;
  59. //# sourceMappingURL=content-item.js.map