add ATTACHMENT_SIZE_LIMIT, MAX_MESSAGE_SIZE, MAX_REACTION_SIZE & replace System.IO with custom Fs class
This commit is contained in:
parent
91f8dd0db5
commit
a17100910e
6 changed files with 99 additions and 48 deletions
|
|
@ -381,6 +381,12 @@ public class Requests
|
|||
string responded = serializedBody.string4;
|
||||
|
||||
if (!await IsMemberOfDm(id, dmId)) return "error:forbidden";
|
||||
|
||||
if (content != null && content.Length > LarpixServer.Utils.Utils.MAX_MESSAGE_SIZE)
|
||||
{
|
||||
string sizeStr = LarpixServer.Utils.Utils.MAX_MESSAGE_SIZE >= 1024 ? $"{LarpixServer.Utils.Utils.MAX_MESSAGE_SIZE / 1024.0:0.##} KB" : $"{LarpixServer.Utils.Utils.MAX_MESSAGE_SIZE} B";
|
||||
return $"error:message.too.long:{sizeStr}";
|
||||
}
|
||||
|
||||
string msgDir = $"{ROOMS_DIR}/dms/{DOMAIN}/{dmId}/messages";
|
||||
long last = 0;
|
||||
|
|
@ -409,7 +415,7 @@ public class Requests
|
|||
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);
|
||||
if (!Fs.Exists(attDir)) Fs.CreateDirectory(attDir);
|
||||
|
||||
for (int i = 0; i < arr.Count; i++)
|
||||
{
|
||||
|
|
@ -422,7 +428,7 @@ public class Requests
|
|||
{
|
||||
string attId = attObj["id"].ToString();
|
||||
string destPath = $"{attDir}/{attId}";
|
||||
System.IO.File.Move(stagingPath, destPath);
|
||||
Fs.MoveFile(stagingPath, destPath);
|
||||
}
|
||||
attObj.Remove("staging_id"); // Clean it up before saving
|
||||
}
|
||||
|
|
@ -529,6 +535,12 @@ public class Requests
|
|||
|
||||
if (!IsSafeMsgId(msgId)) return "error:invalid.msg.id";
|
||||
if (!await IsMemberOfDm(id, dmId)) return "error:forbidden";
|
||||
|
||||
if (reactions != null && reactions.Length > LarpixServer.Utils.Utils.MAX_REACTION_SIZE)
|
||||
{
|
||||
string sizeStr = LarpixServer.Utils.Utils.MAX_REACTION_SIZE >= 1024 ? $"{LarpixServer.Utils.Utils.MAX_REACTION_SIZE / 1024.0:0.##} KB" : $"{LarpixServer.Utils.Utils.MAX_REACTION_SIZE} B";
|
||||
return $"error:reaction.too.long:{sizeStr}";
|
||||
}
|
||||
|
||||
string msgPath = $"{ROOMS_DIR}/dms/{DOMAIN}/{dmId}/messages/{msgId}";
|
||||
if (!Fs.Exists(msgPath)) return "error:message.not.found";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue