mirror of
https://github.com/LD-Reborn/Berufsschule_HAM.git
synced 2025-12-20 06:51:55 +00:00
Merge pull request #264 from LD-Reborn/235-feature-implement-maxdownloadableuserimagesize-settings
Implemented MaxDownloadableUserImageSize config setting
This commit is contained in:
@@ -98,6 +98,7 @@ public class HomeController : Controller
|
|||||||
[ResponseCache(Duration = 3600, Location = ResponseCacheLocation.Any, VaryByQueryKeys = new[] { "uid", "size" })]
|
[ResponseCache(Duration = 3600, Location = ResponseCacheLocation.Any, VaryByQueryKeys = new[] { "uid", "size" })]
|
||||||
public async Task<IActionResult> UserPhotoAsync(string uid, int? size)
|
public async Task<IActionResult> UserPhotoAsync(string uid, int? size)
|
||||||
{
|
{
|
||||||
|
Task<AdminSettingsModel> adminSettingsModelTask = _ldap.GetAdminSettingsModelAsync();
|
||||||
UserModel? user = await _ldap.GetUserByUidAsync(uid, _ldap.UsersAttributes);
|
UserModel? user = await _ldap.GetUserByUidAsync(uid, _ldap.UsersAttributes);
|
||||||
if (user is null || user.JpegPhoto is null)
|
if (user is null || user.JpegPhoto is null)
|
||||||
{
|
{
|
||||||
@@ -107,6 +108,11 @@ public class HomeController : Controller
|
|||||||
{
|
{
|
||||||
return File(Convert.FromBase64String(user.JpegPhoto), "image/jpeg");
|
return File(Convert.FromBase64String(user.JpegPhoto), "image/jpeg");
|
||||||
}
|
}
|
||||||
|
if (size is not null)
|
||||||
|
{
|
||||||
|
AdminSettingsModel adminSettingsModel = await adminSettingsModelTask;
|
||||||
|
size = Math.Min((int)size, adminSettingsModel.MaxDownloadableUserImageSize);
|
||||||
|
}
|
||||||
string encodedFile = ImageHelper.ResizeAndConvertToBase64(Convert.FromBase64String(user.JpegPhoto), size ?? 32);
|
string encodedFile = ImageHelper.ResizeAndConvertToBase64(Convert.FromBase64String(user.JpegPhoto), size ?? 32);
|
||||||
return File(Convert.FromBase64String(encodedFile), "image/jpeg");
|
return File(Convert.FromBase64String(encodedFile), "image/jpeg");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ public static class ImageHelper
|
|||||||
{
|
{
|
||||||
public static string ResizeAndConvertToBase64(byte[] imageBytes, int size = 32)
|
public static string ResizeAndConvertToBase64(byte[] imageBytes, int size = 32)
|
||||||
{
|
{
|
||||||
size = Math.Min(size, 256);
|
|
||||||
using var inputStream = new MemoryStream(imageBytes);
|
using var inputStream = new MemoryStream(imageBytes);
|
||||||
using var image = Image.Load(inputStream);
|
using var image = Image.Load(inputStream);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user