srctree

Gregory Mullen parent 0bab1081 0227e908
unverified migration to new verse API

src/api.zig added: 118, removed: 119, total 0
@@ -34,7 +34,7 @@ const APIRouteData = struct {
}
};
 
pub fn router(vrs: *Verse) Router.RoutingError!Router.BuildFn {
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");
@@ -47,7 +47,7 @@ const Diff = struct {
sha: []const u8,
};
 
fn diff(vrs: *Verse) Router.Error!void {
fn diff(vrs: *Verse.Frame) Router.Error!void {
return try vrs.sendJSON([0]Diff{}, .ok);
}
 
@@ -55,7 +55,7 @@ const HeartBeat = struct {
nice: usize = 0,
};
 
fn heartbeat(vrs: *Verse) Router.Error!void {
fn heartbeat(vrs: *Verse.Frame) Router.Error!void {
return try vrs.sendJSON(HeartBeat{ .nice = 69 }, .ok);
}
 
@@ -63,7 +63,7 @@ const Issue = struct {
index: usize,
};
 
fn issue(vrs: *Verse) Router.Error!void {
fn issue(vrs: *Verse.Frame) Router.Error!void {
return try vrs.sendJSON([0]Issue{}, .ok);
}
 
@@ -82,7 +82,7 @@ const Network = struct {
networks: []RemotePeer,
};
 
fn network(vrs: *Verse) Router.Error!void {
fn network(vrs: *Verse.Frame) Router.Error!void {
return try vrs.sendJSON(Network{ .networks = [0].{} }, .ok);
}
 
@@ -90,7 +90,7 @@ const Patch = struct {
patch: []const u8,
};
 
fn patch(vrs: *Verse) Router.Error!void {
fn patch(vrs: *Verse.Frame) Router.Error!void {
return try vrs.sendJSON(Patch{ .patch = [0].{} }, .ok);
}
 
@@ -102,7 +102,7 @@ const Flex = struct {
};
};
 
fn flex(vrs: *Verse) Router.Error!void {
fn flex(vrs: *Verse.Frame) Router.Error!void {
return try vrs.sendJSON([0]Flex{}, .ok);
}
 
@@ -111,6 +111,6 @@ const User = struct {
email: []const u8,
};
 
fn user(vrs: *Verse) Router.Error!void {
fn user(vrs: *Verse.Frame) Router.Error!void {
return try vrs.sendJSON([0]User{}, .ok);
}
 
src/api/repo.zig added: 118, removed: 119, total 0
@@ -14,7 +14,7 @@ const endpoints = [_]Router.Match{
ROUTE("tags", repoTags),
};
 
pub fn router(ctx: *API.Verse) Router.RoutingError!Router.BuildFn {
pub fn router(ctx: *API.Verse.Frame) Router.RoutingError!Router.BuildFn {
const uri_api = ctx.uri.next() orelse return repo;
if (!std.mem.eql(u8, uri_api, "repo")) return repo;
 
@@ -45,7 +45,7 @@ fn openRepo(a: Allocator, raw_name: []const u8) !Git.Repo {
return gitrepo;
}
 
pub fn repo(ctx: *API.Verse) API.Router.Error!void {
pub fn repo(ctx: *API.Verse.Frame) API.Router.Error!void {
const req = try ctx.request.data.validate(RepoRequest);
 
var gitrepo = openRepo(ctx.alloc, req.name) catch |err| switch (err) {
@@ -84,7 +84,7 @@ pub const RepoBranches = struct {
branches: []const Branch,
};
 
pub fn repoBranches(ctx: *API.Verse) API.Router.Error!void {
pub fn repoBranches(ctx: *API.Verse.Frame) API.Router.Error!void {
const req = try ctx.request.data.validate(RepoRequest);
 
var gitrepo = openRepo(ctx.alloc, req.name) catch |err| switch (err) {
@@ -121,7 +121,7 @@ pub const RepoTags = struct {
tags: []const []const u8,
};
 
pub fn repoTags(ctx: *API.Verse) API.Router.Error!void {
pub fn repoTags(ctx: *API.Verse.Frame) API.Router.Error!void {
const req = try ctx.request.data.validate(RepoRequest);
 
var gitrepo = openRepo(ctx.alloc, req.name) catch |err| switch (err) {
 
src/endpoints/admin.zig added: 118, removed: 119, total 0
@@ -5,8 +5,8 @@ const Allocator = std.mem.Allocator;
const Verse = @import("verse");
const Route = Verse.Router;
const Template = Verse.Template;
const HTML = Template.HTML;
const DOM = Template.DOM;
const HTML = Verse.html;
const DOM = HTML.DOM;
 
const Error = Route.Error;
const UriIter = Route.UriIter;
@@ -39,8 +39,8 @@ const AdminPage = Template.PageData("admin.html");
/// TODO fix me
const btns = [1]Template.Structs.NavButtons{.{ .name = "inbox", .extra = 0, .url = "/inbox" }};
 
fn default(ctx: *Verse) Error!void {
try ctx.auth.requireValid();
fn default(ctx: *Verse.Frame) Error!void {
//try ctx.auth.requireValid();
var dom = DOM.new(ctx.alloc);
const action = "/admin/post";
dom = dom.open(HTML.form(null, &[_]HTML.Attr{
@@ -69,8 +69,8 @@ fn default(ctx: *Verse) Error!void {
try ctx.sendPage(&page);
}
 
fn cloneUpstream(ctx: *Verse) Error!void {
try ctx.auth.requireValid();
fn cloneUpstream(ctx: *Verse.Frame) Error!void {
//try ctx.auth.requireValid();
var dom = DOM.new(ctx.alloc);
const action = "/admin/clone-upstream";
dom = dom.open(HTML.form(null, &[_]HTML.Attr{
@@ -103,8 +103,8 @@ const CloneUpstreamReq = struct {
repo_uri: []const u8,
};
 
fn postCloneUpstream(ctx: *Verse) Error!void {
try ctx.auth.requireValid();
fn postCloneUpstream(ctx: *Verse.Frame) Error!void {
//try ctx.auth.requireValid();
 
const udata = ctx.request.data.post.?.validate(CloneUpstreamReq) catch return error.BadData;
std.debug.print("repo uri {s}\n", .{udata.repo_uri});
@@ -149,8 +149,8 @@ fn postCloneUpstream(ctx: *Verse) Error!void {
try ctx.sendPage(&page);
}
 
fn postNewRepo(ctx: *Verse) Error!void {
try ctx.auth.requireValid();
fn postNewRepo(ctx: *Verse.Frame) Error!void {
//try ctx.auth.requireValid();
// TODO ini repo dir
var valid = if (ctx.request.data.post) |p|
p.validator()
@@ -202,8 +202,8 @@ fn postNewRepo(ctx: *Verse) Error!void {
try ctx.sendPage(&page);
}
 
fn newRepo(ctx: *Verse) Error!void {
try ctx.auth.requireValid();
fn newRepo(ctx: *Verse.Frame) Error!void {
//try ctx.auth.requireValid();
var dom = DOM.new(ctx.alloc);
const action = "/admin/new-repo";
dom = dom.open(HTML.form(null, &[_]HTML.Attr{
@@ -230,8 +230,8 @@ fn newRepo(ctx: *Verse) Error!void {
try ctx.sendPage(&page);
}
 
fn view(ctx: *Verse) Error!void {
try ctx.auth.requireValid();
fn view(ctx: *Verse.Frame) Error!void {
//try ctx.auth.requireValid();
if (ctx.request.data.post) |pd| {
std.debug.print("{any}\n", .{pd.items});
return newRepo(ctx);
 
src/endpoints/commit-flex.zig added: 118, removed: 119, total 0
@@ -233,7 +233,7 @@ const YEAR = 31_536_000;
 
const UserCommitsPage = Template.PageData("user_commits.html");
 
pub fn commitFlex(ctx: *Verse) Error!void {
pub fn commitFlex(ctx: *Verse.Frame) Error!void {
const monthAtt = HTML.Attr.class("month");
 
var nowish = DateTime.now();
@@ -453,8 +453,8 @@ const global_config = &@import("../main.zig").global_config;
 
const Verse = @import("verse");
const Template = Verse.Template;
const DOM = Template.DOM;
const HTML = Template.HTML;
const DOM = Verse.html.DOM;
const HTML = Verse.html;
const S = Template.Structs;
 
const Route = Verse.Router;
 
src/endpoints/gist.zig added: 118, removed: 119, total 0
@@ -26,7 +26,7 @@ const endpoints = [_]Router.Match{
POST("post", post),
};
 
pub fn router(ctx: *Verse) Router.RoutingError!Router.BuildFn {
pub fn router(ctx: *Verse.Frame) Router.RoutingError!Router.BuildFn {
if (!std.mem.eql(u8, ctx.uri.next() orelse "", "gist")) return error.Unrouteable;
 
if (ctx.uri.peek()) |peek| {
@@ -51,14 +51,14 @@ const GistPost = struct {
new_file: ?[]const u8,
};
 
fn post(ctx: *Verse) Error!void {
try ctx.auth.requireValid();
fn post(ctx: *Verse.Frame) Error!void {
//try ctx.auth.requireValid();
 
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.auth.valid())
(ctx.auth.current_user orelse unreachable).username
const username = if (ctx.user.?.valid())
(ctx.user orelse unreachable).username
else
"public";
 
@@ -91,12 +91,12 @@ fn post(ctx: *Verse) Error!void {
return ctx.redirect("/gist/" ++ hash_str, true) catch unreachable;
}
 
fn new(ctx: *Verse) Error!void {
fn new(ctx: *Verse.Frame) Error!void {
const files = [1]Template.Structs.GistFiles{.{}};
return edit(ctx, &files);
}
 
fn edit(vrs: *Verse, files: []const Template.Structs.GistFiles) Error!void {
fn edit(vrs: *Verse.Frame, files: []const Template.Structs.GistFiles) Error!void {
var page = GistNewPage.init(.{
.meta_head = .{
.open_graph = .{
@@ -124,7 +124,7 @@ fn toTemplate(a: Allocator, files: []const Gist.File) ![]Template.Structs.GistFi
return out;
}
 
fn view(vrs: *Verse) Error!void {
fn view(vrs: *Verse.Frame) Error!void {
// TODO move this back into context somehow
var btns = [1]Template.Structs.NavButtons{.{ .name = "inbox", .extra = 0, .url = "/inbox" }};
 
 
src/endpoints/network.zig added: 118, removed: 119, total 0
@@ -3,8 +3,7 @@ const allocPrint = std.fmt.allocPrint;
 
const Verse = @import("verse");
const Template = Verse.Template;
const DOM = Template.DOM;
const HTML = Template.HTML;
const DOM = Verse.html.DOM;
 
const Route = Verse.Router;
const Error = Route.Error;
@@ -21,7 +20,7 @@ pub const endpoints = [_]Route.Match{
 
const NetworkPage = Template.PageData("network.html");
 
fn default(ctx: *Verse) Error!void {
fn default(ctx: *Verse.Frame) Error!void {
var dom = DOM.new(ctx.alloc);
 
const list = try Repos.allNames(ctx.alloc);
@@ -35,10 +34,10 @@ fn default(ctx: *Verse) Error!void {
defer repo.raze();
if (repo.findRemote("upstream") catch continue) |remote| {
if (remote.url) |_| {
dom = dom.open(HTML.h3(null, &HTML.Attr.class("upstream")));
dom.push(HTML.text("Upstream: "));
dom = dom.open(Verse.html.h3(null, &Verse.html.Attr.class("upstream")));
dom.push(Verse.html.text("Upstream: "));
const purl = try allocPrint(ctx.alloc, "{link}", .{remote});
dom.push(HTML.anch(purl, try HTML.Attr.create(ctx.alloc, "href", purl)));
dom.push(Verse.html.anch(purl, try Verse.html.Attr.create(ctx.alloc, "href", purl)));
dom = dom.close();
}
}
 
src/endpoints/repos.zig added: 118, removed: 119, total 0
@@ -9,8 +9,8 @@ const splitScalar = std.mem.splitScalar;
const Verse = @import("verse");
const Request = Verse.Request;
const Template = Verse.Template;
const HTML = Template.HTML;
const DOM = Template.DOM;
const HTML = Verse.html;
const DOM = Verse.html.DOM;
const Route = Verse.Router;
const S = Template.Structs;
const elm = HTML.element;
@@ -90,7 +90,7 @@ pub const RouteData = struct {
}
};
 
pub fn navButtons(ctx: *Verse) ![2]Template.Structs.NavButtons {
pub fn navButtons(ctx: *Verse.Frame) ![2]Template.Structs.NavButtons {
const rd = RouteData.make(&ctx.uri) orelse unreachable;
if (!rd.exists()) unreachable;
var i_count: usize = 0;
@@ -121,7 +121,7 @@ pub fn navButtons(ctx: *Verse) ![2]Template.Structs.NavButtons {
return btns;
}
 
pub fn router(ctx: *Verse) Route.RoutingError!Route.BuildFn {
pub fn router(ctx: *Verse.Frame) Route.RoutingError!Route.BuildFn {
const rd = RouteData.make(&ctx.uri) orelse return list;
 
if (rd.exists()) {
@@ -247,7 +247,7 @@ const RepoSortReq = struct {
sort: ?[]const u8,
};
 
fn list(ctx: *Verse) Error!void {
fn list(ctx: *Verse.Frame) Error!void {
var cwd = std.fs.cwd();
 
const udata = ctx.request.data.query.validate(RepoSortReq) catch return error.BadData;
@@ -276,7 +276,7 @@ fn list(ctx: *Verse) Error!void {
}, repoSorterNew);
 
var repo_buttons: []const u8 = "";
if (ctx.auth.valid()) {
if (ctx.user.?.valid()) {
repo_buttons =
\\<div class="act-btns"><a class="btn" href="/admin/clone-upstream">New Upstream</a></div>
;
@@ -322,13 +322,13 @@ fn dupeDir(a: Allocator, name: []const u8) ![]u8 {
}
 
const NewRepoPage = Template.PageData("repo-new.html");
fn newRepo(ctx: *Verse) Error!void {
fn newRepo(ctx: *Verse.Frame) Error!void {
ctx.status = .ok;
 
return error.NotImplemented;
}
 
fn treeBlob(ctx: *Verse) Error!void {
fn treeBlob(ctx: *Verse.Frame) Error!void {
const rd = RouteData.make(&ctx.uri) orelse return error.Unrouteable;
_ = ctx.uri.next();
 
@@ -453,7 +453,7 @@ fn parseBlame(a: Allocator, blame_txt: []const u8) !struct {
 
const BlamePage = Template.PageData("blame.html");
 
fn blame(ctx: *Verse) Error!void {
fn blame(ctx: *Verse.Frame) Error!void {
const rd = RouteData.make(&ctx.uri) orelse return error.Unrouteable;
std.debug.assert(std.mem.eql(u8, rd.verb orelse "", "blame"));
_ = ctx.uri.next();
@@ -563,7 +563,7 @@ fn excludedExt(name: []const u8) bool {
 
const BlobPage = Template.PageData("blob.html");
 
fn blob(vrs: *Verse, repo: *Git.Repo, pfiles: Git.Tree) Error!void {
fn blob(vrs: *Verse.Frame, repo: *Git.Repo, pfiles: Git.Tree) Error!void {
var blb: Git.Blob = undefined;
 
var files = pfiles;
@@ -710,7 +710,7 @@ fn drawTree(a: Allocator, ddom: *DOM, rname: []const u8, base: []const u8, obj:
 
const TreePage = Template.PageData("tree.html");
 
fn tree(ctx: *Verse, repo: *Git.Repo, files: *Git.Tree) Error!void {
fn tree(ctx: *Verse.Frame, repo: *Git.Repo, files: *Git.Tree) Error!void {
//const head = if (repo.head) |h| switch (h) {
// .sha => |s| s.hex[0..],
// .branch => |b| b.name,
@@ -811,7 +811,7 @@ fn tree(ctx: *Verse, repo: *Git.Repo, files: *Git.Tree) Error!void {
 
const TagPage = Template.PageData("repo-tags.html");
 
fn tagsList(ctx: *Verse) Error!void {
fn tagsList(ctx: *Verse.Frame) Error!void {
const rd = RouteData.make(&ctx.uri) orelse return error.Unrouteable;
 
var cwd = std.fs.cwd();
 
src/endpoints/repos/commits.zig added: 118, removed: 119, total 0
@@ -44,14 +44,14 @@ const AddComment = struct {
text: []const u8,
};
 
pub fn router(ctx: *Verse) Route.RoutingError!Route.BuildFn {
pub fn router(ctx: *Verse.Frame) Route.RoutingError!Route.BuildFn {
const rd = RouteData.make(&ctx.uri) orelse return commitsView;
if (rd.verb != null and std.mem.eql(u8, "commit", rd.verb.?))
return viewCommit;
return commitsView;
}
 
fn newComment(ctx: *Verse) Error!void {
fn newComment(ctx: *Verse.Frame) Error!void {
if (ctx.request.data.post) |post| {
_ = post.validate(AddComment) catch return error.BadData;
}
@@ -72,7 +72,7 @@ pub fn patchVerse(a: Allocator, patch: *Patch.Patch) ![]Template.Context {
return try patch.diffsVerseSlice(a);
}
 
fn commitHtml(ctx: *Verse, sha: []const u8, repo_name: []const u8, repo: Git.Repo) Error!void {
fn commitHtml(ctx: *Verse.Frame, sha: []const u8, repo_name: []const u8, repo: Git.Repo) Error!void {
if (!Git.commitish(sha)) {
std.debug.print("Abusive ''{s}''\n", .{sha});
return error.Abusive;
@@ -180,7 +180,7 @@ fn commitHtml(ctx: *Verse, sha: []const u8, repo_name: []const u8, repo: Git.Rep
return ctx.sendPage(&page) catch unreachable;
}
 
pub fn commitPatch(ctx: *Verse, sha: []const u8, repo: Git.Repo) Error!void {
pub fn commitPatch(ctx: *Verse.Frame, sha: []const u8, repo: Git.Repo) Error!void {
var acts = repo.getAgent(ctx.alloc);
if (endsWith(u8, sha, ".patch")) {
var rbuf: [0xff]u8 = undefined;
@@ -198,7 +198,7 @@ pub fn commitPatch(ctx: *Verse, sha: []const u8, repo: Git.Repo) Error!void {
}
}
 
pub fn viewCommit(ctx: *Verse) Error!void {
pub fn viewCommit(ctx: *Verse.Frame) Error!void {
const rd = RouteData.make(&ctx.uri) orelse return error.Unrouteable;
if (rd.verb == null) return commitsView(ctx);
 
@@ -370,7 +370,7 @@ fn buildListBetween(
return commits;
}
 
pub fn commitsView(ctx: *Verse) Error!void {
pub fn commitsView(ctx: *Verse.Frame) Error!void {
const rd = RouteData.make(&ctx.uri) orelse return error.Unrouteable;
 
if (ctx.uri.next()) |next| {
@@ -409,7 +409,7 @@ pub fn commitsView(ctx: *Verse) Error!void {
return sendCommits(ctx, cmts_list, rd.name, last_sha.hex[0..8]);
}
 
pub fn commitsBefore(ctx: *Verse) Error!void {
pub fn commitsBefore(ctx: *Verse.Frame) Error!void {
const rd = RouteData.make(&ctx.uri) orelse return error.Unrouteable;
 
std.debug.assert(std.mem.eql(u8, "after", ctx.uri.next().?));
@@ -427,7 +427,7 @@ pub fn commitsBefore(ctx: *Verse) Error!void {
return sendCommits(ctx, cmts_list, rd.name, last_sha[0..]);
}
 
fn sendCommits(ctx: *Verse, list: []const S.Commits, repo_name: []const u8, sha: []const u8) Error!void {
fn sendCommits(ctx: *Verse.Frame, list: []const S.Commits, repo_name: []const u8, sha: []const u8) Error!void {
const meta_head = S.MetaHeadHtml{ .open_graph = .{} };
 
var page = CommitsListPage.init(.{
 
src/endpoints/repos/diffs.zig added: 118, removed: 119, total 0
@@ -52,7 +52,7 @@ fn isHex(input: []const u8) ?usize {
return std.fmt.parseInt(usize, input, 16) catch null;
}
 
pub fn router(ctx: *Verse) Route.RoutingError!Route.BuildFn {
pub fn router(ctx: *Verse.Frame) Route.RoutingError!Route.BuildFn {
if (!eql(u8, "diffs", ctx.uri.next() orelse return error.Unrouteable))
return error.Unrouteable;
const verb = ctx.uri.peek() orelse return Route.router(ctx, &routes);
@@ -80,7 +80,7 @@ const DiffCreateChangeReq = struct {
desc: []const u8,
};
 
fn new(ctx: *Verse) Error!void {
fn new(ctx: *Verse.Frame) Error!void {
var network: ?S.Network = null;
var patchuri: ?S.PatchUri = .{};
var title: ?[]const u8 = null;
@@ -158,7 +158,7 @@ const DiffCreateReq = struct {
//},
};
 
fn createDiff(vrs: *Verse) Error!void {
fn createDiff(vrs: *Verse.Frame) Error!void {
const rd = Repos.RouteData.make(&vrs.uri) orelse return error.Unrouteable;
if (vrs.request.data.post) |post| {
const udata = post.validate(DiffCreateReq) catch return error.BadData;
@@ -178,8 +178,8 @@ fn createDiff(vrs: *Verse) Error!void {
rd.name,
udata.title,
udata.desc,
if (vrs.auth.valid())
(vrs.auth.current_user orelse unreachable).username
if (vrs.user.?.valid())
(vrs.user orelse unreachable).username
else
try allocPrint(vrs.alloc, "REMOTE_ADDR {s}", .{remote_addr}),
) catch unreachable;
@@ -202,7 +202,7 @@ fn createDiff(vrs: *Verse) Error!void {
return try new(vrs);
}
 
fn newComment(ctx: *Verse) Error!void {
fn newComment(ctx: *Verse.Frame) Error!void {
const rd = Repos.RouteData.make(&ctx.uri) orelse return error.Unrouteable;
var buf: [2048]u8 = undefined;
if (ctx.request.data.post) |post| {
@@ -215,8 +215,8 @@ fn newComment(ctx: *Verse) Error!void {
if (msg.value.len < 2) return ctx.redirect(loc, true) catch unreachable;
 
var delta = Delta.open(ctx.alloc, rd.name, delta_index) catch unreachable orelse return error.Unrouteable;
const username = if (ctx.auth.valid())
(ctx.auth.current_user orelse unreachable).username
const username = if (ctx.user.?.valid())
(ctx.user orelse unreachable).username
else
"public";
var thread = delta.loadThread(ctx.alloc) catch unreachable;
@@ -228,7 +228,7 @@ fn newComment(ctx: *Verse) Error!void {
return error.Unknown;
}
 
pub fn directReply(ctx: *Verse) Error!void {
pub fn directReply(ctx: *Verse.Frame) Error!void {
_ = ctx.uri.next().?;
_ = ctx.uri.next().?;
std.debug.print("{s}\n", .{ctx.uri.next().?});
@@ -626,7 +626,7 @@ fn translateComment(a: Allocator, comment: []const u8, patch: Patch, repo: *cons
 
const DiffViewPage = Template.PageData("delta-diff.html");
 
fn view(ctx: *Verse) Error!void {
fn view(ctx: *Verse.Frame) Error!void {
const rd = Repos.RouteData.make(&ctx.uri) orelse return error.Unrouteable;
 
var cwd = std.fs.cwd();
@@ -727,8 +727,8 @@ fn view(ctx: *Verse) Error!void {
@panic("oops");
}
 
const username = if (ctx.auth.valid())
(ctx.auth.current_user orelse unreachable).username
const username = if (ctx.user.?.valid())
(ctx.user orelse unreachable).username
else
"public";
 
@@ -754,7 +754,7 @@ fn view(ctx: *Verse) Error!void {
}
 
const DeltaListPage = Template.PageData("delta-list.html");
fn list(ctx: *Verse) Error!void {
fn list(ctx: *Verse.Frame) Error!void {
const rd = Repos.RouteData.make(&ctx.uri) orelse return error.Unrouteable;
 
const last = Delta.last(rd.name) + 1;
 
src/endpoints/repos/issues.zig added: 118, removed: 119, total 0
@@ -37,7 +37,7 @@ fn isHex(input: []const u8) ?usize {
return std.fmt.parseInt(usize, input, 16) catch null;
}
 
pub fn router(ctx: *Verse) Route.RoutingError!Route.BuildFn {
pub fn router(ctx: *Verse.Frame) Route.RoutingError!Route.BuildFn {
std.debug.assert(std.mem.eql(u8, "issues", ctx.uri.next().?));
const verb = ctx.uri.peek() orelse return Route.router(ctx, &routes);
 
@@ -50,7 +50,7 @@ pub fn router(ctx: *Verse) Route.RoutingError!Route.BuildFn {
 
const IssueNewPage = Template.PageData("issue-new.html");
 
fn new(ctx: *Verse) Error!void {
fn new(ctx: *Verse.Frame) Error!void {
const meta_head = S.MetaHeadHtml{ .open_graph = .{} };
var page = IssueNewPage.init(.{
.meta_head = meta_head,
@@ -66,7 +66,7 @@ const IssueCreate = struct {
desc: []const u8,
};
 
fn newPost(ctx: *Verse) Error!void {
fn newPost(ctx: *Verse.Frame) Error!void {
const rd = Repos.RouteData.make(&ctx.uri) orelse return error.Unrouteable;
var buf: [2048]u8 = undefined;
if (ctx.request.data.post) |post| {
@@ -75,8 +75,8 @@ fn newPost(ctx: *Verse) Error!void {
rd.name,
valid.title,
valid.desc,
if (ctx.auth.valid())
(ctx.auth.current_user orelse unreachable).username
if (ctx.user.?.valid())
(ctx.user orelse unreachable).username
else
try allocPrint(ctx.alloc, "remote_address", .{}),
) catch unreachable;
@@ -92,7 +92,7 @@ fn newPost(ctx: *Verse) Error!void {
return ctx.redirect(loc, true) catch unreachable;
}
 
fn newComment(ctx: *Verse) Error!void {
fn newComment(ctx: *Verse.Frame) Error!void {
const rd = Repos.RouteData.make(&ctx.uri) orelse return error.Unrouteable;
if (ctx.request.data.post) |post| {
var valid = post.validator();
@@ -105,8 +105,8 @@ fn newComment(ctx: *Verse) Error!void {
rd.name,
issue_index,
) catch unreachable orelse return error.Unrouteable;
const username = if (ctx.auth.valid())
(ctx.auth.current_user orelse unreachable).username
const username = if (ctx.user.?.valid())
(ctx.user orelse unreachable).username
else
"public";
 
@@ -123,7 +123,7 @@ fn newComment(ctx: *Verse) Error!void {
 
const DeltaIssuePage = Template.PageData("delta-issue.html");
 
fn view(ctx: *Verse) Error!void {
fn view(ctx: *Verse.Frame) Error!void {
const rd = Repos.RouteData.make(&ctx.uri) orelse return error.Unrouteable;
const delta_id = ctx.uri.next().?;
const index = isHex(delta_id) orelse return error.Unrouteable;
@@ -177,7 +177,7 @@ fn view(ctx: *Verse) Error!void {
 
const DeltaListHtml = Template.PageData("delta-list.html");
 
fn list(ctx: *Verse) Error!void {
fn list(ctx: *Verse.Frame) Error!void {
const rd = Repos.RouteData.make(&ctx.uri) orelse return error.Unrouteable;
 
const last = Delta.last(rd.name) + 1;
 
src/endpoints/search.zig added: 118, removed: 119, total 0
@@ -19,7 +19,7 @@ pub const routes = [_]Routes.Match{
ROUTE("inbox", inbox),
};
 
pub fn router(ctx: *Verse) Routes.RoutingError!Routes.BuildFn {
pub fn router(ctx: *Verse.Frame) Routes.RoutingError!Routes.BuildFn {
return Routes.router(ctx, &routes);
}
 
@@ -27,11 +27,11 @@ const SearchReq = struct {
q: ?[]const u8,
};
 
fn inbox(ctx: *Verse) Error!void {
fn inbox(ctx: *Verse.Frame) Error!void {
return custom(ctx, "owner:me");
}
 
fn search(ctx: *Verse) Error!void {
fn search(ctx: *Verse.Frame) Error!void {
const udata = ctx.request.data.query.validate(SearchReq) catch return error.BadData;
 
const query_str = udata.q orelse "null";
@@ -42,7 +42,7 @@ fn search(ctx: *Verse) Error!void {
 
const DeltaListPage = Template.PageData("delta-list.html");
 
fn custom(ctx: *Verse, search_str: []const u8) Error!void {
fn custom(ctx: *Verse.Frame, search_str: []const u8) Error!void {
var rules = std.ArrayList(Delta.SearchRule).init(ctx.alloc);
 
var itr = splitScalar(u8, search_str, ' ');
 
src/endpoints/settings.zig added: 118, removed: 119, total 0
@@ -13,8 +13,8 @@ pub const endpoints = [_]Router.Match{
 
const SettingsPage = Template.PageData("settings.html");
 
fn default(vrs: *Verse) Router.Error!void {
try vrs.auth.requireValid();
fn default(vrs: *Verse.Frame) Router.Error!void {
//try vrs.auth.requireValid();
 
var blocks: []S.ConfigBlocks = &[0]S.ConfigBlocks{};
 
@@ -47,8 +47,8 @@ const SettingsReq = struct {
block_text: [][]const u8,
};
 
fn post(vrs: *Verse) Router.Error!void {
try vrs.auth.requireValid();
fn post(vrs: *Verse.Frame) Router.Error!void {
//try vrs.auth.requireValid();
 
const udata = RequestData(SettingsReq).initMap(vrs.alloc, vrs.request.data) catch return error.BadData;
 
 
src/gitweb.zig added: 118, removed: 119, total 0
@@ -24,12 +24,12 @@ pub const endpoints = [_]Router.Match{
Router.ANY("git-upload-pack", gitUploadPack),
};
 
pub fn router(ctx: *Verse) Router.RoutingError!Router.BuildFn {
pub fn router(ctx: *Verse.Frame) Router.RoutingError!Router.BuildFn {
std.debug.print("gitweb router {s}\n{any}, {any} \n", .{ ctx.ctx.uri.peek().?, ctx.ctx.uri, ctx.request.method });
return Router.router(ctx, &endpoints);
}
 
fn gitUploadPack(ctx: *Verse) Error!void {
fn gitUploadPack(ctx: *Verse.Frame) Error!void {
ctx.uri.reset();
_ = ctx.uri.first();
const name = ctx.uri.next() orelse return error.Unknown;
@@ -105,7 +105,7 @@ fn gitUploadPack(ctx: *Verse) Error!void {
_ = child.wait() catch unreachable;
}
 
fn __objects(ctx: *Verse) Error!void {
fn __objects(ctx: *Verse.Frame) Error!void {
std.debug.print("gitweb objects\n", .{});
 
const rd = @import("endpoints/repos.zig").RouteData.make(&ctx.uri) orelse return error.Unrouteable;
@@ -138,7 +138,7 @@ fn __objects(ctx: *Verse) Error!void {
ctx.sendRawSlice(data) catch return Error.Unknown;
}
 
fn __info(ctx: *Verse) Error!void {
fn __info(ctx: *Verse.Frame) Error!void {
std.debug.print("gitweb info\n", .{});
 
const rd = @import("endpoints/repos.zig").RouteData.make(&ctx.uri) orelse return error.Unrouteable;
 
src/patch.zig added: 118, removed: 119, total 0
@@ -12,8 +12,8 @@ const CURL = @import("curl.zig");
const Bleach = @import("bleach.zig");
const Verse = @import("verse");
const Response = Verse.Response;
const HTML = Verse.Template.HTML;
const DOM = Verse.Template.DOM;
const HTML = Verse.html;
const DOM = Verse.html.DOM;
 
pub const Patch = @This();
 
 
src/srctree.zig added: 118, removed: 119, total 0
@@ -42,14 +42,14 @@ pub const routes = [_]Match{
 
const E404Page = Template.PageData("4XX.html");
 
fn notFound(vrs: *Verse) Router.Error!void {
fn notFound(vrs: *Verse.Frame) Router.Error!void {
std.debug.print("404 for route\n", .{});
vrs.status = .not_found;
var page = E404Page.init(.{});
vrs.sendPage(&page) catch unreachable;
}
 
pub fn router(vrs: *Verse) Router.RoutingError!BuildFn {
pub fn router(vrs: *Verse.Frame) Router.RoutingError!BuildFn {
// var i_count: usize = 0;
// var itr = Types.Delta.iterator(vrs.alloc, "");
// while (itr.next()) |it| {
@@ -59,11 +59,11 @@ pub fn router(vrs: *Verse) Router.RoutingError!BuildFn {
return Router.router(vrs, &routes);
}
 
fn debug(_: *Verse) Router.Error!void {
fn debug(_: *Verse.Frame) Router.Error!void {
return error.Abusive;
}
 
pub fn builder(vrs: *Verse, call: BuildFn) 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 } };