feat(contact-button): add floating contact widget admin management

Add CMS support for floating contact widget with Facebook/Zalo quick
actions. Includes mongoose schema, admin UI tab, image upload with
sharp resize presets, deferred form submission with draft persistence,
and upload middleware error handling.
This commit is contained in:
Tống Thành Đạt
2026-04-07 19:36:20 +07:00
parent e86e5d2c46
commit ffe2f12bb3
12 changed files with 1328 additions and 52 deletions

View File

@@ -36,9 +36,34 @@ const videoGalleryController = require("../controllers/videoGalleryController");
// Dashboard
router.get("/dashboard", ensureAuthenticated, dashboardController.getDashboard);
const runUploadMiddleware = (middleware) => (req, res, next) => {
middleware(req, res, (error) => {
if (!error) {
return next();
}
console.error("Upload middleware error:", error);
const status =
error.code === "LIMIT_FILE_SIZE"
? 413
: error.statusCode || error.status || 400;
return res.status(status).json({
success: false,
error: error.message || "Upload failed",
});
});
};
// Home
router.get("/home", ensureAuthenticated, homeController.index);
router.post("/home/update", ensureAuthenticated, homeController.update);
router.post(
"/home/floating-contact/update",
ensureAuthenticated,
homeController.updateFloatingContact,
);
router.get("/home/api/blogs", ensureAuthenticated, homeController.apiGetBlogs);
// Middleware chuẩn hóa code
@@ -72,13 +97,13 @@ router.get("/upload", ensureAuthenticated, (req, res) => {
router.post(
"/upload/image",
ensureAuthenticated,
upload.single("image"),
runUploadMiddleware(upload.single("image")),
uploadController.uploadImage,
);
router.post(
"/upload/video",
ensureAuthenticated,
uploadVideo.single("video"),
runUploadMiddleware(uploadVideo.single("video")),
uploadController.uploadVideo,
);
router.post(