-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
64 changed files
with
4,152 additions
and
1,962 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,12 @@ | |
"backdrop-filter" | ||
] | ||
} | ||
], | ||
"axe/name-role-value": [ | ||
"default", | ||
{ | ||
"link-name": "off" | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"liveServer.settings.port": 5501 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import BlogPost from '../models/addBlog.js'; | ||
import multer from 'multer'; | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
|
||
// Configure multer for file uploads | ||
const storage = multer.diskStorage({ | ||
destination: (req, file, cb) => { | ||
cb(null, 'uploads/'); // Ensure this directory exists | ||
}, | ||
filename: (req, file, cb) => { | ||
// Set the file name to be unique | ||
const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9); | ||
cb(null, uniqueSuffix + path.extname(file.originalname)); // Preserve the original file extension | ||
} | ||
}); | ||
|
||
const upload = multer({ storage: storage }); | ||
|
||
// Function to save a new blog post | ||
export async function saveBlog(req, res) { | ||
try { | ||
const { title, category, summary, excerpt, tags, publish, featuredImage } = req.body; | ||
|
||
// If an image is uploaded, use its path | ||
let imagePath = req.file ? req.file.path : null; | ||
|
||
// Handle base64 image if provided | ||
if (featuredImage && featuredImage.startsWith('data:image/')) { | ||
// Extract the base64 part of the image data | ||
const base64Image = featuredImage.split(';base64,').pop(); | ||
// Convert base64 string to Buffer | ||
const buffer = Buffer.from(base64Image, 'base64'); | ||
|
||
// Create a path to save the image | ||
const imagePathFromBase64 = `uploads/${Date.now()}.png`; // Use a unique name based on timestamp | ||
|
||
// Save the image buffer to a file | ||
await fs.promises.writeFile(imagePathFromBase64, buffer); | ||
imagePath = imagePathFromBase64; // Set imagePath to the saved file path | ||
} | ||
|
||
// Log request body and file info | ||
|
||
|
||
// Check if required fields are provided | ||
if (!title || !category || !summary || !excerpt) { | ||
return res.status(400).json({ message: "All required fields must be filled out." }); | ||
} | ||
|
||
// Create a new blog document | ||
const newBlog = new BlogPost({ | ||
title, | ||
category, | ||
summary, | ||
excerpt, | ||
tags, | ||
publish, | ||
featuredImage: imagePath // Use the determined image path | ||
}); | ||
|
||
console.log(newBlog); | ||
|
||
// Save the blog post to the database | ||
await newBlog.save(); | ||
|
||
// Respond with success message | ||
res.status(201).json({ | ||
message: "Blog post created successfully!", | ||
data: newBlog | ||
}); | ||
} catch (error) { | ||
console.error("Error saving blog post:", error); | ||
res.status(500).json({ message: "Failed to create blog post.", error }); | ||
} | ||
} | ||
|
||
|
||
// Function to retrieve all blog posts | ||
export async function getAllBlog(req, res) { | ||
try { | ||
const blogs = await BlogPost.find(); // Retrieve all blog posts | ||
res.status(200).json(blogs); // Respond with the list of blog posts | ||
} catch (error) { | ||
console.error("Error retrieving blog posts:", error); | ||
res.status(500).json({ message: "Failed to retrieve blog posts.", error }); | ||
} | ||
} | ||
|
||
// Function to retrieve a specific blog post by ID | ||
export async function getBlog(req, res) { | ||
try { | ||
const { id } = req.params; | ||
|
||
// Retrieve the specific blog post by ID | ||
const blog = await BlogPost.findById(id); | ||
if (!blog) { | ||
return res.status(404).json({ message: "Blog post not found." }); | ||
} | ||
return res.status(200).json(blog); | ||
} catch (error) { | ||
console.error("Error retrieving blog post:", error); | ||
res.status(500).json({ message: "Failed to retrieve blog post.", error }); | ||
} | ||
} | ||
|
||
export { upload }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import Feedback from "../models/feedback.js"; | ||
|
||
// Controller to handle feedback submission | ||
export async function submitFeedback(req, res) { // Changed resp to res | ||
console.log('feedback form getting submit') | ||
try { | ||
// Extract feedback data from the request body | ||
const { | ||
overallExperience, | ||
featuresUsed, | ||
mostHelpfulFeature, | ||
improvement, | ||
newFeatures, | ||
recommendation, | ||
additionalComments | ||
} = req.body; | ||
|
||
// Validate required fields | ||
if (!overallExperience || !featuresUsed || !mostHelpfulFeature || !recommendation) { | ||
return res.status(400).json({ message: 'Please provide all required fields.' }); | ||
} | ||
|
||
// Create a new Feedback instance with the extracted data | ||
const feedback = new Feedback({ | ||
overallExperience, | ||
featuresUsed, | ||
mostHelpfulFeature, | ||
improvement, | ||
newFeatures, | ||
recommendation, | ||
additionalComments | ||
}); | ||
|
||
// Save the feedback data to MongoDB | ||
await feedback.save(); | ||
|
||
// Respond with a success message | ||
res.status(201).json({ message: 'Feedback submitted successfully', feedback }); | ||
} catch (error) { | ||
// Handle errors and send a failure response | ||
console.error('Error saving feedback:', error); | ||
res.status(500).json({ message: 'Failed to submit feedback', error: error.message }); | ||
} | ||
} | ||
|
||
|
||
export async function getFeed(req, res) { | ||
res.send("feedback form") | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Import the GetInTouch model | ||
import GetInTouch from '../models/getInTouch.js'; | ||
|
||
// Controller function to handle form submission | ||
export const submitGetInTouch = async (req, res) => { | ||
try { | ||
// Create a new GetInTouch document using request data | ||
const { name, email, message } = req.body; | ||
|
||
// Validate request data | ||
if (!name || !email || !message) { | ||
return res.status(400).json({ error: 'All fields are required.' }); | ||
} | ||
|
||
const newMessage = new GetInTouch({ | ||
name, | ||
email, | ||
message, | ||
}); | ||
|
||
// Save the new document to the database | ||
await newMessage.save(); | ||
|
||
// Send a success response | ||
res.status(201).json({ message: 'Thank you! Your message has been received.' }); | ||
} catch (error) { | ||
// Handle errors | ||
console.error('Error submitting message:', error); | ||
res.status(500).json({ error: 'There was an error submitting your message. Please try again.' }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import mongoose from "mongoose"; | ||
|
||
const blogPostSchema = new mongoose.Schema({ | ||
title: { | ||
type: String, | ||
required: true, | ||
trim: true | ||
}, | ||
category: { | ||
type: String, | ||
required: true, | ||
enum: ['vocabulary', 'grammar', 'pronunciation', 'culture', 'learning-tips'] // Add more categories as needed | ||
}, | ||
summary: { | ||
type: String, | ||
required: true, | ||
trim: true | ||
}, | ||
excerpt: { | ||
type: String, | ||
required: true, | ||
trim: true | ||
}, | ||
tags: { | ||
type: [String], | ||
default: [] | ||
}, | ||
publish: { | ||
type: Boolean, | ||
default: false | ||
}, | ||
featuredImage: { | ||
type: String, | ||
default: null | ||
}, | ||
createdAt: { | ||
type: Date, | ||
default: Date.now | ||
}, | ||
updatedAt: { | ||
type: Date, | ||
default: Date.now | ||
} | ||
}); | ||
|
||
// Add a pre-save hook to update the `updatedAt` field | ||
blogPostSchema.pre('save', function (next) { | ||
this.updatedAt = Date.now(); | ||
next(); | ||
}); | ||
|
||
const BlogPost = mongoose.model('BlogPost', blogPostSchema); | ||
|
||
export default BlogPost; |
Oops, something went wrong.