add attachments
All checks were successful
Server Build / publish (push) Successful in 32s
Voice Build / publish (push) Successful in 24s

This commit is contained in:
olcxja 2026-07-14 19:35:00 +02:00
commit 91f8dd0db5
4 changed files with 149 additions and 3 deletions

View file

@ -33,7 +33,7 @@ public class Requests
return true;
}
private static async Task<bool> IsMemberOfDm(string id, string dmId)
public static async Task<bool> IsMemberOfDm(string id, string dmId)
{
if (!IsSafeDmId(dmId)) return false;
string memberPath = $"{ROOMS_DIR}/dms/{DOMAIN}/{dmId}/members/{id};{DOMAIN}";
@ -401,6 +401,41 @@ public class Requests
msg.responded = responded ?? "";
msg.reactions = "";
if (!string.IsNullOrEmpty(msg.attachment) && msg.attachment != "[]")
{
try
{
var attachmentsNode = System.Text.Json.Nodes.JsonNode.Parse(msg.attachment);
if (attachmentsNode is System.Text.Json.Nodes.JsonArray arr)
{
string attDir = $"{ROOMS_DIR}/dms/{DOMAIN}/{dmId}/attachments/{nextId}";
if (!Directory.Exists(attDir)) Directory.CreateDirectory(attDir);
for (int i = 0; i < arr.Count; i++)
{
var attObj = arr[i] as System.Text.Json.Nodes.JsonObject;
if (attObj != null && attObj.ContainsKey("staging_id"))
{
string stagingId = attObj["staging_id"].ToString();
string stagingPath = $"{ROOMS_DIR}/dms_staging/{stagingId}";
if (Fs.Exists(stagingPath))
{
string attId = attObj["id"].ToString();
string destPath = $"{attDir}/{attId}";
System.IO.File.Move(stagingPath, destPath);
}
attObj.Remove("staging_id"); // Clean it up before saving
}
}
msg.attachment = attachmentsNode.ToJsonString();
}
}
catch (Exception ex)
{
Console.WriteLine($"Error processing attachments: {ex}");
}
}
await Fs.WriteFile($"{msgDir}/{nextId}", Encoding.UTF8.GetBytes(JsonSerializer.Serialize(msg, AppJsonSerializerContext.Default.Message)));
await Fs.WriteFile($"{msgDir}/last", Encoding.UTF8.GetBytes(nextId.ToString()));