srctree

Gregory Mullen parent f6441a08 7b63fe5e
update to verse response data

src/api.zig added: 33, removed: 54, total 0
@@ -25,12 +25,10 @@ const APIRouteData = struct {
alloc: Allocator,
version: usize = 0,
 
pub fn init(a: Allocator) !*APIRouteData {
const rd = try a.create(APIRouteData);
rd.* = .{
pub fn init(a: Allocator) !APIRouteData {
return .{
.alloc = a,
};
return rd;
}
};
 
@@ -38,7 +36,7 @@ pub fn router(vrs: *Verse.Frame) Router.RoutingError!Router.BuildFn {
const uri_api = vrs.uri.next() orelse return heartbeat;
if (!std.mem.eql(u8, uri_api, "api")) return heartbeat;
const rd = APIRouteData.init(vrs.alloc) catch @panic("OOM");
vrs.route_data.add("api", rd) catch unreachable;
vrs.response_data.add(rd) catch unreachable;
 
return Router.router(vrs, &endpoints);
}
 
src/endpoints/commit-flex.zig added: 33, removed: 54, total 0
@@ -426,10 +426,7 @@ pub fn commitFlex(ctx: *Verse.Frame) Error!void {
 
var page = UserCommitsPage.init(.{
.meta_head = .{ .open_graph = .{} },
.body_header = (ctx.route_data.get(
"body_header",
*const S.BodyHeaderHtml,
) catch return error.Unknown).*,
.body_header = ctx.response_data.get(S.BodyHeaderHtml) catch return error.Unknown,
.total_hits = try allocPrint(ctx.alloc, "{}", .{tcount}),
.flexes = flexes,
.checked_repos = try allocPrint(ctx.alloc, "{}", .{repo_count}),
 
src/endpoints/gist.zig added: 33, removed: 54, total 0
@@ -100,10 +100,7 @@ fn edit(vrs: *Verse.Frame, files: []const Template.Structs.GistFiles) Error!void
.title = "Create A New Gist",
},
},
.body_header = (vrs.route_data.get(
"body_header",
*const S.BodyHeaderHtml,
) catch return error.Unknown).*,
.body_header = vrs.response_data.get(S.BodyHeaderHtml) catch return error.Unknown,
.gist_files = files,
});
 
 
src/endpoints/repos.zig added: 33, removed: 54, total 0
@@ -124,17 +124,12 @@ pub fn router(ctx: *Verse.Frame) Route.RoutingError!Route.BuildFn {
const rd = RouteData.make(&ctx.uri) orelse return list;
 
if (rd.exists()) {
var i_count: usize = 0;
var d_count: usize = 0;
var itr = Types.Delta.iterator(ctx.alloc, rd.name);
while (itr.next()) |dlt| {
switch (dlt.attach) {
.diff => d_count += 1,
.issue => i_count += 1,
else => {},
}
dlt.raze(ctx.alloc);
}
var bh: S.BodyHeaderHtml = ctx.response_data.get(S.BodyHeaderHtml) catch .{ .nav = .{
.nav_auth = "Error",
.nav_buttons = undefined,
} };
bh.nav.nav_buttons = ctx.alloc.dupe(S.NavButtons, &(navButtons(ctx) catch @panic("unreachable"))) catch unreachable;
ctx.response_data.add(bh) catch unreachable;
 
if (rd.verb) |_| {
_ = ctx.uri.next();
@@ -297,10 +292,7 @@ fn list(ctx: *Verse.Frame) Error!void {
 
var page = ReposPage.init(.{
.meta_head = .{ .open_graph = .{} },
.body_header = (ctx.route_data.get(
"body_header",
*const S.BodyHeaderHtml,
) catch return error.Unknown).*,
.body_header = ctx.response_data.get(S.BodyHeaderHtml) catch return error.Unknown,
 
.buttons = .{ .buttons = repo_buttons },
.repo_list = repos_compiled,
@@ -494,10 +486,7 @@ fn blame(ctx: *Verse.Frame) Error!void {
 
var page = BlamePage.init(.{
.meta_head = .{ .open_graph = .{} },
.body_header = (ctx.route_data.get(
"body_header",
*const S.BodyHeaderHtml,
) catch return error.Unknown).*,
.body_header = ctx.response_data.get(S.BodyHeaderHtml) catch return error.Unknown,
.filename = Bleach.Html.sanitizeAlloc(ctx.alloc, blame_file) catch unreachable,
.blame_lines = wrapped_blames,
});
@@ -609,10 +598,7 @@ fn blob(vrs: *Verse.Frame, repo: *Git.Repo, pfiles: Git.Tree) Error!void {
 
var page = BlobPage.init(.{
.meta_head = .{ .open_graph = .{} },
.body_header = (vrs.route_data.get(
"body_header",
*const S.BodyHeaderHtml,
) catch return error.Unknown).*,
.body_header = vrs.response_data.get(S.BodyHeaderHtml) catch return error.Unknown,
.repo = uri_repo,
.uri_filename = uri_filename,
.filename = blb.name,
@@ -795,10 +781,7 @@ fn tree(ctx: *Verse.Frame, repo: *Git.Repo, files: *Git.Tree) Error!void {
 
var page = TreePage.init(.{
.meta_head = .{ .open_graph = .{} },
.body_header = (ctx.route_data.get(
"body_header",
*const S.BodyHeaderHtml,
) catch return error.Unknown).*,
.body_header = ctx.response_data.get(S.BodyHeaderHtml) catch return error.Unknown,
.upstream = null,
.repo_name = rd.name,
.repo = try allocPrint(ctx.alloc, "{s}", .{repo_data[0]}),
@@ -831,10 +814,7 @@ fn tagsList(ctx: *Verse.Frame) Error!void {
//var btns = navButtons(ctx) catch return error.Unknown;
var page = TagPage.init(.{
.meta_head = .{ .open_graph = .{} },
.body_header = (ctx.route_data.get(
"body_header",
*const S.BodyHeaderHtml,
) catch return error.Unknown).*,
.body_header = ctx.response_data.get(S.BodyHeaderHtml) catch return error.Unknown,
.upstream = null,
.tags = tstack,
});
 
src/endpoints/settings.zig added: 33, removed: 54, total 0
@@ -35,7 +35,7 @@ fn default(vrs: *Verse.Frame) Router.Error!void {
 
var page = SettingsPage.init(.{
.meta_head = .{ .open_graph = .{} },
.body_header = (vrs.route_data.get("body_header", *const S.BodyHeaderHtml) catch return error.Unknown).*,
.body_header = vrs.response_data.get(S.BodyHeaderHtml) catch return error.Unknown,
.config_blocks = blocks[0..],
});
 
 
src/srctree.zig added: 33, removed: 54, total 0
@@ -3,6 +3,7 @@ const eql = std.mem.eql;
const Verse = @import("verse");
const Router = Verse.Router;
const Template = Verse.template;
const S = Template.Structs;
const Api = @import("api.zig");
//const Types = @import("types.zig");
 
@@ -64,10 +65,16 @@ fn debug(_: *Verse.Frame) Router.Error!void {
}
 
pub fn builder(vrs: *Verse.Frame, call: BuildFn) void {
const bh = vrs.alloc.create(Template.Structs.BodyHeaderHtml) catch unreachable;
const btns = [1]Template.Structs.NavButtons{.{ .name = "inbox", .extra = 0, .url = "/inbox" }};
bh.* = .{ .nav = .{ .nav_auth = "Public2", .nav_buttons = &btns } };
vrs.route_data.add("body_header", bh) catch {};
var bh: S.BodyHeaderHtml = vrs.response_data.get(S.BodyHeaderHtml) catch .{ .nav = .{
.nav_auth = "Error",
.nav_buttons = &btns,
} };
 
bh.nav.nav_auth = if (vrs.user) |usr| n: {
break :n if (usr.username) |un| un else "Error No Username";
} else "Public";
vrs.response_data.add(bh) catch {};
return call(vrs) catch |err| switch (err) {
error.InvalidURI => builder(vrs, notFound), // TODO catch inline
error.BrokenPipe => std.debug.print("client disconnect", .{}),