Update comment tags and hashtag payload

This commit is contained in:
LeonspaceX
2026-01-26 17:56:48 +08:00
parent f6d9521f80
commit 929ff68f50
2 changed files with 64 additions and 1 deletions

View File

@@ -250,6 +250,17 @@ export interface PostCommentResponse {
export const postComment = async (commentData: PostCommentRequest): Promise<PostCommentResponse> => {
try {
const identity = await get_id_token();
const hashtopic: string[] = [];
const regex = /#\S+/g;
const matches = commentData.content.match(regex);
if (matches) {
matches.forEach(tag => {
const cleanTag = tag.substring(1);
if (!hashtopic.includes(cleanTag)) {
hashtopic.push(cleanTag);
}
});
}
const response = await fetch('/api/comment', {
method: 'POST',
headers: {
@@ -257,6 +268,7 @@ export const postComment = async (commentData: PostCommentRequest): Promise<Post
},
body: JSON.stringify({
...commentData,
hashtopic,
identity,
}),
});