This commit is contained in:
2025-06-23 09:32:25 +08:00
parent 3310bd20e9
commit b5aae0d5b4
3 changed files with 27 additions and 20 deletions

View File

@@ -73,7 +73,10 @@ export class BlogController {
/** @todo 对文章可读性进行更详细的判定 */ /** @todo 对文章可读性进行更详细的判定 */
if (!blog.permissions.includes(BlogPermission.Public) && !blog.permissions.includes(BlogPermission.ByPassword)) { if (
!blog.permissions.includes(BlogPermission.Public) &&
!blog.permissions.includes(BlogPermission.ByPassword)
) {
throw new BadRequestException('文章不存在或未公开'); throw new BadRequestException('文章不存在或未公开');
} }

View File

@@ -104,30 +104,36 @@ export class BlogService {
}, },
}); });
return comments.map(comment => { return comments.map((comment) => {
const { blog, user, ...rest } = comment; const { user, ...rest } = comment;
delete rest.blog;
return { return {
...rest, ...rest,
user: user ? { user: user
? {
userId: user.userId, userId: user.userId,
username: user.username, username: user.username,
nickname: user.nickname, nickname: user.nickname,
} : null,
} }
}) : null,
};
});
} }
async createComment(comment: Partial<BlogComment>) { async createComment(comment: Partial<BlogComment>) {
const newComment = this.blogCommentRepository.create(comment); const newComment = this.blogCommentRepository.create(comment);
const savedComment = await this.blogCommentRepository.save(newComment, {}); const savedComment = await this.blogCommentRepository.save(newComment, {});
const { blog, user, ...commentWithoutBlog } = savedComment; const { user, ...commentWithoutBlog } = savedComment;
delete commentWithoutBlog.blog;
return { return {
...commentWithoutBlog, ...commentWithoutBlog,
user: user ? { user: user
? {
userId: user.userId, userId: user.userId,
username: user.username, username: user.username,
nickname: user.nickname, nickname: user.nickname,
} : null, }
: null,
}; };
} }

View File

@@ -1,6 +1,5 @@
import { useOssSts } from "@/hooks/oss/use-oss-sts"; import { useOssSts } from "@/hooks/oss/use-oss-sts";
import { StsToken } from "@/lib/api/oss"; import { StsToken } from "@/lib/api/oss";
import OSS from "ali-oss";
import { useEffect } from "react"; import { useEffect } from "react";
export function useOssStore(options: { onStsTokenDataChanged?: (data: StsToken | undefined) => void; } = {}) { export function useOssStore(options: { onStsTokenDataChanged?: (data: StsToken | undefined) => void; } = {}) {
@@ -10,7 +9,6 @@ export function useOssStore(options: { onStsTokenDataChanged?: (data: StsToken |
options.onStsTokenDataChanged?.(stsTokenData); options.onStsTokenDataChanged?.(stsTokenData);
}, [stsTokenData]); }, [stsTokenData]);
/** @todo */
const refresh = async () => { const refresh = async () => {
await mutate(); await mutate();
} }