Allow uploading resources

This commit is contained in:
jvyden 2021-10-11 16:51:48 -04:00
commit 6ad45220bf
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278

View file

@ -24,12 +24,21 @@ namespace ProjectLighthouse.Controllers {
public IActionResult GetResource(string hash) {
string path = Path.Combine(Environment.CurrentDirectory, "r", hash);
Console.WriteLine($"path: {path}, exists: {IOFile.Exists(path)}");
if(IOFile.Exists(path)) {
return this.File(IOFile.OpenRead(path), "image/jpg");
}
return this.NotFound();
}
// TODO: check if this is a valid hash
[HttpPost("upload/{hash}")]
public async Task<IActionResult> UploadResource(string hash) {
string path = Path.Combine(Environment.CurrentDirectory, "r", hash);
if(IOFile.Exists(path)) this.Ok(); // no reason to fail if it's already uploaded
await IOFile.WriteAllTextAsync(path, await new StreamReader(Request.Body).ReadToEndAsync());
return this.Ok();
}
}
}