about summary refs log tree commit diff
path: root/LibMatrix.ExampleBot/Bot/FileStorageProvider.cs
diff options
context:
space:
mode:
Diffstat (limited to 'LibMatrix.ExampleBot/Bot/FileStorageProvider.cs')
-rw-r--r--LibMatrix.ExampleBot/Bot/FileStorageProvider.cs11
1 files changed, 7 insertions, 4 deletions
diff --git a/LibMatrix.ExampleBot/Bot/FileStorageProvider.cs b/LibMatrix.ExampleBot/Bot/FileStorageProvider.cs
index 249aba3..1e84ab7 100644
--- a/LibMatrix.ExampleBot/Bot/FileStorageProvider.cs
+++ b/LibMatrix.ExampleBot/Bot/FileStorageProvider.cs
@@ -23,13 +23,16 @@ public class FileStorageProvider : IStorageProvider {
         }
     }
 
-    public async Task SaveObjectAsync<T>(string key, T value) => await File.WriteAllTextAsync(Path.Join(TargetPath, key), ObjectExtensions.ToJson(value));
+    public async Task SaveObjectAsync<T>(string key, T value) => await File.WriteAllTextAsync(Path.Join(TargetPath, key), value?.ToJson());
 
     public async Task<T?> LoadObjectAsync<T>(string key) => JsonSerializer.Deserialize<T>(await File.ReadAllTextAsync(Path.Join(TargetPath, key)));
 
-    public async Task<bool> ObjectExistsAsync(string key) => File.Exists(Path.Join(TargetPath, key));
+    public Task<bool> ObjectExistsAsync(string key) => Task.FromResult(File.Exists(Path.Join(TargetPath, key)));
 
-    public async Task<List<string>> GetAllKeysAsync() => Directory.GetFiles(TargetPath).Select(Path.GetFileName).ToList();
+    public Task<List<string>> GetAllKeysAsync() => Task.FromResult(Directory.GetFiles(TargetPath).Select(Path.GetFileName).ToList());
 
-    public async Task DeleteObjectAsync(string key) => File.Delete(Path.Join(TargetPath, key));
+    public Task DeleteObjectAsync(string key) {
+        File.Delete(Path.Join(TargetPath, key));
+        return Task.CompletedTask;
+    }
 }