aboutsummaryrefslogtreecommitdiff
path: root/src/routes/api/image/list.zig
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2025-11-19 09:15:49 +0100
committerNathan Reiner <nathan@nathanreiner.xyz>2025-11-19 09:15:49 +0100
commit4c06eb64cbed3562e428ce59857d1763098638f3 (patch)
treecc9c8164e76cd48e1dd4ef963329dcfa3c1b152f /src/routes/api/image/list.zig
parent6201307fecf8398a1b53bf276bc08bfbb3524899 (diff)
allow images to upload and sort if according to their datetime
Diffstat (limited to 'src/routes/api/image/list.zig')
-rw-r--r--src/routes/api/image/list.zig19
1 files changed, 15 insertions, 4 deletions
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 .{