srctree

Gregory Mullen parent b2548e4d b8c0520e
update to new Verse Request.Data api

src/api/repo.zig added: 34, removed: 34, total 0
@@ -46,7 +46,7 @@ fn openRepo(a: Allocator, raw_name: []const u8) !Git.Repo {
}
 
pub fn repo(ctx: *API.Verse) API.Router.Error!void {
const req = try ctx.reqdata.validate(RepoRequest);
const req = try ctx.request.data.validate(RepoRequest);
 
var gitrepo = openRepo(ctx.alloc, req.name) catch |err| switch (err) {
error.InvalidName => return error.Abusive,
@@ -85,7 +85,7 @@ pub const RepoBranches = struct {
};
 
pub fn repoBranches(ctx: *API.Verse) API.Router.Error!void {
const req = try ctx.reqdata.validate(RepoRequest);
const req = try ctx.request.data.validate(RepoRequest);
 
var gitrepo = openRepo(ctx.alloc, req.name) catch |err| switch (err) {
error.InvalidName => return error.Abusive,
@@ -122,7 +122,7 @@ pub const RepoTags = struct {
};
 
pub fn repoTags(ctx: *API.Verse) API.Router.Error!void {
const req = try ctx.reqdata.validate(RepoRequest);
const req = try ctx.request.data.validate(RepoRequest);
 
var gitrepo = openRepo(ctx.alloc, req.name) catch |err| switch (err) {
error.InvalidName => return error.Abusive,
 
src/endpoints/admin.zig added: 34, removed: 34, total 0
@@ -106,7 +106,7 @@ const CloneUpstreamReq = struct {
fn postCloneUpstream(ctx: *Verse) Error!void {
try ctx.auth.requireValid();
 
const udata = ctx.reqdata.post.?.validate(CloneUpstreamReq) catch return error.BadData;
const udata = ctx.request.data.post.?.validate(CloneUpstreamReq) catch return error.BadData;
std.debug.print("repo uri {s}\n", .{udata.repo_uri});
var nameitr = std.mem.splitBackwardsScalar(u8, udata.repo_uri, '/');
const name = nameitr.first();
@@ -152,7 +152,7 @@ fn postCloneUpstream(ctx: *Verse) Error!void {
fn postNewRepo(ctx: *Verse) Error!void {
try ctx.auth.requireValid();
// TODO ini repo dir
var valid = if (ctx.reqdata.post) |p|
var valid = if (ctx.request.data.post) |p|
p.validator()
else
return error.Unknown;
@@ -232,7 +232,7 @@ fn newRepo(ctx: *Verse) Error!void {
 
fn view(ctx: *Verse) Error!void {
try ctx.auth.requireValid();
if (ctx.reqdata.post) |pd| {
if (ctx.request.data.post) |pd| {
std.debug.print("{any}\n", .{pd.items});
return newRepo(ctx);
}
 
src/endpoints/commit-flex.zig added: 34, removed: 34, total 0
@@ -226,7 +226,7 @@ pub fn commitFlex(ctx: *Verse) Error!void {
var nowish = DateTime.now();
var email: []const u8 = undefined;
var tz_offset: ?i32 = null;
var query = ctx.reqdata.query.validator();
var query = ctx.request.data.query.validator();
const user = query.optional("user");
 
if (user) |u| {
 
src/endpoints/gist.zig added: 34, removed: 34, total 0
@@ -54,7 +54,7 @@ const GistPost = struct {
fn post(ctx: *Verse) Error!void {
try ctx.auth.requireValid();
 
const udata = RequestData(GistPost).initMap(ctx.alloc, ctx.reqdata) catch return error.BadData;
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())
 
src/endpoints/repos.zig added: 34, removed: 34, total 0
@@ -250,7 +250,7 @@ const RepoSortReq = struct {
fn list(ctx: *Verse) Error!void {
var cwd = std.fs.cwd();
 
const udata = ctx.reqdata.query.validate(RepoSortReq) catch return error.BadData;
const udata = ctx.request.data.query.validate(RepoSortReq) catch return error.BadData;
const tag_sort: bool = if (udata.sort) |srt| if (eql(u8, srt, "tag")) true else false else false;
 
if (cwd.openDir("./repos", .{ .iterate = true })) |idir| {
 
src/endpoints/repos/commits.zig added: 34, removed: 34, total 0
@@ -52,7 +52,7 @@ pub fn router(ctx: *Verse) Error!Route.BuildFn {
}
 
fn newComment(ctx: *Verse) Error!void {
if (ctx.reqdata.post) |post| {
if (ctx.request.data.post) |post| {
_ = post.validate(AddComment) catch return error.BadData;
}
return error.BadData;
@@ -163,7 +163,7 @@ fn commitHtml(ctx: *Verse, sha: []const u8, repo_name: []const u8, repo: Git.Rep
}
}
 
const udata = ctx.reqdata.query.validate(Diffs.PatchView) catch return error.BadData;
const udata = ctx.request.data.query.validate(Diffs.PatchView) catch return error.BadData;
const inline_html = udata.@"inline" orelse true;
 
var page = CommitPage.init(.{
 
src/endpoints/repos/diffs.zig added: 34, removed: 34, total 0
@@ -85,7 +85,7 @@ fn new(ctx: *Verse) Error!void {
var patchuri: ?S.PatchUri = .{};
var title: ?[]const u8 = null;
var desc: ?[]const u8 = null;
if (ctx.reqdata.post) |post| {
if (ctx.request.data.post) |post| {
const udata = post.validate(DiffCreateChangeReq) catch return error.BadData;
title = udata.title;
desc = udata.desc;
@@ -160,7 +160,7 @@ const DiffCreateReq = struct {
 
fn createDiff(vrs: *Verse) Error!void {
const rd = Repos.RouteData.make(&vrs.uri) orelse return error.Unrouteable;
if (vrs.reqdata.post) |post| {
if (vrs.request.data.post) |post| {
const udata = post.validate(DiffCreateReq) catch return error.BadData;
if (udata.title.len == 0) return error.BadData;
 
@@ -205,7 +205,7 @@ fn createDiff(vrs: *Verse) Error!void {
fn newComment(ctx: *Verse) Error!void {
const rd = Repos.RouteData.make(&ctx.uri) orelse return error.Unrouteable;
var buf: [2048]u8 = undefined;
if (ctx.reqdata.post) |post| {
if (ctx.request.data.post) |post| {
var valid = post.validator();
const delta_id = try valid.require("did");
const delta_index = isHex(delta_id.value) orelse return error.Unrouteable;
@@ -664,7 +664,7 @@ fn view(ctx: *Verse) Error!void {
 
_ = delta.loadThread(ctx.alloc) catch unreachable;
 
const udata = ctx.reqdata.query.validate(PatchView) catch return error.BadData;
const udata = ctx.request.data.query.validate(PatchView) catch return error.BadData;
const inline_html = udata.@"inline" orelse true;
 
var patch_formatted: ?Template.Structs.PatchHtml = null;
 
src/endpoints/repos/issues.zig added: 34, removed: 34, total 0
@@ -69,7 +69,7 @@ const IssueCreate = struct {
fn newPost(ctx: *Verse) Error!void {
const rd = Repos.RouteData.make(&ctx.uri) orelse return error.Unrouteable;
var buf: [2048]u8 = undefined;
if (ctx.reqdata.post) |post| {
if (ctx.request.data.post) |post| {
const valid = post.validate(IssueCreate) catch return error.BadData;
var delta = Delta.new(
rd.name,
@@ -94,7 +94,7 @@ fn newPost(ctx: *Verse) Error!void {
 
fn newComment(ctx: *Verse) Error!void {
const rd = Repos.RouteData.make(&ctx.uri) orelse return error.Unrouteable;
if (ctx.reqdata.post) |post| {
if (ctx.request.data.post) |post| {
var valid = post.validator();
const delta_id = try valid.require("did");
const msg = try valid.require("comment");
 
src/endpoints/search.zig added: 34, removed: 34, total 0
@@ -32,7 +32,7 @@ fn inbox(ctx: *Verse) Error!void {
}
 
fn search(ctx: *Verse) Error!void {
const udata = ctx.reqdata.query.validate(SearchReq) catch return error.BadData;
const udata = ctx.request.data.query.validate(SearchReq) catch return error.BadData;
 
const query_str = udata.q orelse "null";
std.debug.print("query {s}\n", .{query_str});
 
src/endpoints/settings.zig added: 34, removed: 34, total 0
@@ -50,7 +50,7 @@ const SettingsReq = struct {
fn post(vrs: *Verse) Router.Error!void {
try vrs.auth.requireValid();
 
const udata = RequestData(SettingsReq).initMap(vrs.alloc, vrs.reqdata) catch return error.BadData;
const udata = RequestData(SettingsReq).initMap(vrs.alloc, vrs.request.data) catch return error.BadData;
 
for (udata.block_name, udata.block_text) |name, text| {
std.debug.print("block data:\nname '{s}'\ntext '''{s}'''\n", .{ name, text });
 
src/gitweb.zig added: 34, removed: 34, total 0
@@ -47,7 +47,7 @@ fn gitUploadPack(ctx: *Verse) Error!void {
defer map.deinit();
 
//(if GIT_PROJECT_ROOT is set, otherwise PATH_TRANSLATED)
if (ctx.reqdata.post == null) {
if (ctx.request.data.post == null) {
try map.put("PATH_TRANSLATED", path_tr);
try map.put("QUERY_STRING", "service=git-upload-pack");
try map.put("REQUEST_METHOD", "GET");
@@ -81,7 +81,7 @@ fn gitUploadPack(ctx: *Verse) Error!void {
.revents = undefined,
},
};
if (ctx.reqdata.post) |pd| {
if (ctx.request.data.post) |pd| {
_ = std.posix.write(child.stdin.?.handle, pd.rawpost) catch unreachable;
std.posix.close(child.stdin.?.handle);
child.stdin = null;
 
src/srctree.zig added: 34, removed: 34, total 0
@@ -89,7 +89,7 @@ pub fn builder(vrs: *Verse, call: BuildFn) void {
for (vrs.request.raw.zwsgi.vars) |vars| {
std.debug.print("Abusive var '{s}' => '''{s}'''", .{ vars.key, vars.val });
}
if (vrs.reqdata.post) |post_data| {
if (vrs.request.data.post) |post_data| {
std.debug.print("post data => '''{s}'''", .{post_data.rawpost});
}
},