Fix: Allow directory creation outside workspace in Add Project modal (#256)
This commit is contained in:
@@ -26,3 +26,4 @@ local-dev*
|
|||||||
*.njsproj
|
*.njsproj
|
||||||
*.sln
|
*.sln
|
||||||
*.sw?
|
*.sw?
|
||||||
|
.opencode/plans/*
|
||||||
|
|||||||
@@ -582,7 +582,7 @@ export const DirectoryTree: React.FC<DirectoryTreeProps> = ({
|
|||||||
const fullPath = `${creatingInPath}/${dirName}`;
|
const fullPath = `${creatingInPath}/${dirName}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await opencodeClient.createDirectory(fullPath);
|
await opencodeClient.createDirectory(fullPath, { allowOutsideWorkspace: true });
|
||||||
|
|
||||||
const children = await loadDirectory(creatingInPath);
|
const children = await loadDirectory(creatingInPath);
|
||||||
const updateItems = (items: DirectoryItem[]): DirectoryItem[] => {
|
const updateItems = (items: DirectoryItem[]): DirectoryItem[] => {
|
||||||
|
|||||||
@@ -1752,7 +1752,10 @@ class OpencodeService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// File System Operations
|
// File System Operations
|
||||||
async createDirectory(dirPath: string): Promise<{ success: boolean; path: string }> {
|
async createDirectory(
|
||||||
|
dirPath: string,
|
||||||
|
options?: { allowOutsideWorkspace?: boolean }
|
||||||
|
): Promise<{ success: boolean; path: string }> {
|
||||||
const desktopFiles = getDesktopFilesApi();
|
const desktopFiles = getDesktopFilesApi();
|
||||||
if (desktopFiles?.createDirectory) {
|
if (desktopFiles?.createDirectory) {
|
||||||
try {
|
try {
|
||||||
@@ -1763,12 +1766,17 @@ class OpencodeService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
path: dirPath,
|
||||||
|
...(options?.allowOutsideWorkspace ? { allowOutsideWorkspace: true } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
const response = await fetch(`${this.baseUrl}/fs/mkdir`, {
|
const response = await fetch(`${this.baseUrl}/fs/mkdir`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ path: dirPath }),
|
body: JSON.stringify(payload),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
|||||||
@@ -6151,20 +6151,27 @@ async function main(options = {}) {
|
|||||||
|
|
||||||
app.post('/api/fs/mkdir', async (req, res) => {
|
app.post('/api/fs/mkdir', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { path: dirPath } = req.body;
|
const { path: dirPath, allowOutsideWorkspace } = req.body ?? {};
|
||||||
|
|
||||||
if (!dirPath) {
|
if (typeof dirPath !== 'string' || !dirPath.trim()) {
|
||||||
return res.status(400).json({ error: 'Path is required' });
|
return res.status(400).json({ error: 'Path is required' });
|
||||||
}
|
}
|
||||||
|
|
||||||
const resolved = await resolveWorkspacePathFromContext(req, dirPath);
|
let resolvedPath = '';
|
||||||
if (!resolved.ok) {
|
|
||||||
return res.status(400).json({ error: resolved.error });
|
if (allowOutsideWorkspace) {
|
||||||
|
resolvedPath = path.resolve(normalizeDirectoryPath(dirPath));
|
||||||
|
} else {
|
||||||
|
const resolved = await resolveWorkspacePathFromContext(req, dirPath);
|
||||||
|
if (!resolved.ok) {
|
||||||
|
return res.status(400).json({ error: resolved.error });
|
||||||
|
}
|
||||||
|
resolvedPath = resolved.resolved;
|
||||||
}
|
}
|
||||||
|
|
||||||
await fsPromises.mkdir(resolved.resolved, { recursive: true });
|
await fsPromises.mkdir(resolvedPath, { recursive: true });
|
||||||
|
|
||||||
res.json({ success: true, path: resolved.resolved });
|
res.json({ success: true, path: resolvedPath });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to create directory:', error);
|
console.error('Failed to create directory:', error);
|
||||||
res.status(500).json({ error: error.message || 'Failed to create directory' });
|
res.status(500).json({ error: error.message || 'Failed to create directory' });
|
||||||
|
|||||||
Reference in New Issue
Block a user