10 Descriptive message about your chansssges

This commit is contained in:
yznahmad 2025-08-09 18:14:39 +03:00
parent 1a9336608d
commit 20505fc6e2
4 changed files with 51 additions and 5 deletions

View File

@ -53,8 +53,29 @@ export async function PUT(req:Request)
phone : string | null = payload.phone as string | null, phone : string | null = payload.phone as string | null,
address : string | null = payload.address as string | null, address : string | null = payload.address as string | null,
showLogo : boolean | null = payload.showLogo as boolean | null, showLogo : boolean | null = payload.showLogo as boolean | null,
logo : string | null = payload.logo as string | null,
currencySymbol : string | null = payload.currencySymbol as string | null; currencySymbol : string | null = payload.currencySymbol as string | null;
let logo : string | null = payload.logo as string | null;
// Validate logo if provided
if (logo && typeof logo === 'string') {
// Check if it's a valid SVG
if (!logo.includes('<svg') || !logo.includes('</svg>')) {
return NextResponse.json({
success: false,
message: "invalidSVGFile",
}, {
status: 400,
headers: {
"content-type": "application/json"
}
})
}
// Remove any script tags for security
const cleanLogo = logo.replace(/<script[^>]*>.*?<\/script>/gi, '');
// Update the logo variable with cleaned content
logo = cleanLogo;
}
// update the doc // update the doc
let updated_doc = await userModel.updateMany({} , { let updated_doc = await userModel.updateMany({} , {
$set: { $set: {

View File

@ -58,13 +58,32 @@ export default function GeneralSettings()
const handleFileChange = async (event : any , setFieldValue : any) => { const handleFileChange = async (event : any , setFieldValue : any) => {
const file = event.target.files[0]; const file = event.target.files[0];
if (file) { if (file) {
// Validate file type
if (!file.type.includes('svg') && !file.name.toLowerCase().endsWith('.svg')) {
alert(t('onlySVGFilesAllowed') || 'Only SVG files are allowed');
event.target.value = ''; // Clear the input
return;
}
try { try {
// get the file content // get the file content
const content = await readFile(file); const content = await readFile(file) as string;
// Validate SVG content
if (!content.includes('<svg') || !content.includes('</svg>')) {
alert(t('invalidSVGFile') || 'Invalid SVG file format');
event.target.value = ''; // Clear the input
return;
}
// Additional security check - remove any script tags
const cleanContent = content.replace(/<script[^>]*>.*?<\/script>/gi, '');
// set the field value with with new file content // set the field value with with new file content
setFieldValue('logo' , content) setFieldValue('logo' , cleanContent)
} catch (error) { } catch (error) {
console.error('Error reading file:', error); console.error('Error reading file:', error);
alert(t('errorReadingFile') || 'Error reading file');
} }
} }
}; };

View File

@ -364,7 +364,10 @@
"edite": "التعديل", "edite": "التعديل",
"save": "الحفظ", "save": "الحفظ",
"ignore": "تجاهل", "ignore": "تجاهل",
"appNameEN": "اسم التطبيق ( en )" "appNameEN": "اسم التطبيق ( en )",
"onlySVGFilesAllowed": "يُسمح فقط بملفات SVG",
"invalidSVGFile": "تنسيق ملف SVG غير صالح",
"errorReadingFile": "خطأ في قراءة الملف"
}, },
"statistics": { "statistics": {
"totalMembers": "إجمالي الأعضاء", "totalMembers": "إجمالي الأعضاء",

View File

@ -368,7 +368,10 @@
"loading": "Loading", "loading": "Loading",
"edite": "Edite", "edite": "Edite",
"save": "Save", "save": "Save",
"ignore": "Ignore" "ignore": "Ignore",
"onlySVGFilesAllowed": "Only SVG files are allowed",
"invalidSVGFile": "Invalid SVG file format",
"errorReadingFile": "Error reading file"
}, },
"statistics": { "statistics": {
"totalMembers": "Total Members", "totalMembers": "Total Members",