const std = @import("std");
const build_options = @import("build_options");
const http_api = @import("../http/api.zig");
const icons = @import("web/icons.zig");
const skin = @import("web/skin.zig");
const http = std.http;
/// Serves the resident account page. The whole document is built at compile
/// time, once per skin (with and without the served font face); a request
/// only picks the selected copy.
pub fn page(request: *http_api.Request) !void {
switch (skin.current()) {
inline else => |selected| {
const body = if (skin.fontServed()) comptime render(selected, true) else comptime render(selected, false);
try http_api.respond(request, .ok, body, &html_headers);
},
}
}
pub fn redirectToSecurity(request: *http_api.Request) !void {
try redirect(request, "/account/manage");
}
pub fn redirectToSpaces(request: *http_api.Request) !void {
try redirect(request, "/account/spaces");
}
fn redirect(request: *http_api.Request, location: []const u8) !void {
const headers = [_]http.Header{
.{ .name = "location", .value = location },
.{ .name = "access-control-allow-origin", .value = "*" },
.{ .name = "connection", .value = "close" },
};
try http_api.respondNowClose(request, .see_other, "", &headers);
}
// Presentation stays in replaceable static assets under web/, outside account
// and protocol logic: the page calls existing XRPCs and nothing else.
const template = @embedFile("web/account.html");
const shared_head = "";
const license = @embedFile("web/lucide-license.html");
fn render(comptime selected: skin.Skin, comptime with_font: bool) []const u8 {
comptime {
@setEvalBranchQuota(1_000_000);
const head_end = std.mem.indexOf(u8, template, "").?;
const body_end = std.mem.lastIndexOf(u8, template, "