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

Duplicate Name Check for Project Creation #260

Merged
merged 2 commits into from
Nov 27, 2023
Merged
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
30 changes: 23 additions & 7 deletions renderer/src/core/projects/saveProjetcsMeta.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,30 @@ export const saveProjectsMeta = async (projectMetaObj) => {
let checkCanon = false;
const folderList = fs.readdirSync(projectDir);
// handle spaces
projectMetaObj.newProjectFields.projectName = projectMetaObj.newProjectFields.projectName.trim();
// trim the leading spaces
projectMetaObj.newProjectFields.projectName = projectMetaObj.newProjectFields.projectName.trim().replace(/(^_+)?(_+$)?/gm, '');
folderList.forEach((folder) => {
const name = folder.split('_');
if (name[0] === projectMetaObj.newProjectFields.projectName && projectMetaObj.call === 'new') {
projectNameExists = true;
// checking for duplicates
logger.warn('saveProjectsMeta.js', 'Project Name already exists');
status.push({ type: 'warning', value: 'projectname exists, check you archived or projects tab' });
const splittedArr = folder.split('_');
splittedArr.pop();
const name = splittedArr.join('_');
const existingName = name && name.toLowerCase().replace(/\s+/g, '_');
const formatedName = projectMetaObj.newProjectFields.projectName?.toLowerCase().replace(/\s+/g, '_');
if ((formatedName === existingName) && projectMetaObj.call === 'new') {
// read meta and check the flavour is same or not // projectType : Translation, OBS, Audio
const readDuplicateMeta = fs.readFileSync(path.join(projectDir, folder, 'metadata.json'));
const currentduplicateMeta = JSON.parse(readDuplicateMeta);
const duplicatePrjFlavour = currentduplicateMeta?.type?.flavorType?.flavor?.name;
const currentFlavourType = projectMetaObj.projectType;
if (
(currentFlavourType === 'Translation' && duplicatePrjFlavour === 'textTranslation')
|| (currentFlavourType === 'OBS' && duplicatePrjFlavour === 'textStories')
|| (currentFlavourType === 'Audio' && duplicatePrjFlavour === 'audioTranslation')
) {
projectNameExists = true;
// checking for duplicates
logger.warn('saveProjectsMeta.js', 'Project Name already exists');
status.push({ type: 'warning', value: 'projectname exists, check you archived or projects tab. NOTE : Project name is case-insenstive.Space and underscore will treated as same.' });
}
}
});

Expand Down
Loading