Add default avatar

This commit is contained in:
jaina heartles 2022-12-10 02:51:59 -08:00
parent 783e3699e8
commit 0777ea83bb
2 changed files with 33 additions and 0 deletions

View file

@ -5,6 +5,8 @@ const sql = @import("sql");
const DateTime = util.DateTime;
const Uuid = util.Uuid;
const default_avatar = "static/default_avi.png";
const services = struct {
const communities = @import("./services/communities.zig");
const actors = @import("./services/actors.zig");
@ -52,7 +54,10 @@ pub const UserResponse = struct {
bio: []const u8,
avatar_file_id: ?Uuid,
avatar_url: []const u8,
header_file_id: ?Uuid,
header_url: ?[]const u8,
profile_fields: []const ProfileField,
@ -459,6 +464,28 @@ fn ApiConn(comptime DbConn: type) type {
fn getUserUnchecked(self: *Self, db: anytype, user_id: Uuid) !UserResponse {
const user = try services.actors.get(db, user_id, self.allocator);
const avatar_url = if (user.avatar_file_id) |fid|
try std.fmt.allocPrint(
self.allocator,
"{s}://{s}/media/{}",
.{ @tagName(self.community.scheme), self.community.host, fid },
)
else
try std.fmt.allocPrint(
self.allocator,
"{s}://{s}/{s}",
.{ @tagName(self.community.scheme), self.community.host, default_avatar },
);
errdefer self.allocator.free(avatar_url);
const header_url = if (user.header_file_id) |fid|
try std.fmt.allocPrint(
self.allocator,
"{s}://{s}/media/{}",
.{ @tagName(self.community.scheme), self.community.host, fid },
)
else
null;
return UserResponse{
.id = user.id,
@ -469,7 +496,10 @@ fn ApiConn(comptime DbConn: type) type {
.bio = user.bio,
.avatar_file_id = user.avatar_file_id,
.avatar_url = avatar_url,
.header_file_id = user.header_file_id,
.header_url = header_url,
.profile_fields = user.profile_fields,

3
static/default_avi.png Normal file
View file

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:54247347d90cecd9e6d598e1d74fae31f874ebb5c5e4dff7b4acc6a606acceef
size 40812