add "dm/messages/get" request
This commit is contained in:
parent
442add0ee4
commit
bb57c26dea
3 changed files with 60 additions and 7 deletions
|
|
@ -631,11 +631,17 @@ public class Requests
|
||||||
, password));
|
, password));
|
||||||
break;
|
break;
|
||||||
case "user/dm/create":
|
case "user/dm/create":
|
||||||
await context.Response.WriteAsync(
|
await context.Response.WriteAsync(Encryption.Encryption.EncryptString(await Room.Requests.DmCreate(id, serializedBody.string2), password));
|
||||||
Encryption.Encryption.EncryptString(
|
|
||||||
await Room.Requests.DmCreate(id, serializedBody.string2)
|
|
||||||
, password));
|
|
||||||
break;
|
break;
|
||||||
|
case "dm/messages/get":
|
||||||
|
{
|
||||||
|
Universal3String msgGet = JsonSerializer.Deserialize(
|
||||||
|
serializedBody.string2,
|
||||||
|
AppJsonSerializerContext.Default.Universal3String
|
||||||
|
);
|
||||||
|
await context.Response.WriteAsync(Encryption.Encryption.EncryptString(await Room.Requests.GetDmMessages(id, msgGet.string1, msgGet.string3, msgGet.string2), password));
|
||||||
|
break;
|
||||||
|
}
|
||||||
case "dm/key/get":
|
case "dm/key/get":
|
||||||
await context.Response.WriteAsync(
|
await context.Response.WriteAsync(
|
||||||
Encryption.Encryption.EncryptString(
|
Encryption.Encryption.EncryptString(
|
||||||
|
|
|
||||||
|
|
@ -160,11 +160,15 @@ public class Fs
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var dir = Path.GetDirectoryName(path);
|
var dir = Path.GetDirectoryName(path)?.Replace("\\", "/");
|
||||||
if (!string.IsNullOrEmpty(dir) && !Directory.Exists(dir))
|
if (!string.IsNullOrEmpty(dir))
|
||||||
|
{
|
||||||
|
existCache[dir] = true;
|
||||||
|
if (!Directory.Exists(dir))
|
||||||
{
|
{
|
||||||
CreateDirectory(dir);
|
CreateDirectory(dir);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await File.WriteAllBytesAsync(path, content);
|
await File.WriteAllBytesAsync(path, content);
|
||||||
existCache[path] = true;
|
existCache[path] = true;
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,49 @@ public class Requests
|
||||||
string memberPath = $"{ROOMS_DIR}/dms/{DOMAIN}/{dmId}/members/{id};{DOMAIN}";
|
string memberPath = $"{ROOMS_DIR}/dms/{DOMAIN}/{dmId}/members/{id};{DOMAIN}";
|
||||||
return Fs.Exists(memberPath);
|
return Fs.Exists(memberPath);
|
||||||
}
|
}
|
||||||
|
public static async Task<string> GetDmMessages(string id, string dmId, string startOffset, string countStr)
|
||||||
|
{
|
||||||
|
if (!await IsMemberOfDm(id, dmId)) return "error:forbidden";
|
||||||
|
|
||||||
|
string msgDir = $"{ROOMS_DIR}/dms/{DOMAIN}/{dmId}/messages";
|
||||||
|
if (!Fs.Exists(msgDir)) return "{}";
|
||||||
|
|
||||||
|
long last = 0;
|
||||||
|
if (Fs.Exists($"{msgDir}/last"))
|
||||||
|
{
|
||||||
|
string lastStr = Encoding.UTF8.GetString(await Fs.ReadFile($"{msgDir}/last"));
|
||||||
|
long.TryParse(lastStr, out last);
|
||||||
|
}
|
||||||
|
|
||||||
|
long start = last;
|
||||||
|
if (!string.IsNullOrEmpty(startOffset) && long.TryParse(startOffset, out long s))
|
||||||
|
{
|
||||||
|
start = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
int count = 50;
|
||||||
|
if (!string.IsNullOrEmpty(countStr) && int.TryParse(countStr, out int c))
|
||||||
|
{
|
||||||
|
count = Math.Min(c, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder("{");
|
||||||
|
int fetched = 0;
|
||||||
|
for (long i = start; i >= 0 && fetched < count; i--)
|
||||||
|
{
|
||||||
|
string p = $"{msgDir}/{i}";
|
||||||
|
if (Fs.Exists(p))
|
||||||
|
{
|
||||||
|
if (fetched > 0) sb.Append(',');
|
||||||
|
sb.Append($"\"{i}\":");
|
||||||
|
sb.Append(Encoding.UTF8.GetString(await Fs.ReadFile(p)));
|
||||||
|
fetched++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sb.Append("}");
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static async Task<string> GetDmKey(string id, string dmId)
|
public static async Task<string> GetDmKey(string id, string dmId)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue