diff --git a/src/api/lib.zig b/src/api/lib.zig index e28bda5..f153140 100644 --- a/src/api/lib.zig +++ b/src/api/lib.zig @@ -781,13 +781,9 @@ fn ApiConn(comptime DbConn: type) type { return try self.backendDriveEntryToFrontend(entry, true); } - pub fn driveMkdir(self: *Self, path: []const u8) !DriveEntry { + pub fn driveMkdir(self: *Self, parent_path: []const u8, name: []const u8) !DriveEntry { const user_id = self.user_id orelse return error.NoToken; - var split = std.mem.splitBackwards(u8, path, "/"); - std.log.debug("{s}", .{path}); - const base = split.first(); - const dir = split.rest(); - const entry = try services.drive.create(self.db, user_id, dir, base, null, self.allocator); + const entry = try services.drive.create(self.db, user_id, parent_path, name, null, self.allocator); errdefer util.deepFree(self.allocator, entry); return try self.backendDriveEntryToFrontend(entry, true); } diff --git a/src/main/controllers/api/drive.zig b/src/main/controllers/api/drive.zig index 4650106..17e8a27 100644 --- a/src/main/controllers/api/drive.zig +++ b/src/main/controllers/api/drive.zig @@ -1,3 +1,4 @@ +const std = @import("std"); const api = @import("api"); const http = @import("http"); const util = @import("util"); @@ -68,7 +69,12 @@ pub const mkdir = struct { pub const Args = DriveArgs; pub fn handler(req: anytype, res: anytype, srv: anytype) !void { - const result = try srv.driveMkdir(req.args.path); + var split = std.mem.splitBackwards(u8, std.mem.trim(u8, req.args.path, "/"), "/"); + const name = split.first(); + const parent = split.rest(); + std.log.debug("{s}, {s}", .{ parent, name }); + + const result = try srv.driveMkdir(parent, name); errdefer util.deepFree(srv.allocator, result); try res.json(.created, result);