UNPKG

@agility/cli

Version:

Agility CLI for working with your content. (Public Beta)

110 lines 5.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GalleryMapper = void 0; var date_fns_1 = require("date-fns"); var core_1 = require("../../core"); var GalleryMapper = /** @class */ (function () { function GalleryMapper(sourceGuid, targetGuid) { this.sourceGuid = sourceGuid; this.targetGuid = targetGuid; this.directory = 'galleries'; // this will provide access to the /agility-files/{GUID} folder this.fileOps = new core_1.fileOperations(targetGuid); this.mappings = this.loadMapping(); } GalleryMapper.prototype.getGalleryMapping = function (gallery, type) { debugger; var mapping = this.mappings.find(function (m) { return type === 'source' ? m.sourceMediaGroupingID === gallery.mediaGroupingID : m.targetMediaGroupingID === gallery.mediaGroupingID; }); if (!mapping) return null; return mapping; }; GalleryMapper.prototype.getGalleryMappingByMediaGroupingID = function (mediaGroupingID, type) { var mapping = this.mappings.find(function (m) { return type === 'source' ? m.sourceMediaGroupingID === mediaGroupingID : m.targetMediaGroupingID === mediaGroupingID; }); if (!mapping) return null; return mapping; }; GalleryMapper.prototype.getMappedEntity = function (mapping, type) { if (!mapping) return null; var guid = type === 'source' ? mapping.sourceGuid : mapping.targetGuid; var mediaGroupingID = type === 'source' ? mapping.sourceMediaGroupingID : mapping.targetMediaGroupingID; var fileOps = new core_1.fileOperations(guid); var galleriesFiles = fileOps.getFolderContents('galleries'); console.log('galleriesFiles', galleriesFiles); for (var _i = 0, galleriesFiles_1 = galleriesFiles; _i < galleriesFiles_1.length; _i++) { var galleryFile = galleriesFiles_1[_i]; var galleryData = fileOps.readJsonFile("galleries/".concat(galleryFile)); if (galleryData.mediaGroupingID === mediaGroupingID) { return galleryData; } } return null; }; GalleryMapper.prototype.addMapping = function (sourceGallery, targetGallery) { var mapping = this.getGalleryMapping(targetGallery, 'target'); if (mapping) { this.updateMapping(sourceGallery, targetGallery); } else { var newMapping = { sourceGuid: this.sourceGuid, targetGuid: this.targetGuid, sourceMediaGroupingID: sourceGallery.mediaGroupingID, targetMediaGroupingID: targetGallery.mediaGroupingID, sourceModifiedOn: sourceGallery.modifiedOn, targetModifiedOn: targetGallery.modifiedOn, }; this.mappings.push(newMapping); } this.saveMapping(); }; GalleryMapper.prototype.updateMapping = function (sourceGallery, targetGallery) { var mapping = this.getGalleryMapping(targetGallery, 'target'); if (mapping) { mapping.sourceGuid = this.sourceGuid; mapping.targetGuid = this.targetGuid; mapping.sourceMediaGroupingID = sourceGallery.mediaGroupingID; mapping.targetMediaGroupingID = targetGallery.mediaGroupingID; mapping.sourceModifiedOn = sourceGallery.modifiedOn; mapping.targetModifiedOn = targetGallery.modifiedOn; } this.saveMapping(); }; GalleryMapper.prototype.loadMapping = function () { var mapping = this.fileOps.getMappingFile(this.directory, this.sourceGuid, this.targetGuid); return mapping; }; GalleryMapper.prototype.saveMapping = function () { this.fileOps.saveMappingFile(this.mappings, this.directory, this.sourceGuid, this.targetGuid); }; GalleryMapper.prototype.hasSourceChanged = function (sourceGallery) { var mapping = this.getGalleryMapping(sourceGallery, 'source'); if (!mapping) return false; //the date format is: 07/23/2025 08:22PM (MM/DD/YYYY hh:mma) so we need to convert it to a Date object // Note: This assumes the date is in the format MM/DD/YYYY hh:mma // If the date format is different, you may need to adjust the parsing logic accordingly var sourceDate = (0, date_fns_1.parse)(sourceGallery.modifiedOn, "MM/dd/yyyy hh:mma", new Date()); var mappedDate = (0, date_fns_1.parse)(mapping.sourceModifiedOn, "MM/dd/yyyy hh:mma", new Date()); return sourceDate > mappedDate; }; GalleryMapper.prototype.hasTargetChanged = function (targetGallery) { if (!targetGallery) return false; var mapping = this.getGalleryMapping(targetGallery, 'target'); if (!mapping) return false; var targetDate = (0, date_fns_1.parse)(targetGallery.modifiedOn, "MM/dd/yyyy hh:mma", new Date()); var mappedDate = (0, date_fns_1.parse)(mapping.targetModifiedOn, "MM/dd/yyyy hh:mma", new Date()); return targetDate > mappedDate; }; return GalleryMapper; }()); exports.GalleryMapper = GalleryMapper; //# sourceMappingURL=gallery-mapper.js.map