diff --git a/src/main/controllers/web.zig b/src/main/controllers/web.zig index cde66a8..835e64e 100644 --- a/src/main/controllers/web.zig +++ b/src/main/controllers/web.zig @@ -18,6 +18,7 @@ pub const routes = .{ controllers.apiEndpoint(cluster.communities.create.page), controllers.apiEndpoint(cluster.communities.create.submit), controllers.apiEndpoint(drive.details), + controllers.apiEndpoint(drive.form), }; const static = struct { @@ -231,6 +232,31 @@ const user_details = struct { }; const drive = struct { + const dir_tmpl = @embedFile("./web/drive/directory.tmpl.html"); + fn servePage(req: anytype, res: anytype, srv: anytype) !void { + const info = try srv.driveGet(req.args.path); + defer util.deepFree(srv.allocator, info); + + var breadcrumbs = std.ArrayList([]const u8).init(srv.allocator); + defer breadcrumbs.deinit(); + + var iter = util.PathIter.from(req.args.path); + while (iter.next()) |p| { + std.log.debug("breadcrumb: {s}", .{p}); + try breadcrumbs.append(if (p.len != 0) p else continue); + } + + switch (info) { + .dir => |dir| try res.template(.ok, srv, dir_tmpl, .{ + .dir = dir, + .breadcrumbs = breadcrumbs.items, + .mount_path = req.mount_path, + .base_drive_path = "drive", + }), + else => unreachable, + } + } + const details = struct { pub const path = "/drive/:path*"; pub const method = .GET; @@ -239,29 +265,41 @@ const drive = struct { path: []const u8, }; - pub const dir_tmpl = @embedFile("./web/drive/directory.tmpl.html"); + pub fn handler(req: anytype, res: anytype, srv: anytype) !void { + try servePage(req, res, srv); + } + }; + + const form = struct { + pub const path = "/drive/:path*"; + pub const method = .POST; + + pub const Args = struct { + path: []const u8, + }; + + const Action = enum { + mkcol, + }; + + pub const Body = struct { + action: Action, + data: union(Action) { + mkcol: struct { + name: []const u8, + }, + }, + }; pub fn handler(req: anytype, res: anytype, srv: anytype) !void { - const info = try srv.driveGet(req.args.path); - defer util.deepFree(srv.allocator, info); + if (req.body.action != req.body.data) return error.BadRequest; + switch (req.body.data) { + .mkcol => |data| { + _ = try srv.driveMkdir(req.args.path, data.name); + // TODO - var breadcrumbs = std.ArrayList([]const u8).init(srv.allocator); - defer breadcrumbs.deinit(); - - var iter = util.PathIter.from(req.args.path); - while (iter.next()) |p| { - std.log.debug("breadcrumb: {s}", .{p}); - try breadcrumbs.append(if (p.len != 0) p else continue); - } - - switch (info) { - .dir => |dir| try res.template(.ok, srv, dir_tmpl, .{ - .dir = dir, - .breadcrumbs = breadcrumbs.items, - .mount_path = req.mount_path, - .base_drive_path = "drive", - }), - else => unreachable, + try servePage(req, res, srv); + }, } } }; diff --git a/src/main/controllers/web/drive/directory.tmpl.html b/src/main/controllers/web/drive/directory.tmpl.html index f6d59bf..5135b6a 100644 --- a/src/main/controllers/web/drive/directory.tmpl.html +++ b/src/main/controllers/web/drive/directory.tmpl.html @@ -17,6 +17,28 @@ {/for =} + +