Skip to content

修复 EdgeOne Pages 平台评论删除与点赞状态显示异常#997

Merged
imaegoo merged 2 commits into
twikoojs:mainfrom
jeoor:fix/edgeone-comment-dto
Jun 22, 2026
Merged

修复 EdgeOne Pages 平台评论删除与点赞状态显示异常#997
imaegoo merged 2 commits into
twikoojs:mainfrom
jeoor:fix/edgeone-comment-dto

Conversation

@jeoor

@jeoor jeoor commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

修复 EdgeOne Pages 平台评论删除与点赞状态显示异常

EdgeOne Pages 的 toCommentDto 返回字段与标准实现不一致,缺少 isOwnerupsdownsdisliked 字段。

这会导致:

  • 用户自己的评论无法显示删除按钮;
  • 点赞 / 点踩计数无法正确显示;
  • 点赞 / 点踩状态刷新后无法正确恢复。

实际后端逻辑中,COMMENT_DELETE_FOR_USERCOMMENT_LIKE 均能正常工作;问题仅出在 COMMENT_GET 返回的 DTO 字段不完整。

本次修复:

  • 补充 isOwner 字段,用于前端判断是否显示用户删除按钮;
  • 补充 ups / downs 字段,用于前端显示点赞 / 点踩计数;
  • 补充 disliked 字段,用于前端恢复点踩状态;
  • liked 改为基于 ups.includes(uid) 判断;
  • 保留旧的 like 字段以保持兼容。

Summary by Sourcery

使 EdgeOne Pages 评论 DTO 与标准字段保持一致,以修复删除和点赞/点踩状态显示问题。

Bug 修复:

  • 暴露 isOwner 标志,以便前端能够正确显示用户自己评论的删除按钮。
  • 返回 ups/downs 计数和 disliked 状态,使点赞/点踩的数量和状态在刷新后能够正确保持。

增强:

  • 在保留传统 like 计数以确保向后兼容的同时,将 liked/disliked 标志基于 ups/downs 数组。
  • 收紧针对 EdgeOne Pages 云函数辅助文件和生成产物的 ESLint 忽略规则。
Original summary in English

Summary by Sourcery

Align EdgeOne Pages comment DTO with standard fields to fix deletion and like/dislike state display issues.

Bug Fixes:

  • Expose isOwner flag so the frontend can correctly show the delete button for a user's own comments.
  • Return ups/downs counts and disliked state so like/dislike counts and statuses persist correctly across refreshes.

Enhancements:

  • Base liked/disliked flags on ups/downs arrays while keeping the legacy like count for backward compatibility.
  • Tighten ESLint ignore patterns for EdgeOne Pages cloud function ancillary files and generated artifacts.

@sourcery-ai

sourcery-ai Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor
审阅者指南(在小型 PR 上折叠)

审阅者指南

使 EdgeOne Pages 的评论 DTO 与标准实现保持一致,以确保删除和点赞/点踩状态正常工作,并为特定的 EdgeOne 构件调整 ESLint 忽略路径。

EdgeOne Pages COMMENT_GET 更新后的评论 DTO 时序图

sequenceDiagram
  actor User
  participant Frontend
  participant COMMENT_GET
  participant toCommentDto

  User->>Frontend: request comments
  Frontend->>COMMENT_GET: COMMENT_GET
  COMMENT_GET->>toCommentDto: toCommentDto(comment, uid, replies, comments, cfg)
  toCommentDto-->>COMMENT_GET: dto { liked, disliked, ups, downs, isOwner, like }
  COMMENT_GET-->>Frontend: response with updated dto
  Frontend-->>User: render delete button, like/dislike count and state based on dto
Loading

文件级变更

Change Details Files
将评论 DTO 字段与标准实现对齐,以修复删除和点赞/点踩展示
  • 从 comment.ups/comment.downs 初始化本地 ups/downs 数组,并在缺失时回退为空数组
  • 在 DTO 上暴露 ups/downs 计数,并基于 downs 成员关系添加 disliked 标志位
  • 更改 liked 计算逻辑,从 ups.includes(uid) 推导,而不是使用旧版 like 数组
  • 添加 isOwner 标志位,基于 uid 与 comment.uid 是否匹配
  • 保留旧版 like 计数字段以保证向后兼容,并保留 replies 简写字段
src/server/eo-pages/cloud-functions/index.js
收紧 ESLint 对 EdgeOne Pages 生成文件/外部文件的忽略规则
  • 不再忽略整个 cloud-functions 目录,而是仅忽略特定生成文件或非 JS 文件(ip2region-data.js、smtp.go、.edgeone 构件)
eslint.config.js

提示和命令

与 Sourcery 交互

  • 触发新的审阅: 在 pull request 上评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审阅评论。
  • 根据审阅评论生成 GitHub Issue: 通过回复某条审阅评论,请求 Sourcery 从该评论创建一个 issue。你也可以在审阅评论下回复 @sourcery-ai issue 来从评论创建 issue。
  • 生成 pull request 标题: 在 pull request 标题中任意位置写入 @sourcery-ai,即可随时生成标题。你也可以在 pull request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 pull request 摘要: 在 pull request 正文任意位置写入 @sourcery-ai summary,即可在你想要的位置生成 PR 摘要。你也可以在 pull request 中评论 @sourcery-ai summary 来(重新)生成摘要。
  • 生成审阅者指南: 在 pull request 中评论 @sourcery-ai guide,即可随时(重新)生成审阅者指南。
  • 解决所有 Sourcery 评论: 在 pull request 中评论 @sourcery-ai resolve,以解决所有 Sourcery 评论。当你已经处理完所有评论且不想再看到它们时非常有用。
  • 忽略所有 Sourcery 审阅: 在 pull request 中评论 @sourcery-ai dismiss,以忽略所有现有的 Sourcery 审阅。当你想从头开始一次新的审阅时尤其有用——别忘了再评论 @sourcery-ai review 以触发新的审阅!

自定义你的使用体验

访问你的 控制面板 以:

  • 启用或禁用审阅功能,例如 Sourcery 自动生成的 pull request 摘要、审阅者指南等。
  • 更改审阅语言。
  • 添加、删除或编辑自定义审阅说明。
  • 调整其他审阅设置。

获取帮助

Original review guide in English
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Aligns EdgeOne Pages comment DTO with the standard implementation so that deletion and like/dislike state work correctly, and adjusts ESLint ignore paths for specific EdgeOne artifacts.

Sequence diagram for EdgeOne Pages COMMENT_GET updated comment DTO

sequenceDiagram
  actor User
  participant Frontend
  participant COMMENT_GET
  participant toCommentDto

  User->>Frontend: request comments
  Frontend->>COMMENT_GET: COMMENT_GET
  COMMENT_GET->>toCommentDto: toCommentDto(comment, uid, replies, comments, cfg)
  toCommentDto-->>COMMENT_GET: dto { liked, disliked, ups, downs, isOwner, like }
  COMMENT_GET-->>Frontend: response with updated dto
  Frontend-->>User: render delete button, like/dislike count and state based on dto
Loading

File-Level Changes

Change Details Files
Align comment DTO fields with standard implementation to fix delete and like/dislike display
  • Initialize local ups/downs arrays from comment.ups/comment.downs with empty-array fallbacks
  • Expose ups/downs counts on the DTO and add disliked flag based on downs membership
  • Change liked computation to derive from ups.includes(uid) instead of legacy like array
  • Add isOwner flag based on uid matching comment.uid
  • Preserve legacy like count field for backward compatibility and keep replies shorthand
src/server/eo-pages/cloud-functions/index.js
Tighten ESLint ignore patterns for EdgeOne Pages generated/foreign files
  • Stop ignoring the entire cloud-functions directory and instead ignore specific generated or non-JS files (ip2region-data.js, smtp.go, .edgeone artifacts)
eslint.config.js

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我在这里给出一些整体性的反馈:

  • toCommentDto 中,like 仍然是从 comment.like.length 派生出来的,而 liked/ups 则是从 comment.ups 派生的。如果这些数组将来出现不一致,可能会导致点赞数不一致;建议让它们基于同一个数据源,或者明确文档化它们在使用上的差异。
  • 由于 ups/downs 只用于计算数量和成员关系,你可以将它们内联(例如:ups: (comment.ups || []).length),从而避免额外变量,并让 DTO 转换更简洁。
给 AI Agent 的提示
Please address the comments from this code review:

## Overall Comments
- In `toCommentDto`, `like` is still derived from `comment.like.length` while `liked`/`ups` are derived from `comment.ups`, which could lead to inconsistent like counts if those arrays ever diverge; consider basing both on the same source or explicitly documenting the difference in usage.
- Since `ups`/`downs` are only used to compute counts and membership, you could inline them (e.g., `ups: (comment.ups || []).length`) to avoid extra variables and keep the DTO transformation more compact.

Sourcery 对开源项目是免费的——如果你喜欢我们的评审,请考虑分享 ✨
帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进后续的代码评审。
Original comment in English

Hey - I've left some high level feedback:

  • In toCommentDto, like is still derived from comment.like.length while liked/ups are derived from comment.ups, which could lead to inconsistent like counts if those arrays ever diverge; consider basing both on the same source or explicitly documenting the difference in usage.
  • Since ups/downs are only used to compute counts and membership, you could inline them (e.g., ups: (comment.ups || []).length) to avoid extra variables and keep the DTO transformation more compact.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `toCommentDto`, `like` is still derived from `comment.like.length` while `liked`/`ups` are derived from `comment.ups`, which could lead to inconsistent like counts if those arrays ever diverge; consider basing both on the same source or explicitly documenting the difference in usage.
- Since `ups`/`downs` are only used to compute counts and membership, you could inline them (e.g., `ups: (comment.ups || []).length`) to avoid extra variables and keep the DTO transformation more compact.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@jeoor

jeoor commented Jun 20, 2026

Copy link
Copy Markdown
Contributor Author

Hey - 我在这里给出一些整体性的反馈:

  • toCommentDto 中,like 仍然是从 comment.like.length 派生出来的,而 liked/ups 则是从 comment.ups 派生的。如果这些数组将来出现不一致,可能会导致点赞数不一致;建议让它们基于同一个数据源,或者明确文档化它们在使用上的差异。
  • 由于 ups/downs 只用于计算数量和成员关系,你可以将它们内联(例如:ups: (comment.ups || []).length),从而避免额外变量,并让 DTO 转换更简洁。

给 AI Agent 的提示

Please address the comments from this code review:

## Overall Comments
- In `toCommentDto`, `like` is still derived from `comment.like.length` while `liked`/`ups` are derived from `comment.ups`, which could lead to inconsistent like counts if those arrays ever diverge; consider basing both on the same source or explicitly documenting the difference in usage.
- Since `ups`/`downs` are only used to compute counts and membership, you could inline them (e.g., `ups: (comment.ups || []).length`) to avoid extra variables and keep the DTO transformation more compact.

Sourcery 对开源项目是免费的——如果你喜欢我们的评审,请考虑分享 ✨

帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进后续的代码评审。
Original comment in English

Thanks. I kept the legacy like field for backward compatibility with the existing DTO shape and added a comment to document that new reaction counts and user state are derived from ups/downs.

I also kept the local ups/downs variables because they are used for both membership checks and counts, so inlining would duplicate the fallback logic.

@imaegoo imaegoo merged commit 1f03b58 into twikoojs:main Jun 22, 2026
2 checks passed
@jeoor jeoor deleted the fix/edgeone-comment-dto branch June 27, 2026 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants