0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-01 06:33:32 +00:00

better error handling for file import

This commit is contained in:
Víctor Losada Hernández
2025-08-20 23:23:13 +02:00
parent 63d957fdc6
commit cca9ebefdb

View File

@@ -5,7 +5,7 @@ const { splitTextStyleAndMetadata } = require('../../../shared/helpers.js'); //
const BREWKEY = 'homebrewery-new'; const BREWKEY = 'homebrewery-new';
const STYLEKEY = 'homebrewery-new-style'; const STYLEKEY = 'homebrewery-new-style';
const METAKEY = 'homebrewery-new-meta'; const METAKEY = 'homebrewery-new-meta';
const NewBrew = ()=>{ const NewBrew = ()=>{
const handleFileChange = (e)=>{ const handleFileChange = (e)=>{
@@ -22,10 +22,26 @@ const NewBrew = ()=>{
splitTextStyleAndMetadata(newBrew); // Modify newBrew directly splitTextStyleAndMetadata(newBrew); // Modify newBrew directly
localStorage.setItem(BREWKEY, newBrew.text); localStorage.setItem(BREWKEY, newBrew.text);
localStorage.setItem(STYLEKEY, newBrew.style); localStorage.setItem(STYLEKEY, newBrew.style);
localStorage.setItem(METAKEY, JSON.stringify(_.pick(newBrew, ['title', 'description', 'tags', 'systems', 'renderer', 'theme', 'lang']))); localStorage.setItem(
METAKEY,
JSON.stringify(
_.pick(newBrew, ['title', 'description', 'tags', 'systems', 'renderer', 'theme', 'lang'])
)
);
window.location.href = '/new'; window.location.href = '/new';
} else { } else {
alert('This file is invalid, please, enter a valid file'); const type = file.name.split('.').pop().toLowercase();
if(type === 'txt') {
alert(
`This file type is correct, but it is not from the homebrewery or has been tampered with,
please try with a correct file or report this as an issue if you think it is a mistake.`
);
} else if(!type) {
alert('This file is invalid, please, enter a valid file');
console.log(file);
} else {
alert(`This is a .${type} file, only '.txt' files are allowed`);
}
} }
}; };
reader.readAsText(file); reader.readAsText(file);