Folder-Browser für Workspace-Auswahl, Layout/Style Anpassungen
This commit is contained in:
1 parent
f4ad949db4
commit
aa2d9f1200
6 files changed
+179
-23
No files matched your search
@@ -38,6 +38,7 @@ public static class WorkspaceEndpoint
|
||||
{
|
||||
app.MapGet("/api/workspace/tree", HandleTree);
|
||||
app.MapGet("/api/workspace/file", HandleFile);
|
||||
app.MapGet("/api/workspace/browse", HandleBrowse);
|
||||
}
|
||||
|
||||
private static async Task HandleTree(HttpContext ctx)
|
||||
@@ -157,6 +158,41 @@ public static class WorkspaceEndpoint
|
||||
});
|
||||
}
|
||||
|
||||
private static async Task HandleBrowse(HttpContext ctx)
|
||||
{
|
||||
var path = ctx.Request.Query["path"].FirstOrDefault() ?? "/";
|
||||
|
||||
var targetPath = Path.GetFullPath(path);
|
||||
if (!Directory.Exists(targetPath))
|
||||
{
|
||||
ctx.Response.StatusCode = 404;
|
||||
await ctx.Response.WriteAsJsonAsync(new { error = "Verzeichnis nicht gefunden" });
|
||||
return;
|
||||
}
|
||||
|
||||
var entries = new List<object>();
|
||||
|
||||
// Parent
|
||||
var parent = Directory.GetParent(targetPath);
|
||||
if (parent != null)
|
||||
{
|
||||
entries.Add(new { name = "..", path = parent.FullName.Replace('\\', '/'), type = "dir" });
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
foreach (var dir in Directory.GetDirectories(targetPath).OrderBy(d => Path.GetFileName(d), StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
var name = Path.GetFileName(dir);
|
||||
if (IgnoredDirs.Contains(name)) continue;
|
||||
entries.Add(new { name, path = dir.Replace('\\', '/'), type = "dir" });
|
||||
}
|
||||
}
|
||||
catch (UnauthorizedAccessException) { }
|
||||
|
||||
await ctx.Response.WriteAsJsonAsync(new { current = targetPath.Replace('\\', '/'), entries });
|
||||
}
|
||||
|
||||
private static bool IsLikelyTextFile(string name)
|
||||
{
|
||||
var lower = name.ToLowerInvariant();
|
||||
|
||||
Reference in new issue
Block a user