Skip to content

Commit

Permalink
Merge pull request itpartnersillinois#92 from itpartnersillinois/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
bryanjonker-illinois authored Nov 14, 2024
2 parents 971f98d + 7f31169 commit 2715e03
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions uofi-itp-directory-external/ImageManager/DirectoryImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
public static class DirectoryImage {
private const string _blank = "https://directory.illinois.edu/webservices/public/ds/profile.png";

public static string Blank => _blank;

public static string CheckImage(string url) {
if (string.IsNullOrWhiteSpace(url)) {
return _blank;
Expand Down
29 changes: 29 additions & 0 deletions uofi-itp-directory/Controllers/PictureController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using uofi_itp_directory_data.Data;
using uofi_itp_directory_external.ImageManager;

namespace uofi_itp_directory.Controllers {

[Route("[controller]")]
[AllowAnonymous]
public class PictureController(DirectoryRepository? directoryRepository) : Controller {
private readonly DirectoryRepository _directoryRepository = directoryRepository ?? throw new ArgumentNullException("directoryRepository");

[Route("{netid}")]
[HttpGet]
public async Task<IActionResult> ByUsername(string netid) => await Index(netid);

[HttpGet]
public async Task<IActionResult> Index(string netid) {
netid = netid.Replace("@illinois.edu", "") + "@illinois.edu";
var url = (await _directoryRepository.ReadAsync(d => d.Employees.FirstOrDefault(e => e.NetId == netid)))?.PhotoUrl ?? "";
if (string.IsNullOrWhiteSpace(url)) {
url = DirectoryImage.Blank;
}
var wc = new HttpClient();
var stream = await wc.GetStreamAsync(url);
return new FileStreamResult(stream, "image/webp");
}
}
}

0 comments on commit 2715e03

Please sign in to comment.