blob: 5d2eaceddf977fb7df38358c45581df37b58aaf1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
const std = @import("std");
const memora = @import("memora");
const Context = memora.Context;
const Storage = memora.Storage;
pub const access = .users;
const ImageInfo = struct {
id: []const u8,
timestamp: ?i64,
};
const Result = struct {
images: []ImageInfo,
};
pub fn get(ctx: *Context) !Result {
var images: std.ArrayList(ImageInfo) = .empty;
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];
try images.append(ctx.allocator, .{
.id = try ctx.allocator.dupe(u8, image.id),
.timestamp = image.timestamp,
});
current = c.next();
}
return .{
.images = try images.toOwnedSlice(ctx.allocator),
};
}
|