Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #678 #679

Merged
merged 3 commits into from
Dec 31, 2024
Merged

fix #678 #679

merged 3 commits into from
Dec 31, 2024

Conversation

wu-yafeng
Copy link
Contributor

@wu-yafeng wu-yafeng commented Dec 31, 2024

Summary by Sourcery

Bug 修复:

  • 确保如果配置文件存在但不可读,仍然能够写入 webui 配置。
Original summary in English

Summary by Sourcery

Bug Fixes:

  • Ensure the webui config is written if the file exists but is not readable.

Copy link

sourcery-ai bot commented Dec 31, 2024

审阅者指南 by Sourcery

此 PR 修复了如果 webui.json 文件不存在则不会创建的错误。同时确保仅在具有写入权限时才将配置写回文件。

WebUI 配置文件处理的序列图

sequenceDiagram
    participant WebUiConfigWrapper
    participant FileSystem

WebUiConfigWrapper->>FileSystem: Check if config file exists (F_OK)
    alt File does not exist
        WebUiConfigWrapper->>FileSystem: Write default config
    end
    WebUiConfigWrapper->>FileSystem: Read config file
    WebUiConfigWrapper->>WebUiConfigWrapper: Parse and validate config
    WebUiConfigWrapper->>FileSystem: Check write permission (W_OK)
    alt Has write permission
        WebUiConfigWrapper->>FileSystem: Write updated config
    end
Loading

配置文件操作的状态图

stateDiagram-v2
    [*] --> CheckFileExists
    CheckFileExists --> CreateFile: File not exists
    CheckFileExists --> ReadConfig: File exists
    CreateFile --> ReadConfig
    ReadConfig --> ValidateConfig
    ValidateConfig --> CheckWritePermission
    CheckWritePermission --> WriteConfig: Has permission
    CheckWritePermission --> [*]: No permission
    WriteConfig --> [*]
Loading

文件级别变更

变更 详情 文件
检查文件是否存在而非读取权限
  • 将访问检查从 constants.R_OK 更改为 constants.F_OK
src/webui/src/helper/config.ts
仅在文件可写时写入配置
  • 在将配置写回 webui.json 文件之前添加了写入权限检查
src/webui/src/helper/config.ts

提示和命令

与 Sourcery 交互

  • 触发新的审阅: 在拉取请求中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审阅评论。
  • 从审阅评论生成 GitHub 问题: 通过回复评论要求 Sourcery 创建问题。
  • 生成拉取请求标题: 在拉取请求标题的任何位置写 @sourcery-ai 以随时生成标题。
  • 生成拉取请求摘要: 在拉取请求正文的任何位置写 @sourcery-ai summary 以随时生成 PR 摘要。您还可以使用此命令指定摘要的插入位置。

自定义您的体验

访问您的仪表板以:

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

获取帮助

Original review guide in English

Reviewer's Guide by Sourcery

This PR fixes a bug where the webui.json file is not created if it does not exist. It also ensures that the config is only written back to the file if the file has write access.

Sequence diagram for WebUI config file handling

sequenceDiagram
    participant WebUiConfigWrapper
    participant FileSystem

WebUiConfigWrapper->>FileSystem: Check if config file exists (F_OK)
    alt File does not exist
        WebUiConfigWrapper->>FileSystem: Write default config
    end
    WebUiConfigWrapper->>FileSystem: Read config file
    WebUiConfigWrapper->>WebUiConfigWrapper: Parse and validate config
    WebUiConfigWrapper->>FileSystem: Check write permission (W_OK)
    alt Has write permission
        WebUiConfigWrapper->>FileSystem: Write updated config
    end
Loading

State diagram for config file operations

stateDiagram-v2
    [*] --> CheckFileExists
    CheckFileExists --> CreateFile: File not exists
    CheckFileExists --> ReadConfig: File exists
    CreateFile --> ReadConfig
    ReadConfig --> ValidateConfig
    ValidateConfig --> CheckWritePermission
    CheckWritePermission --> WriteConfig: Has permission
    CheckWritePermission --> [*]: No permission
    WriteConfig --> [*]
Loading

File-Level Changes

Change Details Files
Check for file existence instead of read access
  • Changed the access check from constants.R_OK to constants.F_OK
src/webui/src/helper/config.ts
Write config only if file is writable
  • Added a check for write access before writing the config back to the webui.json file
src/webui/src/helper/config.ts

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.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a 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. You can also use
    this command to specify where the summary should be inserted.

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

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

@wu-yafeng - 我已经审查了你的更改 - 以下是一些反馈:

整体评论

  • W_OK 权限检查在写入配置之前会在没有写入权限时静默失败。这应该抛出一个错误,因为静默跳过写入操作可能导致配置不一致。
以下是我在审查期间查看的内容
  • 🟢 一般问题:一切看起来都很好
  • 🟡 安全性:发现1个问题
  • 🟢 测试:一切看起来都很好
  • 🟢 复杂性:一切看起来都很好
  • 🟢 文档:一切看起来都很好

Sourcery 对开源是免费的 - 如果你喜欢我们的评论,请考虑分享它们 ✨
帮助我变得更有用!请在每条评论上点击 👍 或 👎,我将使用反馈来改进你的评论。
Original comment in English

Hey @wu-yafeng - I've reviewed your changes - here's some feedback:

Overall Comments:

  • The W_OK permission check before writing the config silently fails if we don't have write permissions. This should throw an error instead, as silently skipping the write operation could lead to configuration inconsistencies.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟡 Security: 1 issue found
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

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.

src/webui/src/helper/config.ts Outdated Show resolved Hide resolved
@wu-yafeng
Copy link
Contributor Author

wu-yafeng commented Dec 31, 2024

是否需要在文件不存在时,默认创建文件的动作记录information日志?
是否需要考虑在配置更改,没有回写权限时,记录warn日志?

@MliKiowa
Copy link
Member

是否需要在文件不存在时,默认创建文件的动作记录information日志? 是否需要考虑在配置更改,没有回写权限时,记录warn日志?

这个不需要 无权限可以warn下

@MliKiowa MliKiowa changed the title fix #669 fix #679 Dec 31, 2024
@MliKiowa MliKiowa changed the title fix #679 fix #678 Dec 31, 2024
@MliKiowa MliKiowa merged commit 6be6023 into NapNeko:main Dec 31, 2024
4 checks passed
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