Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
55 changes: 28 additions & 27 deletions upload-api/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export const HTTP_TEXTS = {
ZIP_FILE_SAVE: 'Issue While Saving Zip File.',
XML_FILE_SAVE: 'Issue While Saving XML File.',
MAPPER_SAVED: 'Mapping process completed successfull.',
LOCALE_SAVED: 'Source locales stored successfully'
LOCALE_SAVED: 'Source locales stored successfully',
LOCALE_FAILED: 'Unable to create source.',
};

export const HTTP_RESPONSE_HEADERS = {
Expand All @@ -33,46 +34,46 @@ export const HTTP_RESPONSE_HEADERS = {
};

export const MIGRATION_DATA_CONFIG = {
DATA :"cmsMigrationData",
DATA: "cmsMigrationData",

BACKUP_DATA: "migration-data",
BACKUP_LOG_DIR: "logs",
BACKUP_FOLDER_NAME: "import",
BACKUP_FILE_NAME: "success.log",

LOCALE_DIR_NAME : "locale",
LOCALE_FILE_NAME : "locales.json",
LOCALE_MASTER_LOCALE : "master-locale.json",
LOCALE_CF_LANGUAGE : "language.json",
LOCALE_DIR_NAME: "locale",
LOCALE_FILE_NAME: "locales.json",
LOCALE_MASTER_LOCALE: "master-locale.json",
LOCALE_CF_LANGUAGE: "language.json",

WEBHOOKS_DIR_NAME : "webhooks",
WEBHOOKS_FILE_NAME : "webhooks.json",
WEBHOOKS_DIR_NAME: "webhooks",
WEBHOOKS_FILE_NAME: "webhooks.json",

ENVIRONMENTS_DIR_NAME : "environments",
ENVIRONMENTS_FILE_NAME : "environments.json",
ENVIRONMENTS_DIR_NAME: "environments",
ENVIRONMENTS_FILE_NAME: "environments.json",

CONTENT_TYPES_DIR_NAME : "content_types",
CONTENT_TYPES_FILE_NAME : "contenttype.json",
CONTENT_TYPES_MASTER_FILE : "contenttypes.json",
CONTENT_TYPES_SCHEMA_FILE : "schema.json",
CONTENT_TYPES_DIR_NAME: "content_types",
CONTENT_TYPES_FILE_NAME: "contenttype.json",
CONTENT_TYPES_MASTER_FILE: "contenttypes.json",
CONTENT_TYPES_SCHEMA_FILE: "schema.json",

REFERENCES_DIR_NAME : "reference",
REFERENCES_FILE_NAME : "reference.json",
REFERENCES_DIR_NAME: "reference",
REFERENCES_FILE_NAME: "reference.json",

RTE_REFERENCES_DIR_NAME : "rteReference",
RTE_REFERENCES_FILE_NAME : "rteReference.json",
RTE_REFERENCES_DIR_NAME: "rteReference",
RTE_REFERENCES_FILE_NAME: "rteReference.json",

ASSETS_DIR_NAME : "assets",
ASSETS_FILE_NAME : "assets.json",
ASSETS_SCHEMA_FILE : "index.json",
ASSETS_FAILED_FILE : "cs_failed.json",
ASSETS_METADATA_FILE :"metadata.json",
ASSETS_DIR_NAME: "assets",
ASSETS_FILE_NAME: "assets.json",
ASSETS_SCHEMA_FILE: "index.json",
ASSETS_FAILED_FILE: "cs_failed.json",
ASSETS_METADATA_FILE: "metadata.json",

ENTRIES_DIR_NAME : "entries",
ENTRIES_MASTER_FILE : "index.json",
ENTRIES_DIR_NAME: "entries",
ENTRIES_MASTER_FILE: "index.json",

GLOBAL_FIELDS_DIR_NAME : "global_fields",
GLOBAL_FIELDS_FILE_NAME : "globalfields.json",
GLOBAL_FIELDS_DIR_NAME: "global_fields",
GLOBAL_FIELDS_FILE_NAME: "globalfields.json",

EXPORT_INFO_FILE: "export-info.json"
}
47 changes: 28 additions & 19 deletions upload-api/src/controllers/sitecore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,39 @@ const {
GLOBAL_FIELDS_FILE_NAME
} = MIGRATION_DATA_CONFIG;

const createLocaleSource = async ({ app_token, localeData, projectId }: { app_token: string | string[], localeData: any, projectId: string | string[] }) => {
const mapperConfig = {
method: 'post',
maxBodyLength: Infinity,
url: `${process.env.NODE_BACKEND_API}/v2/migration/localeMapper/${projectId}`,
headers: {
app_token,
'Content-Type': 'application/json'
},
data: {
locale: Array?.from?.(localeData) ?? []
},
};
const mapRes = await axios?.request?.(mapperConfig);
if (mapRes?.status == 200) {
logger.info('Legacy CMS', {
status: HTTP_CODES?.OK,
message: HTTP_TEXTS?.LOCALE_SAVED,
});
} else {
logger.warn('Legacy CMS error:', {
status: HTTP_CODES?.UNAUTHORIZED,
message: HTTP_TEXTS?.LOCALE_FAILED,
});
}
}

const createSitecoreMapper = async (filePath: string = "", projectId: string | string[], app_token: string | string[], affix: string | string[], config: object) => {
try {
const newPath = path.join(filePath, 'items');
await ExtractFiles(newPath);
const localeData = await extractLocales(path.join(filePath, 'items', 'master', 'sitecore', 'content'));
await createLocaleSource?.({ app_token, localeData, projectId });
await ExtractConfiguration(newPath);
await contentTypes(newPath, affix, config);
const infoMap = await reference();
Expand Down Expand Up @@ -56,25 +84,6 @@ const createSitecoreMapper = async (filePath: string = "", projectId: string | s
status: HTTP_CODES?.OK,
message: HTTP_TEXTS?.MAPPER_SAVED,
});
const mapperConfig = {
method: 'post',
maxBodyLength: Infinity,
url: `${process.env.NODE_BACKEND_API}/v2/migration/localeMapper/${projectId}`,
headers: {
app_token,
'Content-Type': 'application/json'
},
data: {
locale: Array?.from?.(localeData) ?? []
},
};
const mapRes = await axios.request(mapperConfig);
if (mapRes?.status == 200) {
logger.info('Legacy CMS', {
status: HTTP_CODES?.OK,
message: HTTP_TEXTS?.LOCALE_SAVED,
});
}
}
}
} catch (err: any) {
Expand Down
Loading