╭ changed ──╮ │src/web.zig│ ╰───────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭─────────────────────────────────────────────────────────────────────────────╮ │37 │ │38 // what a web request is served from: the multi-user server (admin repo +│ │39 // login sessions) or a single local repo. │ │40 -pub const Host = union(enum) { │ │41 - remote: struct { │ │40 +pub const Host = union(evt.HostKind) { │ │41 + local: ui.RepoSource, │ │42 + server: struct { │ │43 admin_repo_path: []const u8, │ │44 session_store: SessionStore, │ │45 git_http_port: ?u16, │ ╰─────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────╮ │46 git_ssh_port: ?u16, │ │47 git_ssh_prefix: []const u8, │ │48 }, │ │48 - local: ui.RepoSource, │ │49 }; │ │50 │ │51 -// an on-disk repo resolved from a request url. remote paths are owned.│ │51 +// an on-disk repo resolved from a request url. server paths are owned.│ │52 const RequestRepoSource = struct { │ │53 source: ui.RepoSource, │ │54 owned_path: ?[]const u8 = null, │ ╰───────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │60 │ │61 fn requestRepoSource(io: std.Io, allocator: std.mem.Allocator, host: Host, repo_base: []const u8) !?RequestRepoSource { │ │62 return switch (host) { │ │63 - .remote => |remote| blk: { │ │63 + .server => |server| blk: { │ │64 const repo_prefix = "/repo/"; │ │65 if (!std.mem.startsWith(u8, repo_base, repo_prefix)) break :blk null; │ │66 - const repos_dir = try std.fs.path.join(allocator, &.{ std.fs.path.dirname(remote.admin_repo_path) orelse ".", "repos" }); │ │66 + const repos_dir = try std.fs.path.join(allocator, &.{ std.fs.path.dirname(server.admin_repo_path) orelse ".", "repos" }); │ │67 defer allocator.free(repos_dir); │ │68 - const path = switch (try serve_common.resolveRepoPath(io, allocator, repos_dir, remote.admin_repo_path, repo_base[repo_prefix.len..], false)) {│ │68 + const path = switch (try serve_common.resolveRepoPath(io, allocator, repos_dir, server.admin_repo_path, repo_base[repo_prefix.len..], false)) {│ │69 .ok => |value| value, │ │70 .invalid, .not_found => break :blk null, │ │71 }; │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │132 // you were on. local mode has no accounts, so only the repo routes. │ │133 if (method == .POST) { │ │134 switch (host) { │ │135 - .remote => |remote| { │ │135 + .server => |server| { │ │136 const PostRoute = enum { login, logout, ansi, new, edit, remove, open, close, resolve, publish, merge, squash, attach };│ │137 inline for (@typeInfo(PostRoute).@"enum".fields) |field| { │ │138 const suffix = "/" ++ field.name; │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │139 if (std.mem.endsWith(u8, path, suffix)) { │ │140 const base = path[0 .. path.len - suffix.len]; │ │141 return switch (@field(PostRoute, field.name)) { │ │142 - .login => handleLogin(io, request, allocator, base, remote.admin_repo_path, remote.session_store),│ │143 - .logout => handleLogout(request, base, remote.session_store), │ │144 - .ansi => handleAnsi(io, request, allocator, base, remote.admin_repo_path, remote.session_store), │ │142 + .login => handleLogin(io, request, allocator, base, server.admin_repo_path, server.session_store),│ │143 + .logout => handleLogout(request, base, server.session_store), │ │144 + .ansi => handleAnsi(io, request, allocator, base, server.admin_repo_path, server.session_store), │ │145 .new => handleNew(io, request, allocator, base, host), │ │146 .edit => handleEdit(io, request, allocator, base, host), │ │147 .remove => handleRemove(io, request, allocator, base, host), │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │200 if (attachmentRequest(path)) |attachment| return serveAttachment(io, request, allocator, attachment, host);│ │201 │ │202 const current_page_maybe = switch (host) { │ │203 - .remote => ui.RoutablePage.fromUrl(path), │ │203 + .server => ui.RoutablePage.fromUrl(path), │ │204 .local => ui.RoutablePage.fromUrlLocal(path), │ │205 }; │ │206 if (current_page_maybe) |current_page| { │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────╮ │222 var cookie_buf: [256]u8 = undefined; │ │223 var session_cookie: ?[]const u8 = null; │ │224 switch (host) { │ │225 - .remote => |remote| { │ │225 + .server => |server| { │ │226 user_id = blk: { │ │227 const token = getCookieValue(request, cookie_name) orelse break :blk null;│ │228 - if (!remote.session_store.lookup(token, &user_id_buf)) break :blk null; │ │228 + if (!server.session_store.lookup(token, &user_id_buf)) break :blk null; │ │229 break :blk user_id_buf[0..evt.event_id_size]; │ │230 }; │ │231 // whoever seeded the store may have left a session to claim │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │232 if (user_id == null) { │ │233 var token: [SessionStore.token_hex_len]u8 = undefined; │ │234 - if (remote.session_store.autoLogin(&token) and remote.session_store.lookup(&token, &user_id_buf)) {│ │234 + if (server.session_store.autoLogin(&token) and server.session_store.lookup(&token, &user_id_buf)) {│ │235 session_cookie = try std.fmt.bufPrint(&cookie_buf, session_cookie_fmt, .{token}); │ │236 user_id = user_id_buf[0..evt.event_id_size]; │ │237 } │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────╮ │238 } │ │239 if (getCookieValue(request, form_flash_cookie)) |token| { │ │240 form_cookie_seen = true; │ │241 - form_feedback = remote.session_store.takeFlash(form_arena.allocator(), token);│ │241 + form_feedback = server.session_store.takeFlash(form_arena.allocator(), token);│ │242 } │ │243 }, │ │244 .local => { │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │262 } │ │263 │ │264 const git_http_port: ?u16, const git_ssh_port: ?u16, const git_ssh_prefix: []const u8 = switch (host) {│ │265 - .remote => |remote| .{ remote.git_http_port, remote.git_ssh_port, remote.git_ssh_prefix }, │ │265 + .server => |server| .{ server.git_http_port, server.git_ssh_port, server.git_ssh_prefix }, │ │266 .local => .{ null, null, "" }, │ │267 }; │ │268 const html = renderIndexHtml(io, allocator, host, .{ │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────╮ │next →│ ╰──────╯