[backend/api] Add endpoint to get drive files by their hash (ISH-459)

This commit is contained in:
Laura Hausmann 2024-09-06 17:24:00 +02:00
parent a22e857ed7
commit e88878cf3e
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -120,6 +120,30 @@ public class DriveController(
}; };
} }
[HttpGet("/by-hash/{sha256}")]
[Authenticate]
[Authorize]
[Produces(MediaTypeNames.Application.Json)]
[ProducesResults(HttpStatusCode.OK)]
[ProducesErrors(HttpStatusCode.NotFound)]
public async Task<DriveFileResponse> GetFileByHash(string sha256)
{
var user = HttpContext.GetUserOrFail();
var file = await db.DriveFiles.FirstOrDefaultAsync(p => p.User == user && p.Sha256 == sha256) ??
throw GracefulException.NotFound("File not found");
return new DriveFileResponse
{
Id = file.Id,
Url = file.AccessUrl,
ThumbnailUrl = file.ThumbnailAccessUrl,
Filename = file.Name,
ContentType = file.Type,
Description = file.Comment,
Sensitive = file.IsSensitive
};
}
[HttpPatch("{id}")] [HttpPatch("{id}")]
[Authenticate] [Authenticate]
[Authorize] [Authorize]