From f41b6e5ec431c88bc1d94e4832d8ba49ddc42004 Mon Sep 17 00:00:00 2001 From: "Emma [it/its]@Rory&" Date: Tue, 5 Mar 2024 11:19:52 +0100 Subject: HomeserverEmulator work --- .../Services/MediaStore.cs | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Tests/LibMatrix.HomeserverEmulator/Services/MediaStore.cs (limited to 'Tests/LibMatrix.HomeserverEmulator/Services/MediaStore.cs') 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 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>(File.ReadAllText(Path.Combine(path, "index.json"))); + } + else + Console.WriteLine("Data storage is disabled, not loading rooms from disk"); + } + + public async Task 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 -- cgit 1.4.1