diff --git a/src/api/lib.zig b/src/api/lib.zig index 00a16eb..e145fba 100644 --- a/src/api/lib.zig +++ b/src/api/lib.zig @@ -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, diff --git a/static/default_avi.png b/static/default_avi.png new file mode 100644 index 0000000..edd1828 --- /dev/null +++ b/static/default_avi.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:54247347d90cecd9e6d598e1d74fae31f874ebb5c5e4dff7b4acc6a606acceef +size 40812