update: escape the html tag from announcmetn
This commit is contained in:
@@ -10,6 +10,7 @@ import { SubscriptionPlan } from "../../subscriptions/entities/subscription.enti
|
|||||||
import { UserSubscription } from "../../subscriptions/entities/user-subscription.entity";
|
import { UserSubscription } from "../../subscriptions/entities/user-subscription.entity";
|
||||||
import { User } from "../../users/entities/user.entity";
|
import { User } from "../../users/entities/user.entity";
|
||||||
import { UsersService } from "../../users/providers/users.service";
|
import { UsersService } from "../../users/providers/users.service";
|
||||||
|
import { stripHtmlTags } from "../../utils/providers/string.utils";
|
||||||
import { ANNOUNCEMENT } from "../constants";
|
import { ANNOUNCEMENT } from "../constants";
|
||||||
import { Announcement } from "../entities/announcement.entity";
|
import { Announcement } from "../entities/announcement.entity";
|
||||||
import { UserAnnouncement } from "../entities/user-announcement.entity";
|
import { UserAnnouncement } from "../entities/user-announcement.entity";
|
||||||
@@ -109,7 +110,7 @@ export class AnnouncementProcessor extends WorkerProcessor {
|
|||||||
userPhone: user.phone,
|
userPhone: user.phone,
|
||||||
userEmail: user.email,
|
userEmail: user.email,
|
||||||
title: announcement.title,
|
title: announcement.title,
|
||||||
description: announcement.content,
|
description: stripHtmlTags(announcement.content),
|
||||||
date: announcement.publishAt ?? new Date(),
|
date: announcement.publishAt ?? new Date(),
|
||||||
};
|
};
|
||||||
await this.notificationQueue.addAnnouncementNotification(userId, notifData);
|
await this.notificationQueue.addAnnouncementNotification(userId, notifData);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
export function truncateIfLong(str: string, maxLength = 30): string {
|
export function truncateIfLong(str: string, maxLength = 35): string {
|
||||||
if (typeof str !== "string") return str;
|
if (typeof str !== "string") return str;
|
||||||
return str.length > maxLength ? str.slice(0, maxLength) + "..." : str;
|
return str.length > maxLength ? str.slice(0, maxLength) + "..." : str;
|
||||||
}
|
}
|
||||||
@@ -18,3 +18,18 @@ export function randomizeCase(str: string): string {
|
|||||||
})
|
})
|
||||||
.join("");
|
.join("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function stripHtmlTags(str: string): string {
|
||||||
|
if (typeof str !== "string") return str;
|
||||||
|
|
||||||
|
// Remove HTML tags and decode common HTML entities
|
||||||
|
return str
|
||||||
|
.replace(/<[^>]*>/g, "") // Remove all HTML tags
|
||||||
|
.replace(/ /g, " ") // Replace non-breaking spaces
|
||||||
|
.replace(/&/g, "&") // Replace ampersand entities
|
||||||
|
.replace(/</g, "<") // Replace less than entities
|
||||||
|
.replace(/>/g, ">") // Replace greater than entities
|
||||||
|
.replace(/"/g, '"') // Replace quote entities
|
||||||
|
.replace(/'/g, "'") // Replace apostrophe entities
|
||||||
|
.trim(); // Remove leading/trailing whitespace
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user