srctree

Gregory Mullen parent b42964c3 f6441a08
Verse redirect API

src/endpoints/gist.zig added: 22, removed: 39, total 0
@@ -57,10 +57,7 @@ fn post(ctx: *Verse.Frame) Error!void {
const udata = RequestData(GistPost).initMap(ctx.alloc, ctx.request.data) catch return error.BadData;
 
if (udata.file_name.len != udata.file_blob.len) return error.BadData;
const username = if (ctx.user.?.valid())
(ctx.user orelse unreachable).username
else
"public";
const username = if (ctx.user) |usr| usr.username.? else "public";
 
if (udata.new_file != null) {
const files = try ctx.alloc.alloc(Template.Structs.GistFiles, udata.file_name.len + 1);
@@ -88,7 +85,7 @@ fn post(ctx: *Verse.Frame) Error!void {
 
const hash_str: [64]u8 = Gist.new(username, files) catch return error.Unknown;
 
return ctx.redirect("/gist/" ++ hash_str, true) catch unreachable;
return ctx.redirect("/gist/" ++ hash_str, .see_other) catch unreachable;
}
 
fn new(ctx: *Verse.Frame) Error!void {
 
src/endpoints/repos.zig added: 22, removed: 39, total 0
@@ -275,7 +275,7 @@ fn list(ctx: *Verse.Frame) Error!void {
}, repoSorterNew);
 
var repo_buttons: []const u8 = "";
if (ctx.user.?.valid()) {
if (ctx.user != null and ctx.user.?.valid()) {
repo_buttons =
\\<div class="act-btns"><a class="btn" href="/admin/clone-upstream">New Upstream</a></div>
;
 
src/endpoints/repos/diffs.zig added: 22, removed: 39, total 0
@@ -178,10 +178,7 @@ fn createDiff(vrs: *Verse.Frame) Error!void {
rd.name,
udata.title,
udata.desc,
if (vrs.user.?.valid())
(vrs.user orelse unreachable).username
else
try allocPrint(vrs.alloc, "REMOTE_ADDR {s}", .{remote_addr}),
if (vrs.user) |usr| usr.username.? else try allocPrint(vrs.alloc, "REMOTE_ADDR {s}", .{remote_addr}),
) catch unreachable;
delta.commit() catch unreachable;
std.debug.print("commit id {x}\n", .{delta.index});
@@ -195,7 +192,7 @@ fn createDiff(vrs: *Verse.Frame) Error!void {
file.writer().writeAll(data.blob) catch unreachable;
var buf: [2048]u8 = undefined;
const loc = try std.fmt.bufPrint(&buf, "/repo/{s}/diffs/{x}", .{ rd.name, delta.index });
return vrs.redirect(loc, true) catch unreachable;
return vrs.redirect(loc, .see_other) catch unreachable;
}
}
 
@@ -212,18 +209,15 @@ fn newComment(ctx: *Verse.Frame) Error!void {
const loc = try std.fmt.bufPrint(&buf, "/repo/{s}/diffs/{x}", .{ rd.name, delta_index });
 
const msg = try valid.require("comment");
if (msg.value.len < 2) return ctx.redirect(loc, true) catch unreachable;
if (msg.value.len < 2) return ctx.redirect(loc, .see_other) catch unreachable;
 
var delta = Delta.open(ctx.alloc, rd.name, delta_index) catch unreachable orelse return error.Unrouteable;
const username = if (ctx.user.?.valid())
(ctx.user orelse unreachable).username
else
"public";
const username = if (ctx.user) |usr| usr.username.? else "public";
var thread = delta.loadThread(ctx.alloc) catch unreachable;
thread.newComment(ctx.alloc, .{ .author = username, .message = msg.value }) catch unreachable;
// TODO record current revision at comment time
delta.commit() catch unreachable;
return ctx.redirect(loc, true) catch unreachable;
return ctx.redirect(loc, .see_other) catch unreachable;
}
return error.Unknown;
}
@@ -727,10 +721,7 @@ fn view(ctx: *Verse.Frame) Error!void {
@panic("oops");
}
 
const username = if (ctx.user.?.valid())
(ctx.user orelse unreachable).username
else
"public";
const username = if (ctx.user) |usr| usr.username.? else "public";
 
var page = DiffViewPage.init(.{
.meta_head = .{ .open_graph = .{} },
 
src/endpoints/repos/issues.zig added: 22, removed: 39, total 0
@@ -75,21 +75,18 @@ fn newPost(ctx: *Verse.Frame) Error!void {
rd.name,
valid.title,
valid.desc,
if (ctx.user.?.valid())
(ctx.user orelse unreachable).username
else
try allocPrint(ctx.alloc, "remote_address", .{}),
if (ctx.user) |usr| usr.username.? else try allocPrint(ctx.alloc, "remote_address", .{}),
) catch unreachable;
 
delta.attach = .{ .issue = 0 };
delta.commit() catch unreachable;
 
const loc = try std.fmt.bufPrint(&buf, "/repo/{s}/issues/{x}", .{ rd.name, delta.index });
return ctx.redirect(loc, true) catch unreachable;
return ctx.redirect(loc, .see_other) catch unreachable;
}
 
const loc = try std.fmt.bufPrint(&buf, "/repo/{s}/issue/new", .{rd.name});
return ctx.redirect(loc, true) catch unreachable;
return ctx.redirect(loc, .see_other) catch unreachable;
}
 
fn newComment(ctx: *Verse.Frame) Error!void {
@@ -105,17 +102,14 @@ fn newComment(ctx: *Verse.Frame) Error!void {
rd.name,
issue_index,
) catch unreachable orelse return error.Unrouteable;
const username = if (ctx.user.?.valid())
(ctx.user orelse unreachable).username
else
"public";
const username = if (ctx.user) |usr| usr.username.? else "public";
 
var thread = delta.loadThread(ctx.alloc) catch unreachable;
thread.newComment(ctx.alloc, .{ .author = username, .message = msg.value }) catch {};
delta.commit() catch unreachable;
var buf: [2048]u8 = undefined;
const loc = try std.fmt.bufPrint(&buf, "/repo/{s}/issues/{x}", .{ rd.name, issue_index });
ctx.redirect(loc, true) catch unreachable;
ctx.redirect(loc, .see_other) catch unreachable;
return;
}
return error.Unknown;
 
src/endpoints/settings.zig added: 22, removed: 39, total 0
@@ -56,5 +56,5 @@ fn post(vrs: *Verse.Frame) Router.Error!void {
std.debug.print("block data:\nname '{s}'\ntext '''{s}'''\n", .{ name, text });
}
 
return vrs.redirect("/settings", true) catch unreachable;
return vrs.redirect("/settings", .see_other) catch unreachable;
}
 
src/srctree.zig added: 22, removed: 39, total 0
@@ -71,6 +71,7 @@ pub fn builder(vrs: *Verse.Frame, call: BuildFn) void {
return call(vrs) catch |err| switch (err) {
error.InvalidURI => builder(vrs, notFound), // TODO catch inline
error.BrokenPipe => std.debug.print("client disconnect", .{}),
error.IOWriteFailure => @panic("Unexpected IOWrite"),
error.Unrouteable => {
std.debug.print("Unrouteable", .{});
if (@errorReturnTrace()) |trace| {