v1.0.9.0
This commit is contained in:
@@ -0,0 +1,161 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Saxonite.Net.Core.Web.Online.Models;
|
||||
using Saxonite.Net.Core.Web.Base.App;
|
||||
using Saxonite.Net.Core.Web.Base.Controllers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Saxonite.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using Saxonite.Net.Standard.Base.App;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Sarand.Net.Standard.Base.Helpers;
|
||||
using System.IO;
|
||||
using System.Drawing;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
using System.Collections.Specialized;
|
||||
|
||||
namespace Saxonite.Net.Core.Web.Online.Controllers
|
||||
{
|
||||
//=======================================================================
|
||||
// Online Image Controller - delivers dynamic images.
|
||||
//=======================================================================
|
||||
public partial class ImageController : SaxController_Online
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public ImageController(SaxLocaliser localiser, ILogger<HomeController> logger) :
|
||||
base(localiser, logger)
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Account Contact image - General
|
||||
//-------------------------------------------------------------------
|
||||
// Account Contact Image request.
|
||||
/// <summary>
|
||||
/// Get the Account Contact Image for the specified account.
|
||||
/// <para>Current User Account is used if no other specified in the encrypted parameter.</para>
|
||||
/// <para>Encrypted parameter:</para>
|
||||
/// <para>- uaie: User Account Id encrypted.</para>
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
[Route("Image/Account/Contact")]
|
||||
public IActionResult GetAccountContactImage(String uaie)
|
||||
{
|
||||
String userAccountIdParam = "";// ToDo Decrypt from uaie value.
|
||||
SysId userAccountId = userAccountIdParam.ToSysId();
|
||||
if (!SysId.IsValid(userAccountId))
|
||||
userAccountId = SessionData.User.UserAccountId;
|
||||
return GetAccountContactImage(userAccountId, Sax.ImageType.Avatar);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Account Contact image - Profile
|
||||
//-------------------------------------------------------------------
|
||||
// Account Profile Contact Image request.
|
||||
/// <summary>
|
||||
/// Get the current Account Profile Contact Image for the specified account.
|
||||
/// <para>Account is always current User Account - this request is only fir use from the user's own profile page.</para>
|
||||
/// <para>'Uploaded' avatar image will take precedence as this will be the latest if present.</para>
|
||||
/// <para>NB Avoid caching this image as it will change whenever a new one is uploaded.</para>
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
[Route("Image/Account/Contact/Profile")]
|
||||
[ResponseCache(NoStore = true, Location = ResponseCacheLocation.None)]
|
||||
public IActionResult GetAccountContactImage()
|
||||
{
|
||||
// Response should not be cached.
|
||||
Response.Headers[HeaderNames.CacheControl] = "no-cache, no-store, must-revalidate, max-age=0";
|
||||
Response.Headers[HeaderNames.Expires] = "-1";
|
||||
SysId userAccountId = SessionData.User.UserAccountId;
|
||||
return GetAccountContactImage(userAccountId, Sax.ImageType.AvatarUpload);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Get the
|
||||
/// </summary>
|
||||
/// <param name="imageTypePriority"></param>
|
||||
/// <returns></returns>
|
||||
private IActionResult GetAccountContactImage(SysId userAccountId, Sax.ImageType imageTypePriority)
|
||||
{
|
||||
String fn = GetType().Name + ".GetAccountContactImage";
|
||||
|
||||
// Validate session and referrer.
|
||||
if (!ValidReferer)
|
||||
return Forbid();
|
||||
if (!ValidUserSession)
|
||||
return Forbid();
|
||||
ItemId userItemId = new ItemId((short)Sax.DataItemType.UserAccount, userAccountId);
|
||||
|
||||
// Retrieve account contact images.
|
||||
SaxItemImage.Params prmItemImage = new SaxItemImage.Params();
|
||||
prmItemImage.ItemIdsIncluded.Add(userItemId);
|
||||
prmItemImage.ImageTypesIncluded.Add(Sax.ImageType.Avatar);
|
||||
prmItemImage.ImageTypesIncluded.Add(Sax.ImageType.AvatarUpload);
|
||||
prmItemImage.StatusCat = SaxItemImage.StatusCat.ActiveOnly;
|
||||
SaxItemImage itemImage = null;
|
||||
foreach (SaxItemImage itemImageCandidate in ItemDataMgr.GetItemImageList(prmItemImage))
|
||||
{
|
||||
// One of the 'Avatar' image types will take precedence.
|
||||
if (itemImage == null || itemImageCandidate.ImageType == imageTypePriority)
|
||||
itemImage = itemImageCandidate;
|
||||
}
|
||||
|
||||
if (itemImage == null)
|
||||
return NotFound();
|
||||
|
||||
// Construct response.
|
||||
return File(itemImage.ImageData, itemImage.ContentType);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Journalist Article image
|
||||
//-------------------------------------------------------------------
|
||||
public static String ParamName_JournalistArticleImageEncrypted { get; } = "jaie";
|
||||
public static String ParamName_ItemImageId { get; } = "iii";
|
||||
/// <summary>
|
||||
/// Get the specified Journalist Article Image.
|
||||
/// <para>Encrypted parameters:</para>
|
||||
/// <para>- iii: item Image Id.</para>
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
[Route("Image/Journalist/Article")]
|
||||
public IActionResult GetJournalistArticleImage(String jaie)
|
||||
{
|
||||
String fn = GetType().Name + ".GetJournalistArticleImage";
|
||||
|
||||
// Validate session and referrer.
|
||||
if (!ValidReferer) return Forbid();
|
||||
if (!ValidUserSession) return Forbid();
|
||||
ItemId userItemId = new ItemId((short)Sax.DataItemType.UserAccount, SessionData.User.UserAccountId);
|
||||
|
||||
// EXtract encrypted parameters.
|
||||
NameValueCollection parameters = ExtractOnlineParams(jaie);
|
||||
if (parameters.Count<1) return Forbid();
|
||||
|
||||
// Item Image.
|
||||
SysId itemImageId = parameters.Get(ParamName_ItemImageId).ToSysId();
|
||||
if (!SysId.IsValid(itemImageId)) return Forbid();
|
||||
SaxItemImage itemImage = ItemDataMgr.GetItemImageById(itemImageId);
|
||||
if (itemImage == null)
|
||||
return NotFound();
|
||||
|
||||
// Construct response.
|
||||
return File(itemImage.ImageData, itemImage.ContentType);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
Reference in New Issue
Block a user