diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..ed99db1 Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..699a302 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +challange3/.env diff --git a/challange1/index.html b/challange1/index.html new file mode 100644 index 0000000..db31faf --- /dev/null +++ b/challange1/index.html @@ -0,0 +1,115 @@ + + +
+ + +Processing your file...
'; +}); diff --git a/challange2/public/style.css b/challange2/public/style.css new file mode 100644 index 0000000..4d15cea --- /dev/null +++ b/challange2/public/style.css @@ -0,0 +1,54 @@ +body { + font-family: Arial, sans-serif; + background-color: #f9f9f9; + margin: 0; + padding: 0; + display: flex; + justify-content: center; + align-items: center; + height: 100vh; +} + +.container { + background: #fff; + padding: 20px; + border-radius: 8px; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); + text-align: center; + max-width: 400px; + width: 100%; +} + +h1 { + margin-bottom: 20px; + color: #333; +} + +label { + display: block; + margin-bottom: 8px; + color: #555; +} + +input[type="file"] { + margin-bottom: 20px; +} + +button { + background: #007bff; + color: #fff; + border: none; + padding: 10px 15px; + border-radius: 5px; + cursor: pointer; + font-size: 16px; +} + +button:hover { + background: #0056b3; +} + +#result { + margin-top: 20px; + color: #666; +} diff --git a/challange2/server.js b/challange2/server.js new file mode 100644 index 0000000..aaeba5b --- /dev/null +++ b/challange2/server.js @@ -0,0 +1,64 @@ +const express = require('express'); +const multer = require('multer'); +const fs = require('fs'); +const path = require('path'); + +const app = express(); +const upload = multer({ dest: 'uploads/' }); +const PORT = 3000; + +app.use(express.static(path.join(__dirname, 'public'))); + +function evaluateExpression(expression) { + try { + const safeExpression = expression.replace(/\^/g, '**'); + return eval(safeExpression); + } catch (error) { + return `Error: Invalid expression`; + } +} + +app.post('/process-file', upload.single('file'), (req, res) => { + const inputFile = req.file.path; + const outputFile = path.join(__dirname, 'uploads', `output-${Date.now()}.txt`); + + const inputData = fs.readFileSync(inputFile, 'utf-8'); + const lines = inputData.split('\n'); + + + const results = lines.map((line) => { + const match = line.match(/^(.*)=\s*(.*)$/); + if (match) { + const expression = match[1].trim(); + const providedResult = match[2].trim(); + + try { + const calculatedResult = evaluateExpression(expression); + if (providedResult) { + return calculatedResult == providedResult + ? `${line.trim()}` + : `${line.trim()} Error: Incorrect result (expected ${calculatedResult})`; + } else { + return `${expression} = ${calculatedResult}`; + } + } catch (error) { + return `${line.trim()} Error: ${error.message}`; + } + } else { + return `${line.trim()} Error: Invalid format`; + } + }); + + + + fs.writeFileSync(outputFile, results.join('\n')); + + res.download(outputFile, 'output.txt', () => { + fs.unlinkSync(inputFile); + fs.unlinkSync(outputFile); + }); +}); + +app.listen(PORT, () => { + console.log(`Server running on http://localhost:${PORT}`); +}); diff --git a/challange3/public/index.html b/challange3/public/index.html new file mode 100644 index 0000000..0502c3c --- /dev/null +++ b/challange3/public/index.html @@ -0,0 +1,85 @@ + + + + + +Fill in your details and upload an image to send an email to hr@ignitershub.com.
+ + + diff --git a/challange3/server.mjs b/challange3/server.mjs new file mode 100644 index 0000000..43b52f3 --- /dev/null +++ b/challange3/server.mjs @@ -0,0 +1,73 @@ +import express from 'express'; +import multer from 'multer'; +import nodemailer from 'nodemailer'; +import path from 'path'; +import dotenv from 'dotenv'; +import fs from 'fs'; + +dotenv.config(); + +const app = express(); +const PORT = 3000; + +app.use(express.static(path.join(process.cwd(), 'public'))); +app.get('/', (req, res) => { + res.sendFile(path.join(process.cwd(), 'public', 'index.html')); +}); + +// Multer setup +const upload = multer({ + dest: 'uploads/', + fileFilter: (req, file, cb) => { + const allowedTypes = ['image/png', 'image/jpg', 'image/jpeg']; + if (!allowedTypes.includes(file.mimetype)) { + return cb(new Error('Only PNG, JPG, and JPEG files are allowed.')); + } + cb(null, true); + }, +}); + +const transporter = nodemailer.createTransport({ + service: 'gmail', + auth: { + user: process.env.EMAIL_USER, + pass: process.env.EMAIL_PASS, + }, +}); + +app.post('/send-email', upload.single('image'), (req, res) => { + const { name, semester, branch, rollNumber } = req.body; + const { file } = req; + + if (!file) { + return res.status(400).send('Image attachment is required.'); + } + + const mailOptions = { + from: process.env.EMAIL_USER, + to: 'hr@ignitershub.com', + subject: 'Challenge 3 Completed', + text: `Hello,\n\nMy name is ${name}, and here are my details:\nSemester: ${semester}\nBranch: ${branch}\nRoll Number: ${rollNumber}\n\nBest regards,\n${name}`, + attachments: [ + { + filename: file.originalname, + path: path.join(process.cwd(), file.path), + }, + ], + }; + + transporter.sendMail(mailOptions, (error, info) => { + fs.unlinkSync(path.join(process.cwd(), file.path)); + + if (error) { + console.error('Error sending email:', error); + alert('An error occurred while sending the email.'); + } + console.log('Email sent:', info.response); + alert('Email sent successfully!'); + }); +}); + +app.listen(PORT, () => { + console.log(`Server running on http://localhost:${PORT}`); +}); diff --git a/challange4/index.html b/challange4/index.html new file mode 100644 index 0000000..79cbcc7 --- /dev/null +++ b/challange4/index.html @@ -0,0 +1,95 @@ + + + + + +Enter a string to check if it's a palindrome:
+ +