@gmetrixr/rjson
Version:
(R)ecursive Json
58 lines (57 loc) • 2.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const r_1 = require("../../../r");
const gdash_1 = require("@gmetrixr/gdash");
/**
* Rerun pop items migration. This is being done as the migration rjson scheme has changed.
* new scheme
* 1. Apply initial migrations
* 2. inject file sources
* 3. run normal migrations - Few migrations require file sources to be injected
*/
class Migration {
execute(projectJson) {
var _a, _b, _c;
const pJson = projectJson;
const projectF = r_1.r.record(pJson);
const allPopupElements = projectF.getAllDeepChildrenWithFilter(r_1.RT.element, el => el.props.element_type === r_1.en.ElementType.popup);
for (const element of allPopupElements) {
const elementF = r_1.r.element(element);
const allItems = elementF.getRecords(r_1.RT.item);
for (const item of allItems) {
const itemF = r_1.r.record(item);
const source = itemF.getValueOrDefault(r_1.rtp.item.item_source);
let sourceType = source.type;
//* Only in case of JSON corruption could this scenario occur
if (!sourceType) {
// get the file type from the file_urls
const url = ((_a = source.file_urls) === null || _a === void 0 ? void 0 : _a.glb) || ((_b = source.file_urls) === null || _b === void 0 ? void 0 : _b.gltf) || ((_c = source.file_urls) === null || _c === void 0 ? void 0 : _c.o) || "";
sourceType = gdash_1.pathUtils.getFileType(url);
}
const { FileType } = gdash_1.pathUtils;
switch (sourceType) {
case FileType.IMAGE: {
item.props.item_source_type = "image";
break;
}
case FileType.VIDEO: {
item.props.item_source_type = "video";
break;
}
case FileType.AUDIO: {
item.props.item_source_type = "audio";
break;
}
case FileType.THREED:
case FileType.COMPRESSED: {
item.props.item_source_type = "3d_model";
break;
}
}
}
}
projectF.set(r_1.rtp.project.version, 153);
}
}
const migration = new Migration();
exports.default = migration;