add new upload endpoint, so we can get rid of base64 for uploading images
This commit is contained in:
parent
499de238cb
commit
e15ce6ba8b
4 changed files with 111 additions and 1 deletions
|
|
@ -764,6 +764,54 @@ public static async Task Auth(HttpContext context, Func<Task> next, IQueryCollec
|
|||
}
|
||||
return;
|
||||
}
|
||||
public static async Task Upload(HttpContext context, Func<Task> next, IQueryCollection query)
|
||||
{
|
||||
if (!query.TryGetValue("id", out var idQuery))
|
||||
return;
|
||||
|
||||
if (!context.Request.Headers.TryGetValue("secret", out var secret))
|
||||
return;
|
||||
|
||||
if (!context.Request.Headers.TryGetValue("target", out var targetHeader))
|
||||
return;
|
||||
|
||||
string id = Utils.GetValidIdOrZero(idQuery.ToString());
|
||||
string password = await Utils.GetPassword(id);
|
||||
|
||||
string target = await Utils.NonceDecryptBody(id, password, targetHeader, false);
|
||||
string secretStr = await Utils.NonceDecryptBody(id, password, secret, false);
|
||||
|
||||
string auth = await Utils.Auth(id, secretStr, password);
|
||||
|
||||
if (auth != Utils.LOGIN_SUCCESS)
|
||||
{
|
||||
await context.Response.WriteAsync(Encryption.Encryption.EncryptString(auth, secretStr));
|
||||
return;
|
||||
}
|
||||
|
||||
byte[] bodyBytes = await LarpixServer.Utils.Utils.LoadBodyBytes(context.Request.Body, LarpixServer.Utils.Utils.PUBLIC_STORAGE_LIMIT);
|
||||
byte[] fileBytes = await Utils.NonceDecryptBytes(id, password, bodyBytes, true);
|
||||
|
||||
if (fileBytes == null)
|
||||
{
|
||||
await context.Response.WriteAsync(Encryption.Encryption.EncryptString("error:invalid.nonce", password));
|
||||
return;
|
||||
}
|
||||
|
||||
SemaphoreSlim userLock = Utils.GetUserLock(id);
|
||||
await userLock.WaitAsync();
|
||||
try
|
||||
{
|
||||
await context.Response.WriteAsync(
|
||||
Encryption.Encryption.EncryptString(
|
||||
await Utils.UpdateUserPublicStorageEntryRaw(id, target, fileBytes)
|
||||
, password));
|
||||
}
|
||||
finally
|
||||
{
|
||||
userLock.Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class CreateHolder
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue