Skip to content

Conversation

HardyNLee
Copy link
Contributor

介绍

新增 增量保存 按钮, 防止因原文件损坏而丢失整个文件的数据, 算是一种临时补救方案
image

严格来说, 原理是复制当前活动文件, 并加一个序号后缀

主要更改

  • TagsManager 最右边新增一个 增量保存 按钮
  • api 及相关地方新增增量保存函数

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @HardyNLee, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request implements a new 'incremental save' functionality, enhancing data safety by allowing users to create numbered backups of their currently active file. This feature aims to provide a temporary recovery solution, mitigating potential data loss in cases of original file corruption. The changes encompass updates to the user interface, new API definitions, and robust backend file system operations, along with comprehensive localization support.

Highlights

  • New Feature: Incremental Save Button: A new 'Incremental Save' button has been added to the TagsManager in the editor UI, providing users with an easy way to create backups.
  • API Integration for File Operations: A new API endpoint (/api/assets/copyFileWithIncrement) has been introduced to facilitate the incremental file saving process from the frontend to the backend.
  • Robust Backend File Management: The backend now includes a dedicated utility to copy files with an intelligent incremental naming convention (e.g., filename_001.ext, filename_002.ext), designed to prevent data loss from accidental file corruption.
  • Localization Support: New strings for the incremental save feature and its descriptive tooltip have been added to English, Japanese, and Simplified Chinese localization files, ensuring a consistent user experience across different languages.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

这个 PR 新增了增量保存功能,这是一个非常实用的特性,可以有效防止数据丢失。整体实现思路清晰,前端和后端代码都比较完善。我发现了一些可以改进的地方,主要涉及类型安全和代码健壮性,具体请看我的评论。修改这些问题后,代码质量会更高。

// 读取目录下所有文件
const files = await fs.readdir(dir);
// 匹配类似 xxx_序号.txt 的文件
const regex = new RegExp(`^${base}_(\\d+)${ext.replace('.', '\\.')}$`);
Copy link
Contributor

Choose a reason for hiding this comment

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

high

在构建正则表达式时,base 变量(即不带扩展名的文件名)没有被转义。如果文件名包含正则表达式的特殊字符(例如 (, ), . 等),这可能会导致 new RegExp 抛出错误或产生意外的匹配行为。为了增强健壮性,建议对 base 变量进行转义。

Suggested change
const regex = new RegExp(`^${base}_(\\d+)${ext.replace('.', '\\.')}$`);
const escapedBase = base.replace(/[.*+?^${}()|[\\\]]/g, '\\$&');
const regex = new RegExp(`^${escapedBase}_(\\d+)${ext.replace('.', '\\.')}$`);

Comment on lines +112 to +116
onMouseDown={(event: any) => {
if (event.button === 1) {
closeTag(event, item);
}
}}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

event 参数的类型是 any。为了更好的类型安全和代码可读性,建议使用更具体的 React.MouseEvent 类型。另外,closeTag 函数期望一个原生的 MouseEvent,所以应该传递 event.nativeEvent

Suggested change
onMouseDown={(event: any) => {
if (event.button === 1) {
closeTag(event, item);
}
}}
onMouseDown={(event: React.MouseEvent) => {
if (event.button === 1) {
closeTag(event.nativeEvent, item);
}
}}

<div>
{item.name}
</div>
<div className={styles.closeIcon} onClick={(event: any) => closeTag(event, item)}>
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

event 参数的类型是 any。为了更好的类型安全和代码可读性,建议使用更具体的 React.MouseEvent 类型。另外,closeTag 函数期望一个原生的 MouseEvent,所以应该传递 event.nativeEvent

Suggested change
<div className={styles.closeIcon} onClick={(event: any) => closeTag(event, item)}>
<div className={styles.closeIcon} onClick={(event: React.MouseEvent) => closeTag(event.nativeEvent, item)}>

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.

1 participant