const std = @import("std"); const http_api = @import("../../http/api.zig"); const entries = @import("web_drawings").entries; pub const slots = @import("icons/slots.zig"); pub fn decorate(allocator: std.mem.Allocator, html: []const u8) ![]const u8 { if (entries.len == 0) return html; const position = std.mem.lastIndexOf(u8, html, "") orelse return error.MissingPageBody; var out: std.Io.Writer.Allocating = .init(allocator); try out.writer.writeAll(html[0..position]); try out.writer.writeAll(""); try out.writer.writeAll(html[position..]); return out.toOwnedSlice(); } pub fn serve(request: *http_api.Request) !void { var buffer: [256]u8 = undefined; const cid = http_api.queryParam(request.url.raw, "cid", &buffer) orelse ""; inline for (entries) |entry| { if (std.mem.eql(u8, cid, entry.cid)) { return http_api.respond(request, .ok, entry.png, &.{ .{ .name = "content-type", .value = "image/png" }, .{ .name = "cache-control", .value = "public, max-age=31536000, immutable" }, .{ .name = "x-content-type-options", .value = "nosniff" }, }); } } try http_api.respond(request, .not_found, "Icon not found", &.{.{ .name = "cache-control", .value = "no-store" }}); }