Skip to content

Commit

Permalink
import changes , restrict chapter vise , only allow old mp3 with prop…
Browse files Browse the repository at this point in the history
…er mimetype
  • Loading branch information
sijumoncy committed Dec 8, 2023
1 parent 1fa7d82 commit b089637
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 23 deletions.
17 changes: 17 additions & 0 deletions renderer/src/core/burrito/importBurrito.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,15 @@ export const viewBurrito = async (filePath, currentUser, resource) => {
sb = JSON.stringify(metadata);
}
const success = await validate('metadata', path.join(filePath, 'metadata.json'), sb, metadata.meta.version);
console.log({ metadata });

Check warning on line 99 in renderer/src/core/burrito/importBurrito.js

View workflow job for this annotation

GitHub Actions / Lint Run

Unexpected console statement

Check warning on line 99 in renderer/src/core/burrito/importBurrito.js

View workflow job for this annotation

GitHub Actions / Lint Run

Unexpected console statement
if (success || metadata.type?.flavorType?.flavor?.name === 'audioTranslation') {
result.validate = true;
logger.debug('importBurrito.js', 'Burrito file validated successfully');
result.projectName = metadata.identification?.name?.en;
result.version = metadata.meta.version;
result.burritoType = `${metadata.type?.flavorType?.name} / ${metadata.type?.flavorType?.flavor?.name}`;
result.ingredients = Object.keys(metadata.ingredients).map((key) => key);
result.ingredientsArray = metadata.ingredients;
result.primaryKey = metadata.identification.primary;
result.publicDomain = metadata.copyright?.publicDomain;
result.language = metadata.languages.map((lang) => lang.name.en);
Expand Down Expand Up @@ -331,6 +333,21 @@ const importBurrito = async (filePath, currentUser, updateBurritoVersion, concat
}
metadata.ingredients[key].checksum.md5 = checksum;
metadata.ingredients[key].size = stats.size;
// specific to old .mp3 audio support
// change .mp3 to wav and mimetype to audio/wav (for old mp3 exports)
if (/\.mp3$/.test(key)) {
try {
fs.renameSync(path.join(audioDir, key), path.join(audioDir, key.replace('.mp3', '.wav')));
metadata.ingredients[key].mimeType = 'audio/wav';
const newKey = key.replace('.mp3', '.wav');
metadata.ingredients[newKey] = metadata.ingredients[key];
delete metadata.ingredients[key];
} catch (err) {
logger.debug('importBurrito.js', `import failed - mp3 to wav section : ${err}`);
fs.unlinkSync(path.join(projectDir, `${projectName}_${id}`));
throw new Error('import failed');
}
}
});
})
.catch((err) => logger.error('importBurrito.js', `${err}`));
Expand Down
2 changes: 1 addition & 1 deletion renderer/src/layouts/projects/Export/ExportProjectPopUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { ProgressCircle } from '../../../components/ProgressCircle';
import { exportDefaultAudio, exportFullAudio } from './ExportUtils';
import packageInfo from '../../../../../package.json';

const audioExportFormats = { wav: { ext: 'wav', mimeType: 'audio/wav' }, mp3: { ext: 'mp3', mimeType: 'audio/mp3' } };
const audioExportFormats = { wav: { ext: 'wav', mimeType: 'audio/wav' }, mp3: { ext: 'mp3', mimeType: 'audio/mpeg' } };

export default function ExportProjectPopUp(props) {
const {
Expand Down
75 changes: 53 additions & 22 deletions renderer/src/layouts/projects/ImportProjectPopUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,35 +152,66 @@ export default function ImportProjectPopUp(props) {
logger.debug('importProjectPopUp.js', 'git merge process done');
}

const checksForAudioImport = async (sbData) => {
console.log({sbData});
const ingredientsArr = sbData?.ingredientsArray || []
// check for the importing audio is chapter vise
if(Object.keys(ingredientsArr).length > 0){
Object.entries(ingredientsArr).forEach(([key ,value]) => {
console.log(key ,value)
if(/^ingredients\/.+\/\d+.mp3$/.test(key)) {
// matched ingedients/BookId/1.mp3
throw new Error("Chapter Level audio project is not supported")
}
// new mp3 have mime type as audio/mpeg old is audio/mp3
if(/\.mp3$/.test(key) && value?.mimeType === "audio/mpeg") {
// key - path end with mp3
throw new Error("unable to import mp3 projects")
}
})
}else{
throw new Error("Not found ingredients in metadata")
}
}

const importProject = async () => {
logger.debug('ImportProjectPopUp.js', 'Inside importProject');
if (folderPath) {
setImportProgress((prev)=>({...prev, importStarted:true, completedSteps: prev.completedSteps + 1 }))
setValid(false);
if (sbData.duplicate === true) {
logger.warn('ImportProjectPopUp.js', 'Project already available');
// currently MERGE feature only Enabled for OBS projects
console.log({sbData});
if (sbData?.burritoType === 'gloss / textStories'){
setMerge(true)
try{
logger.debug('ImportProjectPopUp.js', 'Inside importProject');
if (folderPath) {
setImportProgress((prev)=>({...prev, importStarted:true, completedSteps: prev.completedSteps + 1 }))
setValid(false);
// if type is audio
if(sbData?.burritoType === 'scripture / audioTranslation'){
await checksForAudioImport(sbData)
}
if (sbData.duplicate === true) {
logger.warn('ImportProjectPopUp.js', 'Project already available');
// currently MERGE feature only Enabled for OBS projects
if (sbData?.burritoType === 'gloss / textStories'){
setMerge(true)
}
setModel({
openModel: true,
title: t('modal-title-replace-resource'),
confirmMessage: t('dynamic-msg-confirm-replace-resource'),
buttonName: t('btn-replace'),
});
} else {
logger.debug('ImportProjectPopUp.js', 'Its a new project');
checkBurritoVersion();
}
setModel({
openModel: true,
title: t('modal-title-replace-resource'),
confirmMessage: t('dynamic-msg-confirm-replace-resource'),
buttonName: t('btn-replace'),
});
} else {
logger.debug('ImportProjectPopUp.js', 'Its a new project');
checkBurritoVersion();
logger.error('ImportProjectPopUp.js', 'Invalid Path');
setValid(true);
throw new Error(t('dynamic-msg-invalid-path'))
}
} else {
logger.error('ImportProjectPopUp.js', 'Invalid Path');
setValid(true);
} catch(err) {
setNotify('failure');
setSnackText(t('dynamic-msg-invalid-path'));
setSnackText(err?.message || err);
setOpenSnackBar(true);
setImportProgress((prev)=>({...prev, importStarted:false, completedSteps: 0, totalSteps: 4}))
}

};

React.useEffect(() => {
Expand Down

0 comments on commit b089637

Please sign in to comment.