FIX: Implement proper 404 error handling for missing files in SSH file size check

- Fix case-sensitive string matching for "no such file or directory" errors
- Return 404 status with fileNotFound flag when files don't exist
- Enable automatic cleanup of deleted files from recent/pinned lists
- Improve error detection in file size check phase before file reading
This commit is contained in:
ZacharyZcR
2025-09-25 08:05:42 +08:00
parent 36ae41a4f1
commit a9dc8d9cb3

View File

@@ -569,10 +569,20 @@ app.get("/ssh/file_manager/ssh/readFile", (req, res) => {
sizeStream.on("close", (sizeCode) => {
if (sizeCode !== 0) {
// Check if it's a file not found error (case-insensitive)
const errorLower = sizeErrorData.toLowerCase();
const isFileNotFound = errorLower.includes("no such file or directory") ||
errorLower.includes("cannot access") ||
errorLower.includes("not found") ||
errorLower.includes("resource not found");
fileLogger.error(`File size check failed: ${sizeErrorData}`);
return res
.status(500)
.json({ error: `Cannot check file size: ${sizeErrorData}` });
.status(isFileNotFound ? 404 : 500)
.json({
error: `Cannot check file size: ${sizeErrorData}`,
fileNotFound: isFileNotFound
});
}
const fileSize = parseInt(sizeData.trim(), 10);