This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ApplicationUser : IdentityUser | |
{ | |
[Column(TypeName = "varchar(50)")] | |
[StringLength(50)] | |
public string ApiAuthKey { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var apiAuthKey = Guid.NewGuid().ToString("N"); | |
var user = new ApplicationUser | |
{ | |
ApiAuthKey = apiAuthKey, | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AuthKeyFilter : ActionFilterAttribute | |
{ | |
private readonly IdentityDbContext _context; | |
private readonly ILogger<AuthKeyFilter> _logger; | |
public AuthKeyFilter(IdentityDbContext context, ILogger<AuthKeyFilter> logger) | |
{ | |
_context = context; | |
_logger = logger; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<string> GetShortUrl(string longUrl, string customBitLink) | |
{ | |
var shortContent = $"{{\"long_url\":\"{longUrl}\",\"group_guid\":\"groupGuid\",\"domain\":\"domain.com\"}}"; | |
var shortenUrlRequest = new HttpRequestMessage(HttpMethod.Post, ShortenUrl) | |
{ | |
Content = new StringContent(shortContent, Encoding.UTF8, "application/json") | |
}; | |
shortenUrlRequest.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _appSettings.BitlyApiToken); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public string ConvertToPhotoCdn(string imageUrl) | |
{ | |
var cdnUrl = _appSettings.CDN.Images.CdnUrl; | |
return _appSettings.CDN.Images.UseCdn | |
? imageUrl.Replace(_appSettings.Azure.Storage.StorageBlobUrl, cdnUrl) | |
: imageUrl; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<img | |
src="@CdnHelper.ConvertToPhotoCdn($"{primaryMediaImage.ImageUrl}?tr=w-252")" | |
srcset="@CdnHelper.ConvertToPhotoCdn($"{primaryMediaImage.ImageUrl}?tr=w-252"), | |
@CdnHelper.ConvertToPhotoCdn($"{primaryMediaImage.ImageUrl}?tr=w-378") 1.5x, | |
@CdnHelper.ConvertToPhotoCdn($"{primaryMediaImage.ImageUrl}?tr=w-504") 2x, | |
@CdnHelper.ConvertToPhotoCdn($"{primaryMediaImage.ImageUrl}?tr=w-756") 3x," | |
alt="@Model.Media.Title" title="@Model.Media.Title" class="coverphoto rounded hoverable" itemprop="image" sizes="252" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var imageCdnUrl = Configuration["CDN:Images:CdnUrl"]; | |
app.Use(async (context, next) => | |
{ | |
context.Response.Headers.Add("Accept-CH", "viewport-width, width, dpr"); | |
context.Response.Headers.Add("Feature-Policy", $"ch-viewport-width {imageCdnUrl};ch-width {imageCdnUrl};ch-dpr {imageCdnUrl};ch-device-memory {imageCdnUrl};ch-rtt {imageCdnUrl};ch-ect {imageCdnUrl};ch-downlink {imageCdnUrl}"); | |
context.Response.Headers.Add("Permissions-Policy", $"ch-viewport-width {imageCdnUrl};ch-width {imageCdnUrl};ch-dpr {imageCdnUrl};ch-device-memory {imageCdnUrl};ch-rtt {imageCdnUrl};ch-ect {imageCdnUrl};ch-downlink {imageCdnUrl}"); | |
await next(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<List<string>> GetCacheKeys() | |
{ | |
var cacheKeys = new List<string>(); | |
var endpoints = Connection.GetEndPoints(); | |
var keys = Connection.GetServer(endpoints.First()).KeysAsync(); | |
var enumerator = keys.GetAsyncEnumerator(); | |
while (await enumerator.MoveNextAsync()) | |
{ | |
var key = enumerator.Current; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// add event cross browser | |
function addEvent(elem, event, fn) { | |
if (elem.addEventListener) { | |
elem.addEventListener(event, fn, false); | |
} else { | |
elem.attachEvent("on" + event, function () { | |
// set the this pointer same as addEventListener when fn is called | |
return fn.call(elem, window.event); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var countryNameToCode = { | |
'Afghanistan': 'AF', | |
'Aland Islands': 'AX', | |
'Albania': 'AL', | |
'Algeria': 'DZ', | |
'American Samoa': 'AS', | |
'Andorra': 'AD', | |
'Angola': 'AO', | |
'Anguilla': 'AI', | |
'Antarctica': 'AQ', |