Implement file hashing on upload

Closes #25
This commit is contained in:
jvyden 2021-11-18 19:30:37 -05:00
parent 4542bd3313
commit 09c72eb9c2
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
4 changed files with 26 additions and 12 deletions

View file

@ -1,6 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using LBPUnion.ProjectLighthouse.Helpers;
@ -55,6 +56,14 @@ namespace LBPUnion.ProjectLighthouse.Tests
return this.Client.SendAsync(requestMessage);
}
public async Task<HttpResponseMessage> UploadFileEndpointRequest(string filePath)
{
byte[] bytes = Encoding.UTF8.GetBytes(await File.ReadAllTextAsync(filePath));
string hash = HashHelper.Sha1Hash(bytes);
return await this.Client.PostAsync($"/LITTLEBIGPLANETPS3_XML/upload/{hash}", new ByteArrayContent(bytes));
}
public async Task<HttpResponseMessage> UploadFileRequest(string endpoint, string filePath)
=> await this.Client.PostAsync(endpoint, new StringContent(await File.ReadAllTextAsync(filePath)));