Skip to content

Commit

Permalink
use ulid.bytes() instead of ulid.toString(alloc)
Browse files Browse the repository at this point in the history
  • Loading branch information
nektro committed Aug 11, 2022
1 parent 3c1dbf1 commit 2655922
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/db/Remote.zig
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ fn apiRequest(self: Remote, alloc: std.mem.Allocator, user: ?User, endpoint: str
defer headers.deinit();

if (user) |_| {
if (_handler.getAccessToken(try user.?.uuid.toString(alloc))) |token| {
if (_handler.getAccessToken(&user.?.uuid.bytes())) |token| {
switch (self.type) {
.github => try headers.appendValue("Authorization", try std.mem.join(alloc, " ", &.{ "Bearer", token })),
.gitea => try headers.appendValue("Authorization", try std.mem.join(alloc, " ", &.{ "token", token })),
Expand Down Expand Up @@ -206,7 +206,7 @@ fn apiPost(self: Remote, alloc: std.mem.Allocator, user: ?User, endpoint: string
defer headers.deinit();

if (user) |_| {
if (_handler.getAccessToken(try user.?.uuid.toString(alloc))) |token| {
if (_handler.getAccessToken(&user.?.uuid.bytes())) |token| {
try headers.appendValue("Authorization", try std.mem.join(alloc, " ", &.{ "Bearer", token }));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/db/Version.zig
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub fn format(self: Version, comptime fmt: string, options: std.fmt.FormatOption
}

pub fn setVersion(self: *Version, alloc: std.mem.Allocator, approver: User, major: u32, minor: u32) !void {
try self.update(alloc, .approved_by, try approver.uuid.toString(alloc));
try self.update(alloc, .approved_by, &approver.uuid.bytes());
try self.update(alloc, .real_major, major);
try self.update(alloc, .real_minor, minor);
}
Expand Down
2 changes: 1 addition & 1 deletion src/handler/_handler.zig
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub fn saveInfo(response: *http.Response, request: http.Request, idp: oauth2.Pro
const alloc = request.arena;
const r = (try db.Remote.byKey(alloc, .domain, idp.domain())) orelse unreachable;
const u = (try r.findUserBy(alloc, .snowflake, id)) orelse try db.User.create(alloc, r.id, id, name);
const ulid = try _internal.access_tokens.allocator.dupe(u8, try u.uuid.toString(alloc));
const ulid = try _internal.access_tokens.allocator.dupe(u8, &u.uuid.bytes());

try response.headers.put("Set-Cookie", try std.fmt.allocPrint(alloc, "jwt={s}", .{
try ox.token.encodeMessage(alloc, ulid),
Expand Down
2 changes: 1 addition & 1 deletion src/handler/do_import.zig
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn get(_: void, response: *http.Response, request: http.Request, captures: ?
const tarfile = try std.fs.cwd().openFile(tarpath, .{});
defer tarfile.close();

const destdirpath = try std.fs.path.join(alloc, &.{ root.datadirpath, "packages", try u.uuid.toString(alloc), details.id });
const destdirpath = try std.fs.path.join(alloc, &.{ root.datadirpath, "packages", &u.uuid.bytes(), details.id });
try std.fs.cwd().makePath(destdirpath);

const destpath = try std.fs.path.join(alloc, &.{ destdirpath, try std.mem.concat(alloc, u8, &.{ "latest", ".tar.gz" }) });
Expand Down
3 changes: 1 addition & 2 deletions src/handler/hook.zig
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,8 @@ pub fn post(_: void, response: *http.Response, request: http.Request, captures:

try std.fs.cwd().deleteTree(path);

// TODO remove toString usages
const jobs = [_]string{
try (try db.Job.create(alloc, p, commit, .x86_64, .debian)).uuid.toString(alloc),
&(try db.Job.create(alloc, p, commit, .x86_64, .debian)).uuid.bytes(),
};

var v = try db.Version.create(alloc, p, commit, unpackedsize, totalsize, filelist, tarsize, tarhash, deps, rootdeps, builddeps, readme, &jobs);
Expand Down
2 changes: 1 addition & 1 deletion zigmod.lock
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ git https://github.com/kivikakk/zunicode commit-5bf4a3a5f0c6e3d96f6def56957ab7f2
git https://github.com/nektro/ox commit-ee7d31a66d82ed86b4610eea66cb0b8c7c420995
git https://github.com/nektro/zig-zorm commit-e5176e73203424da95a9d660648016d6f3776281
git https://github.com/vrischmann/zig-sqlite commit-13b8e4e6a036f43d28a5f6691587ca1d8baa7eae
git https://github.com/nektro/zig-ulid commit-d2834174ee6a0011ee42fe43be2886c539a146ce
git https://github.com/nektro/zig-ulid commit-7f2c7edf0e7f91229be17bda52d0e74d42d862e2
git https://github.com/leroycep/zig-jwt commit-137598749184c830ad07d9e5762b9db5e9a326c6
git https://gist.github.com/nektro/a0045048d8e7458e42520e9ffb90becd commit-3fdb9fddeefa8ebb2c60a3b349fff4e635993cea
git https://gist.github.com/nektro/64c7da67a00d8b94091d754dd2cf1aa9 commit-4d6ac0b23bd3e55c1907eeced651fca04721a88d
Expand Down

0 comments on commit 2655922

Please sign in to comment.