fix(web): handle plans dir errors during listing
This commit is contained in:
@@ -6505,9 +6505,16 @@ async function main(options = {}) {
|
|||||||
? req.query.path.trim()
|
? req.query.path.trim()
|
||||||
: os.homedir();
|
: os.homedir();
|
||||||
const respectGitignore = req.query.respectGitignore === 'true';
|
const respectGitignore = req.query.respectGitignore === 'true';
|
||||||
|
let resolvedPath = '';
|
||||||
|
|
||||||
|
const isPlansDirectory = (value) => {
|
||||||
|
if (!value || typeof value !== 'string') return false;
|
||||||
|
const normalized = value.replace(/\\/g, '/').replace(/\/+$/, '');
|
||||||
|
return normalized.endsWith('/.opencode/plans') || normalized.endsWith('.opencode/plans');
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const resolvedPath = path.resolve(normalizeDirectoryPath(rawPath));
|
resolvedPath = path.resolve(normalizeDirectoryPath(rawPath));
|
||||||
|
|
||||||
const stats = await fsPromises.stat(resolvedPath);
|
const stats = await fsPromises.stat(resolvedPath);
|
||||||
if (!stats.isDirectory()) {
|
if (!stats.isDirectory()) {
|
||||||
@@ -6588,16 +6595,17 @@ async function main(options = {}) {
|
|||||||
entries: entries.filter(Boolean)
|
entries: entries.filter(Boolean)
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to list directory:', error);
|
|
||||||
const err = error;
|
const err = error;
|
||||||
if (err && typeof err === 'object' && 'code' in err) {
|
const code = err && typeof err === 'object' && 'code' in err ? err.code : undefined;
|
||||||
const code = err.code;
|
const isPlansPath = code === 'ENOENT' && (isPlansDirectory(resolvedPath) || isPlansDirectory(rawPath));
|
||||||
if (code === 'ENOENT') {
|
if (!isPlansPath) {
|
||||||
return res.status(404).json({ error: 'Directory not found' });
|
console.error('Failed to list directory:', error);
|
||||||
}
|
}
|
||||||
if (code === 'EACCES') {
|
if (code === 'ENOENT') {
|
||||||
return res.status(403).json({ error: 'Access to directory denied' });
|
return res.status(404).json({ error: 'Directory not found' });
|
||||||
}
|
}
|
||||||
|
if (code === 'EACCES') {
|
||||||
|
return res.status(403).json({ error: 'Access to directory denied' });
|
||||||
}
|
}
|
||||||
res.status(500).json({ error: (error && error.message) || 'Failed to list directory' });
|
res.status(500).json({ error: (error && error.message) || 'Failed to list directory' });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user