about summary refs log tree commit diff
path: root/Tests/LibMatrix.HomeserverEmulator/Services/MediaStore.cs
diff options
context:
space:
mode:
authorEmma [it/its]@Rory& <root@rory.gay>2024-03-05 11:19:52 +0100
committerEmma [it/its]@Rory& <root@rory.gay>2024-03-05 11:19:52 +0100
commitf41b6e5ec431c88bc1d94e4832d8ba49ddc42004 (patch)
tree503be94f5036f7cc221846c1eabf7c5edd107f1a /Tests/LibMatrix.HomeserverEmulator/Services/MediaStore.cs
parentUnknown changes (diff)
downloadLibMatrix-f41b6e5ec431c88bc1d94e4832d8ba49ddc42004.tar.xz
HomeserverEmulator work
Diffstat (limited to '')
-rw-r--r--Tests/LibMatrix.HomeserverEmulator/Services/MediaStore.cs47
1 files changed, 47 insertions, 0 deletions
diff --git a/Tests/LibMatrix.HomeserverEmulator/Services/MediaStore.cs b/Tests/LibMatrix.HomeserverEmulator/Services/MediaStore.cs
new file mode 100644
index 0000000..e34a731
--- /dev/null
+++ b/Tests/LibMatrix.HomeserverEmulator/Services/MediaStore.cs
@@ -0,0 +1,47 @@
+using System.Collections.Concurrent;
+using System.Collections.Frozen;
+using System.Collections.ObjectModel;
+using System.Security.Cryptography;
+using System.Text.Json;
+using System.Text.Json.Nodes;
+using System.Text.Json.Serialization;
+using ArcaneLibs;
+using ArcaneLibs.Collections;
+using ArcaneLibs.Extensions;
+using LibMatrix.EventTypes;
+using LibMatrix.EventTypes.Spec.State;
+using LibMatrix.Responses;
+
+namespace LibMatrix.HomeserverEmulator.Services;
+
+public class MediaStore {
+    private readonly HSEConfiguration _config;
+    private List<MediaInfo> index = new();
+
+    public MediaStore(HSEConfiguration config) {
+        _config = config;
+        if (config.StoreData) {
+            var path = Path.Combine(config.DataStoragePath, "media");
+            if (!Directory.Exists(path)) Directory.CreateDirectory(path);
+            if(File.Exists(Path.Combine(path, "index.json")))
+                index = JsonSerializer.Deserialize<List<MediaInfo>>(File.ReadAllText(Path.Combine(path, "index.json")));
+        }
+        else
+            Console.WriteLine("Data storage is disabled, not loading rooms from disk");
+    }
+
+    public async Task<object> UploadMedia(string userId, string mimeType, Stream stream, string? filename = null) {
+        var mediaId = $"mxc://{Guid.NewGuid().ToString()}";
+        var path = Path.Combine(_config.DataStoragePath, "media", mediaId);
+        if (!Directory.Exists(path)) Directory.CreateDirectory(path);
+        var file = Path.Combine(path, filename ?? "file");
+        await using var fs = File.Create(file);
+        await stream.CopyToAsync(fs);
+        index.Add(new() {
+            
+        });
+        return media;
+    }
+
+    public class MediaInfo { }
+}
\ No newline at end of file