diff --git a/src/main/controllers/web.zig b/src/main/controllers/web.zig index d1feafd..5ec6d55 100644 --- a/src/main/controllers/web.zig +++ b/src/main/controllers/web.zig @@ -280,6 +280,7 @@ const drive = struct { const Action = enum { mkdir, + delete, }; pub const body_tag_from_query_param = "action"; @@ -287,6 +288,7 @@ const drive = struct { mkdir: struct { name: []const u8, }, + delete: struct {}, }; pub fn handler(req: anytype, res: anytype, srv: anytype) !void { @@ -297,6 +299,19 @@ const drive = struct { try servePage(req, res, srv); }, + .delete => { + const trimmed_path = std.mem.trim(u8, req.args.path, "/"); + _ = try srv.driveDelete(trimmed_path); + + const dir = trimmed_path[0 .. std.mem.lastIndexOfScalar(u8, trimmed_path, '/') orelse trimmed_path.len]; + const url = try std.fmt.allocPrint(srv.allocator, "{s}/drive/{s}", .{ + req.mount_path, + dir, + }); + defer srv.allocator.free(url); + try res.headers.put("Location", url); + return res.status(.see_other); + }, } } }; diff --git a/src/main/controllers/web/drive/directory.tmpl.html b/src/main/controllers/web/drive/directory.tmpl.html index 277174d..39f4b2d 100644 --- a/src/main/controllers/web/drive/directory.tmpl.html +++ b/src/main/controllers/web/drive/directory.tmpl.html @@ -48,6 +48,25 @@ {$dir.name.?} + + + + + + {#case file |$file|} {#if %user |$u|} @@ -71,6 +90,23 @@ {#if $file.meta.content_type |$t|}{$t}{/if} {$file.meta.size} {$file.meta.created_at} + + + {/switch =} {/for=} diff --git a/src/util/serialize.zig b/src/util/serialize.zig index a7ca8e1..120ca48 100644 --- a/src/util/serialize.zig +++ b/src/util/serialize.zig @@ -266,7 +266,11 @@ pub fn DeserializerContext(comptime Result: type, comptime From: type, comptime } pub fn finish(self: *@This(), allocator: std.mem.Allocator) !Result { - return (try self.deserialize(allocator, Result, self.data, &.{})) orelse error.MissingField; + return (try self.deserialize(allocator, Result, self.data, &.{})) orelse + if (std.meta.fields(Result).len == 0) + return .{} + else + return error.MissingField; } fn getSerializedField(self: *@This(), comptime field_ref: FieldRef) ?From {