From f2cd03729059206fe584e2a9f278dd67625a9221 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Mon, 24 Nov 2025 17:43:49 +0100 Subject: add config --- src/storage/root.zig | 12 ++++++++++-- src/storage/session-manager/root.zig | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'src/storage') diff --git a/src/storage/root.zig b/src/storage/root.zig index 381dc45..f11798b 100644 --- a/src/storage/root.zig +++ b/src/storage/root.zig @@ -1,6 +1,6 @@ const std = @import("std"); -const config = @import("../config.zig"); const prompt = @import("../prompt.zig"); +const Config = @import("../config.zig"); pub const User = @import("user.zig"); @@ -15,15 +15,22 @@ const Self = @This(); dir: std.fs.Dir, sessions: SessionManager = .empty, images: ImageManager = .empty, +config: Config, allocator: std.mem.Allocator, -pub fn init(allocator: std.mem.Allocator) !Self { +pub fn init( + allocator: std.mem.Allocator, +) !Self { + var config = try Config.load(allocator); + errdefer config.deinit(); + const dir = std.fs.cwd().openDir(config.storage_path, .{}) catch blk: { try std.fs.cwd().makeDir(config.storage_path); break :blk try std.fs.cwd().openDir(config.storage_path, .{}); }; var self = Self { + .config = config, .dir = dir, .allocator = allocator, }; @@ -67,5 +74,6 @@ pub fn init(allocator: std.mem.Allocator) !Self { pub fn deinit(self: *Self) void { self.dir.close(); + self.config.deinit(); self.* = undefined; } diff --git a/src/storage/session-manager/root.zig b/src/storage/session-manager/root.zig index d0e1441..8a59f21 100644 --- a/src/storage/session-manager/root.zig +++ b/src/storage/session-manager/root.zig @@ -65,7 +65,7 @@ pub fn get(self: *Self, storage: *Storage, fingerprint: []const u8) ?*Session { const now = std.time.Instant.now() catch return null; const since = now.since(session.age); - if (since > config.session_expires_after) { + if (since > storage.config.session_expires_after) { session.deinit(storage.allocator); _ = self.cache.remove(fingerprint); return null; -- cgit v1.2.3-70-g09d2