Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/sre3 #54

Merged
merged 4 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 41 additions & 16 deletions lib/util/lookupReplaceAssets.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,29 +59,54 @@ module.exports = function (data, mappedAssetUids, mappedAssetUrls, assetUidMappe
assetUids = _.uniq(assetUids);
assetUrls = _.uniq(assetUrls);
var entry = JSON.stringify(data.entry);
// NOTE: Incase the code breaks use the commented code
// assetUids.forEach(function (assetUid) {
// var uid = mappedAssetUids[assetUid];
// if (typeof uid !== 'undefined') {
// const cp = assetUid.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
// const regexString = `${cp}`;
// entry = entry.replace(new RegExp(regexString, 'img'), uid);
// matchedUids.push(assetUid);
// } else {
// unmatchedUids.push(assetUid);
// }
// });
assetUids.forEach(function (assetUid) {
var uid = mappedAssetUids[assetUid];
if (typeof uid !== 'undefined') {
const cp = assetUid.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
const regexString = `${cp}`;
entry = entry.replace(new RegExp(regexString, 'img'), uid);
matchedUids.push(assetUid);
const escapedAssetUid = assetUid.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
entry = entry.split(escapedAssetUid).join(uid);
matchedUids.push(assetUid);
} else {
unmatchedUids.push(assetUid);
unmatchedUids.push(assetUid);
}
});
});

assetUrls.forEach(function (assetUrl) {
var url = mappedAssetUrls[assetUrl];
if (typeof url !== 'undefined') {
const cp = assetUrl.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
const regexString = `${cp}`;
entry = entry.replace(new RegExp(regexString, 'img'), url);
unmatchedUrls.push(url);
} else {

// NOTE: Incase the code breaks use the commented code
// assetUrls.forEach(function (assetUrl) {
// var url = mappedAssetUrls[assetUrl];
// if (typeof url !== 'undefined') {
// const cp = assetUrl.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
// const regexString = `${cp}`;
// entry = entry.replace(new RegExp(regexString, 'img'), url);
// unmatchedUrls.push(url);
// } else {
// unmatchedUrls.push(assetUrl);
// }
// });
assetUrls.forEach(function (assetUrl) {
var url = mappedAssetUrls[assetUrl];
if (typeof url !== 'undefined') {
const escapedAssetUrl = assetUrl.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
entry = entry.split(escapedAssetUrl).join(url);

matchedUrls.push(assetUrl);
} else {
unmatchedUrls.push(assetUrl);
}
});
}
});


if (matchedUids.length) {
var matchedAssetUids = helper.readFile(path.join(sanitizePath(assetUidMapperPath), 'matched-asset-uids.json'));
Expand Down
15 changes: 13 additions & 2 deletions lib/util/lookupReplaceEntries.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,21 @@ module.exports = function (data, mappedUids, uidMapperPath) {

uids = _.uniq(uids);
var entry = JSON.stringify(data.entry);
// NOTE: Incase the code breaks use the commented code
// uids.forEach(function (uid) {
// if (mappedUids.hasOwnProperty(uid)) {
// entry = entry.replace(new RegExp(uid, "img"), mappedUids[uid]);
// mapped.push(uid);
// } else {
// unmapped.push(uid);
// }
// });
uids.forEach(function (uid) {
if (mappedUids.hasOwnProperty(uid)) {
entry = entry.replace(new RegExp(uid, "img"), mappedUids[uid]);
mapped.push(uid);
const escapedUid = uid.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
entry = entry.split(escapedUid).join(mappedUids[uid]);

mapped.push(uid);
} else {
unmapped.push(uid);
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "contentstack-import",
"version": "1.7.8",
"version": "1.8.0",
"description": "Import data into Contentstack",
"homepage": "https://www.contentstack.com/docs/tools-and-frameworks/content-migration/within-contentstack",
"author": {
Expand Down
Loading