fix: preserve save-as backups and register history CLI routes

This commit is contained in:
whyour committed 2026-10-06 01:54:59 +08:00
1 parent ea9461c085
commit 91e6005152
6 files changed
+152 -3

No files matched your search

+9
View File
@@ -295,6 +295,15 @@ export default (app: Router) => {
fileExists &&
resolveFileAccess(config.scriptPath, [filePath], config.blackFileList)
) {
// Save-as removes the source after committing the destination. Keep
// its original content too: destination history only protects the
// file being overwritten, not the source being deleted.
if (filename !== originFilename) {
await fs.copyFile(
originFilePath,
join(config.bakPath, originFilename.replace(/\//g, '')),
);
}
const data = await historyService().save(path, filename, content, {
skipHistory: req.body.skipHistory,
expectedHash: req.body.expectedHash,