From 880f9bfdab6e2c8fa6d4237a916808d929b4ed73 Mon Sep 17 00:00:00 2001 From: tanish35 Date: Tue, 30 Jul 2024 09:08:54 +0530 Subject: [PATCH] put .json instead of .txt for email domains --- backend/src/mail/checkAcademic.ts | 10 +++++----- backend/src/mail/emails.json | 6 ++++++ backend/src/mail/emails.txt | 4 ---- 3 files changed, 11 insertions(+), 9 deletions(-) create mode 100644 backend/src/mail/emails.json delete mode 100644 backend/src/mail/emails.txt diff --git a/backend/src/mail/checkAcademic.ts b/backend/src/mail/checkAcademic.ts index f48c53e..42068c5 100644 --- a/backend/src/mail/checkAcademic.ts +++ b/backend/src/mail/checkAcademic.ts @@ -1,13 +1,13 @@ import fs from 'fs'; import path from 'path'; +// Get the directory name of the current module +const __dirname = path.resolve(); // CommonJS way to get the directory path + // Function to check if an email has a valid college domain function checkCollegeEmail(email: string): boolean { - // Get the directory name of the current module - const __dirname = path.resolve(); // CommonJS way to get the directory path - - const filePath = path.join(__dirname, '/src/mail/emails.txt'); - const domains = fs.readFileSync(filePath, 'utf8').split('\n').map(domain => domain.trim()); + const filePath = path.join(__dirname, 'emails.json'); + const domains = JSON.parse(fs.readFileSync(filePath, 'utf8')); // Extract the domain from the email const emailDomain = email.split('@')[1]; diff --git a/backend/src/mail/emails.json b/backend/src/mail/emails.json new file mode 100644 index 0000000..a1fc90b --- /dev/null +++ b/backend/src/mail/emails.json @@ -0,0 +1,6 @@ +[ + "aec.edu", + "jadavpuruniversity.in", + "anothercollege.edu" +] + \ No newline at end of file diff --git a/backend/src/mail/emails.txt b/backend/src/mail/emails.txt deleted file mode 100644 index 118dd71..0000000 --- a/backend/src/mail/emails.txt +++ /dev/null @@ -1,4 +0,0 @@ -aec.edu -jadavpuruniversity.in -examplecollege.edu -anothercollege.org