Changes
5 changed files (+71/-5)
-
-
@@ -1555,6 +1555,51 @@ return image.GetResult.makeRetainedError(.out_of_memory) catch null;}; } pub fn getImageUrl( ptr: ?*Connection, image_key_ptr: [*:0]const u8, opts_ptr: ?*image.GetOptions, ) callconv(.C) ?[*:0]u8 { var self = ptr orelse @panic( std.fmt.comptimePrint("Received null pointer on {s}_{s}", .{ cname, @src().fn_name }), ); const image_key = std.mem.span(image_key_ptr); const req = req: { const opts = image.GetOptions.retain(opts_ptr); defer opts.release(); var r = ImageService.Get.Request{ .image_key = image_key, .format = if (opts.internal.data.content_type) |t| switch (t) { .jpeg => .jpeg, .png => .png, } else null, }; if (opts.internal.data.size) |size| { r.scale = switch (size.scaling_method) { .fit => .fit, .fill => .fill, .stretch => .stretch, }; r.width = size.width; r.height = size.height; } break :req r; }; const slice = req.url( [:0]u8, self.internal.tsa.allocator(), self.internal.server.internal.address, ) catch return null; return slice.ptr; } pub fn export_capi() void { @export(&make, .{ .name = std.fmt.comptimePrint("{s}_make", .{cname}) }); @export(&retain, .{ .name = std.fmt.comptimePrint("{s}_retain", .{cname}) });
-
@@ -1568,6 +1613,7 @@ @export(&decreaseVolume, .{ .name = std.fmt.comptimePrint("{s}_decrease_volume", .{cname}) });@export(&changeVolume, .{ .name = std.fmt.comptimePrint("{s}_change_volume", .{cname}) }); @export(&requestBrowse, .{ .name = std.fmt.comptimePrint("{s}_browse", .{cname}) }); @export(&getImage, .{ .name = std.fmt.comptimePrint("{s}_get_image", .{cname}) }); @export(&getImageUrl, .{ .name = std.fmt.comptimePrint("{s}_get_image_url", .{cname}) }); @export(&disconnect, .{ .name = std.fmt.comptimePrint("{s}_disconnect", .{cname}) }); } };
-
-
-
@@ -554,7 +554,7 @@ std.log.err("Downloading image without specifying format is not currently supported", .{});return try GetResult.makeRetainedError(.failed_to_send); }; const url = req.url(allocator, server.internal.address) catch |err| { const url = req.url([]const u8, allocator, server.internal.address) catch |err| { std.log.err("Unable to construct image download URL: {s}", .{@errorName(err)}); return try GetResult.makeRetainedError(.unknown_error); };
-
-
-
@@ -442,5 +442,6 @@ plac_transport_volume_control_result_code plac_connection_increase_volume(plac_connection*, plac_transport_output*);plac_transport_volume_control_result_code plac_connection_decrease_volume(plac_connection*, plac_transport_output*); plac_browse_result *plac_connection_browse(plac_connection*, plac_browse_hierarchy, plac_transport_zone*, plac_browse_item*, bool pop); plac_image_get_result *plac_connection_get_image(plac_connection*, const char *image_key, plac_image_get_options*); const char *plac_connection_get_image_url(plac_connection*, const char *image_key, plac_image_get_options*); #endif
-
-
-
@@ -668,5 +668,8 @@ public Browse.Result? browse(Browse.Hierarchy hierarchy, Transport.Zone? zone, Browse.Item? item, bool pop);[CCode (cname = "plac_connection_get_image")] public Image.GetResult? get_image(string image_key, Image.GetOptions options); [CCode (cname = "plac_connection_get_image_url")] public string? get_image_url(string image_key, Image.GetOptions options); } }
-
-
-
@@ -94,7 +94,12 @@return buf; } pub fn url(self: *const @This(), allocator: std.mem.Allocator, addr: std.net.Address) ![]const u8 { pub fn url( self: *const @This(), comptime T: type, allocator: std.mem.Allocator, addr: std.net.Address, ) !T { const path = try std.fmt.allocPrint(allocator, "/api/image/{s}", .{self.image_key}); defer allocator.free(path);
-
@@ -151,7 +156,14 @@ .path = true,.query = true, }, result.writer()); return result.toOwnedSlice(); return switch (T) { []const u8, []u8 => result.toOwnedSlice(), [:0]const u8, [:0]u8 => result.toOwnedSliceSentinel(0), else => @compileError(std.fmt.comptimePrint( "Unsupported type {s}. Must be a slice of u8", .{@typeName(T)}, )), }; } test url {
-
@@ -159,7 +171,11 @@ const req = Request{.image_key = "foo", }; const result = try req.url(std.testing.allocator, try std.net.Address.parseIp("127.0.0.1", 8080)); const result = try req.url( []const u8, std.testing.allocator, try std.net.Address.parseIp("127.0.0.1", 8080), ); defer std.testing.allocator.free(result); try std.testing.expectEqualStrings("http://127.0.0.1:8080/api/image/foo", result);
-
@@ -174,7 +190,7 @@ .height = 200,.format = .png, }; const result = try req.url(std.testing.allocator, try std.net.Address.parseIp("127.0.0.1", 8080)); const result = try req.url([]const u8, std.testing.allocator, try std.net.Address.parseIp("127.0.0.1", 8080)); defer std.testing.allocator.free(result); try std.testing.expectEqualStrings(
-