Use body_tag_from_query_param

This commit is contained in:
jaina heartles 2022-12-16 02:05:20 -08:00
parent 57f2bd821e
commit 6dc8447343
2 changed files with 9 additions and 13 deletions

View file

@ -282,20 +282,17 @@ const drive = struct {
mkdir, mkdir,
}; };
pub const Body = struct { pub const body_tag_from_query_param = "action";
action: Action, pub const Body = union(Action) {
data: union(Action) {
mkdir: struct { mkdir: struct {
name: []const u8, name: []const u8,
}, },
},
}; };
pub fn handler(req: anytype, res: anytype, srv: anytype) !void { pub fn handler(req: anytype, res: anytype, srv: anytype) !void {
if (req.body.action != req.body.data) return error.BadRequest; switch (req.body) {
switch (req.body.data) { .mkdir => |body| {
.mkdir => |data| { _ = try srv.driveMkdir(req.args.path, body.name);
_ = try srv.driveMkdir(req.args.path, data.name);
// TODO // TODO
try servePage(req, res, srv); try servePage(req, res, srv);

View file

@ -29,12 +29,11 @@
<a class="button popup-close" href="#"> <a class="button popup-close" href="#">
<i class="fa-solid fa-xmark"></i> <i class="fa-solid fa-xmark"></i>
</a> </a>
<form class="popup-dialog" method="post" enctype="multipart/form-data"> <form class="popup-dialog" action="?action=mkdir" method="post" enctype="multipart/form-data">
<label> <label>
<div>Create Directory</div> <div>Create Directory</div>
<input type="text" name="mkcol.name" /> <!-- TODO: Rename this form param --> <input type="text" name="name" />
</label> </label>
<input type="hidden" name="action" value="mkcol" />
<button type="submit">Create</button> <button type="submit">Create</button>
</form> </form>
</div> </div>