@gmetrixr/rjson
Version:
(R)ecursive Json
56 lines (55 loc) • 2.43 kB
JavaScript
import { r, rtp, RT, en } from "../../../r";
import { pathUtils } from "@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.record(pJson);
const allPopupElements = projectF.getAllDeepChildrenWithFilter(RT.element, el => el.props.element_type === en.ElementType.popup);
for (const element of allPopupElements) {
const elementF = r.element(element);
const allItems = elementF.getRecords(RT.item);
for (const item of allItems) {
const itemF = r.record(item);
const source = itemF.getValueOrDefault(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 = pathUtils.getFileType(url);
}
const { FileType } = 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(rtp.project.version, 153);
}
}
const migration = new Migration();
export default migration;