mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-29 08:28:39 +00:00
Allow uploading resources
This commit is contained in:
parent
06b89fec50
commit
6ad45220bf
1 changed files with 12 additions and 3 deletions
|
@ -23,13 +23,22 @@ namespace ProjectLighthouse.Controllers {
|
|||
[HttpGet("r/{hash}")]
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue