zen-gitsync 2.10.5 → 2.10.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,10 +6,10 @@
6
6
  <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
7
7
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
8
8
  <title>Zen GitSync</title>
9
- <script type="module" crossorigin src="/assets/index-DyAN61Fr.js"></script>
10
- <link rel="modulepreload" crossorigin href="/assets/vendor-D4i1qkqt.js">
9
+ <script type="module" crossorigin src="/assets/index-5z2rWrTJ.js"></script>
10
+ <link rel="modulepreload" crossorigin href="/assets/vendor-CrYGMytM.js">
11
11
  <link rel="stylesheet" crossorigin href="/assets/vendor-BreftYKt.css">
12
- <link rel="stylesheet" crossorigin href="/assets/index-GafPlTJq.css">
12
+ <link rel="stylesheet" crossorigin href="/assets/index-bVmQ0atC.css">
13
13
  </head>
14
14
  <body>
15
15
  <div id="app"></div>
@@ -449,7 +449,8 @@ export function registerConfigRoutes({
449
449
  name: command.name,
450
450
  description: command.description || '',
451
451
  directory: command.directory || '',
452
- command: command.command
452
+ command: command.command,
453
+ params: Array.isArray(command.params) ? command.params : []
453
454
  }
454
455
 
455
456
  config.customCommands.push(newCommand)
@@ -505,7 +506,8 @@ export function registerConfigRoutes({
505
506
  name: command.name,
506
507
  description: command.description || '',
507
508
  directory: command.directory || '',
508
- command: command.command
509
+ command: command.command,
510
+ params: Array.isArray(command.params) ? command.params : []
509
511
  }
510
512
  await configManager.saveConfig(config)
511
513
  } else {
@@ -8,6 +8,9 @@ export function registerGitDiffRoutes({
8
8
  }) {
9
9
  const { checkShouldSkipDiff, checkDiffSize, getDiffStats } = createDiffHelpers({ execGitCommand });
10
10
 
11
+ const skipExtensions = /\.(min\.js|umd\.cjs|bundle\.js|dist\.js|prod\.js|map|wasm|exe|dll|so|dylib|bin|zip|tar|gz|rar|7z|jar|war|ear|pdf|doc|docx|xls|xlsx|ppt|pptx|jpg|jpeg|png|gif|bmp|ico|mp3|mp4|avi|mov|wmv|flv|webm|mkv|ttf|woff|woff2|eot|otf)$/i;
12
+ const maxBytes = 1024 * 1024;
13
+
11
14
  // 获取文件差异
12
15
  app.get('/api/diff', async (req, res) => {
13
16
  try {
@@ -106,6 +109,50 @@ export function registerGitDiffRoutes({
106
109
  }
107
110
  });
108
111
 
112
+ app.get('/api/git-file-content', async (req, res) => {
113
+ try {
114
+ const filePath = req.query.file;
115
+ const rev = req.query.rev;
116
+
117
+ if (!filePath || !rev) {
118
+ return res.status(400).json({ success: false, error: '缺少必要参数' });
119
+ }
120
+
121
+ if (skipExtensions.test(String(filePath))) {
122
+ return res.json({
123
+ success: true,
124
+ isBinary: true,
125
+ content: '⚠️ 检测到二进制/编译产物文件,不支持以文本形式显示完整内容。'
126
+ });
127
+ }
128
+
129
+ const r = String(rev);
130
+ const spec = r === ':' ? `:${filePath}` : `${r}:${filePath}`;
131
+
132
+ let sizeBytes = 0;
133
+ try {
134
+ const { stdout: sizeOut } = await execGitCommand(`git cat-file -s "${spec}"`, { log: false });
135
+ sizeBytes = parseInt(String(sizeOut).trim(), 10) || 0;
136
+ } catch (e) {
137
+ return res.json({ success: true, notFound: true, content: '' });
138
+ }
139
+
140
+ if (sizeBytes > maxBytes) {
141
+ return res.json({
142
+ success: true,
143
+ isLargeFile: true,
144
+ size: sizeBytes,
145
+ content: `⚠️ 文件内容过大 (${(sizeBytes / 1024).toFixed(1)} KB),已跳过显示以避免浏览器卡顿。`
146
+ });
147
+ }
148
+
149
+ const { stdout } = await execGitCommand(`git show "${spec}"`, { log: false });
150
+ return res.json({ success: true, content: stdout ?? '' });
151
+ } catch (error) {
152
+ res.status(500).json({ success: false, error: error.message });
153
+ }
154
+ });
155
+
109
156
  // 解决冲突:保存解决后的文件内容
110
157
  app.post('/api/resolve-conflict', async (req, res) => {
111
158
  try {
@@ -742,6 +742,79 @@ export function registerGitOpsRoutes({
742
742
  }
743
743
  });
744
744
 
745
+ app.get('/api/commit-file-content', async (req, res) => {
746
+ try {
747
+ const hash = req.query.hash;
748
+ const filePath = req.query.file;
749
+ const version = req.query.version;
750
+
751
+ if (!hash || !filePath) {
752
+ return res.status(400).json({
753
+ success: false,
754
+ error: '缺少必要参数'
755
+ });
756
+ }
757
+
758
+ const isOld = String(version || 'new') === 'old';
759
+ const targetHash = isOld ? `${hash}^` : `${hash}`;
760
+
761
+ const skipExtensions = /\.(min\.js|umd\.cjs|bundle\.js|dist\.js|prod\.js|map|wasm|exe|dll|so|dylib|bin|zip|tar|gz|rar|7z|jar|war|ear|pdf|doc|docx|xls|xlsx|ppt|pptx|jpg|jpeg|png|gif|bmp|ico|mp3|mp4|avi|mov|wmv|flv|webm|mkv|ttf|woff|woff2|eot|otf)$/i;
762
+ if (skipExtensions.test(String(filePath))) {
763
+ return res.json({
764
+ success: true,
765
+ isBinary: true,
766
+ content: '⚠️ 检测到二进制/编译产物文件,不支持以文本形式显示完整内容。\n\n提示:建议使用专业工具或命令行查看。'
767
+ });
768
+ }
769
+
770
+ const spec = `${targetHash}:${filePath}`;
771
+ const sizeCmd = `git cat-file -s "${spec}"`;
772
+
773
+ let sizeBytes = 0;
774
+ try {
775
+ const { stdout: sizeOut } = await execGitCommand(sizeCmd, { log: false });
776
+ sizeBytes = parseInt(String(sizeOut).trim(), 10) || 0;
777
+ } catch (e) {
778
+ return res.json({
779
+ success: true,
780
+ notFound: true,
781
+ content: isOld
782
+ ? '该文件在该提交的上一个版本中不存在(可能是新增文件)。'
783
+ : '该文件在该提交版本中不存在(可能是删除文件或重命名)。'
784
+ });
785
+ }
786
+
787
+ const maxBytes = 1024 * 1024;
788
+ if (sizeBytes > maxBytes) {
789
+ return res.json({
790
+ success: true,
791
+ isLargeFile: true,
792
+ size: sizeBytes,
793
+ content: `⚠️ 文件内容过大 (${(sizeBytes / 1024).toFixed(1)} KB),已跳过显示以避免浏览器卡顿。\n\n提示:建议使用命令行或编辑器打开查看。`
794
+ });
795
+ }
796
+
797
+ const showCmd = `git show "${spec}"`;
798
+ try {
799
+ const { stdout } = await execGitCommand(showCmd, { log: false });
800
+ res.json({
801
+ success: true,
802
+ content: stdout ?? ''
803
+ });
804
+ } catch (error) {
805
+ res.status(500).json({
806
+ success: false,
807
+ error: `获取文件内容失败: ${error.message}`
808
+ });
809
+ }
810
+ } catch (error) {
811
+ res.status(500).json({
812
+ success: false,
813
+ error: error.message
814
+ });
815
+ }
816
+ });
817
+
745
818
  // 撤销某个提交 (revert)
746
819
  app.post('/api/revert-commit', async (req, res) => {
747
820
  try {