This commit is contained in:
Vaica committed 2026-06-22 00:41:05 +08:00
1 parent ed14361e7b
commit d664326648
8 files changed
+39 -14

No files matched your search

+14 -3
View File
@@ -47,12 +47,18 @@ export function moveToRecycle(
expiresAt: expires.toISOString(),
};
// Move post directory to recycle
// Move post directory to recycle (fallback to copy+delete for cross-filesystem)
const targetDir = path.join(RECYCLE_POSTS_DIR, slug);
if (fs.existsSync(targetDir)) {
fs.rmSync(targetDir, { recursive: true, force: true });
}
fs.renameSync(sourceDir, targetDir);
try {
fs.renameSync(sourceDir, targetDir);
} catch (_e) {
// Cross-filesystem: copy then delete
fs.cpSync(sourceDir, targetDir, { recursive: true });
fs.rmSync(sourceDir, { recursive: true, force: true });
}
// Save metadata
const metaPath = path.join(RECYCLE_META_DIR, `${slug}.json`);
@@ -110,7 +116,12 @@ export function restoreFromRecycle(slug: string): boolean {
fs.rmSync(meta.originalPath, { recursive: true, force: true });
}
fs.renameSync(recyclePostPath, meta.originalPath);
try {
fs.renameSync(recyclePostPath, meta.originalPath);
} catch (_e) {
fs.cpSync(recyclePostPath, meta.originalPath, { recursive: true });
fs.rmSync(recyclePostPath, { recursive: true, force: true });
}
fs.unlinkSync(metaPath);
return true;