Basic drive folder page

This commit is contained in:
jaina heartles 2022-12-13 02:05:37 -08:00
parent 03463de743
commit a49131f6bf
2 changed files with 42 additions and 0 deletions

View file

@ -17,6 +17,7 @@ pub const routes = .{
controllers.apiEndpoint(cluster.overview),
controllers.apiEndpoint(cluster.communities.create.page),
controllers.apiEndpoint(cluster.communities.create.submit),
controllers.apiEndpoint(drive.details),
};
const static = struct {
@ -229,6 +230,29 @@ const user_details = struct {
}
};
const drive = struct {
const details = struct {
pub const path = "/drive/:path*";
pub const method = .GET;
pub const Args = struct {
path: []const u8,
};
pub const dir_tmpl = @embedFile("./web/drive/directory.tmpl.html");
pub fn handler(req: anytype, res: anytype, srv: anytype) !void {
const info = try srv.driveGet(req.args.path);
defer util.deepFree(srv.allocator, info);
switch (info) {
.dir => |dir| try res.template(.ok, srv, dir_tmpl, .{ .dir = dir }),
else => unreachable,
}
}
};
};
const cluster = struct {
const overview = struct {
pub const path = "/cluster/overview";

View file

@ -0,0 +1,18 @@
<div class="drive">
<table class="directory-listing">
{#for .dir.children.? |$child| =}
<tr>
{#switch $child case dir |$dir| =}
<td class="icon"><i class="fa-solid fa-folder-closed"></i></td>
<td class="name"><a href="./{$dir.name.?}">{$dir.name.?}</a></td>
{#case file |$file| =}
<td class="icon"><i class="fa-solid fa-file"></i></td>
<td class="name"><a href="./{$file.name.?}">{$file.name.?}</a></td>
<td class="content-type">{#if $file.meta.content_type |$t|}{$t}{/if}</td>
<td class="size">{$file.meta.size}</td>
<td class="created-at">{$file.meta.created_at}</td>
{/switch =}
</tr>
{/for=}
</table>
</div>