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

@@ -22,7 +22,7 @@ export class BlogController {
constructor(
private readonly blogService: BlogService,
private readonly userService: UserService,
) { }
) {}
@Get()
getBlogs() {
@@ -73,7 +73,10 @@ export class BlogController {
/** @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('文章不存在或未公开');
}

View File

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

View File

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