From 4c06eb64cbed3562e428ce59857d1763098638f3 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Wed, 19 Nov 2025 09:15:49 +0100 Subject: allow images to upload and sort if according to their datetime --- src/routes/api/image/list.zig | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/routes/api/image/list.zig') diff --git a/src/routes/api/image/list.zig b/src/routes/api/image/list.zig index d305276..5d2eace 100644 --- a/src/routes/api/image/list.zig +++ b/src/routes/api/image/list.zig @@ -7,6 +7,7 @@ pub const access = .users; const ImageInfo = struct { id: []const u8, + timestamp: ?i64, }; const Result = struct { @@ -16,13 +17,23 @@ const Result = struct { pub fn get(ctx: *Context) !Result { var images: std.ArrayList(ImageInfo) = .empty; - const images_list = ctx.storage.images.list(); - defer images_list.deinit(); + var images_list = ctx.storage.images.list(); + defer images_list.unlock(); + + var locked = ctx.storage.images.first_by_timestamp(); + defer locked.unlock(); + + var current = locked.value; + + while (current) |c| { + const image = ctx.storage.images.items.items[c.index]; - for (images_list.images) |*image| { try images.append(ctx.allocator, .{ - .id = image.id + .id = try ctx.allocator.dupe(u8, image.id), + .timestamp = image.timestamp, }); + + current = c.next(); } return .{ -- cgit v1.2.3-70-g09d2