diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2025-11-19 09:15:49 +0100 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2025-11-19 09:15:49 +0100 |
| commit | 4c06eb64cbed3562e428ce59857d1763098638f3 (patch) | |
| tree | cc9c8164e76cd48e1dd4ef963329dcfa3c1b152f /src/routes/api/image | |
| parent | 6201307fecf8398a1b53bf276bc08bfbb3524899 (diff) | |
allow images to upload and sort if according to their datetime
Diffstat (limited to 'src/routes/api/image')
| -rw-r--r-- | src/routes/api/image/list.zig | 19 | ||||
| -rw-r--r-- | src/routes/api/image/load.zig | 2 | ||||
| -rw-r--r-- | src/routes/api/image/upload.zig | 2 |
3 files changed, 17 insertions, 6 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 .{ diff --git a/src/routes/api/image/load.zig b/src/routes/api/image/load.zig index 4f0a072..1b2a3e2 100644 --- a/src/routes/api/image/load.zig +++ b/src/routes/api/image/load.zig @@ -8,6 +8,6 @@ pub const access = .users; pub fn get(ctx: *Context) !memora.Stream { const id = ctx.request.head.target["/api/image/load/".len..]; - var image = Storage.Image { .id = id }; + var image = Storage.Image { .id = id, .timestamp = null }; return .from_file(try image.file(ctx.storage)); } diff --git a/src/routes/api/image/upload.zig b/src/routes/api/image/upload.zig index bbdd47c..72c8a2d 100644 --- a/src/routes/api/image/upload.zig +++ b/src/routes/api/image/upload.zig @@ -12,6 +12,6 @@ pub fn post(ctx: *Context) !void { if (ctx.request.head.content_length) |length| { var buffer: [1024]u8 = undefined; const reader = try ctx.request.readerExpectContinue(&buffer); - try ctx.storage.images.add(ctx.storage, reader, length); + try ctx.storage.images.save(ctx.storage, reader, length); } } |