添加项目文件。
This commit is contained in:
19
TightWiki.Library/ApplicationDbContext.cs
Normal file
19
TightWiki.Library/ApplicationDbContext.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace TightWiki.Library
|
||||
{
|
||||
public class ApplicationDbContext : IdentityDbContext<IdentityUser>
|
||||
{
|
||||
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
base.OnModelCreating(builder);
|
||||
}
|
||||
}
|
||||
}
|
||||
187
TightWiki.Library/ConfirmActionHelper.cs
Normal file
187
TightWiki.Library/ConfirmActionHelper.cs
Normal file
@@ -0,0 +1,187 @@
|
||||
using NTDLS.Helpers;
|
||||
using System.Text;
|
||||
|
||||
namespace TightWiki.Library
|
||||
{
|
||||
public static class ConfirmActionHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Generates a link that navigates via GET to a "confirm action" page where the yes link is RED, but the NO button is still GREEN.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to be displayed.</param>
|
||||
/// <param name="linkLabel">the label for the link that will redirect to this confirm action page.</param>
|
||||
/// <param name="controllerURL">The URL which will handle the click of the "yes" or "no" for the confirm action page.</param>
|
||||
/// <param name="parameter">An optional parameter to pass to the page and controller function.</param>
|
||||
/// <param name="yesOrDefaultRedirectURL">The URL to redirect to AFTER the controller has been called if the user selected YES (or NO, if the NO link is not specified.</param>
|
||||
/// <param name="noRedirectURL">The URL to redirect to AFTER the controller has been called if the user selected NO, if not specified, the same link that is provided to yesOrDefaultRedirectURL is used.</param>
|
||||
/// <returns></returns>
|
||||
public static string GenerateDangerLink(string basePath, string message, string linkLabel, string controllerURL,
|
||||
string? yesOrDefaultRedirectURL, string? noRedirectURL = null)
|
||||
{
|
||||
noRedirectURL ??= yesOrDefaultRedirectURL;
|
||||
|
||||
yesOrDefaultRedirectURL.EnsureNotNull();
|
||||
noRedirectURL.EnsureNotNull();
|
||||
|
||||
var param = new StringBuilder();
|
||||
param.Append($"ControllerURL={Uri.EscapeDataString($"{basePath}{controllerURL}")}");
|
||||
param.Append($"&YesRedirectURL={Uri.EscapeDataString(yesOrDefaultRedirectURL)}");
|
||||
param.Append($"&NoRedirectURL={Uri.EscapeDataString(noRedirectURL)}");
|
||||
param.Append($"&Message={Uri.EscapeDataString(message)}");
|
||||
param.Append($"&Style=Danger");
|
||||
|
||||
return $"<a class=\"btn btn-danger btn-thin\" href=\"{basePath}/Utility/ConfirmAction?{param}\">{linkLabel}</a>";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a link that navigates via GET to a "confirm action" page where the yes link is GREEN.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to be displayed.</param>
|
||||
/// <param name="linkLabel">the label for the link that will redirect to this confirm action page.</param>
|
||||
/// <param name="controllerURL">The URL which will handle the click of the "yes" or "no" for the confirm action page.</param>
|
||||
/// <param name="parameter">An optional parameter to pass to the page and controller function.</param>
|
||||
/// <param name="yesOrDefaultRedirectURL">The URL to redirect to AFTER the controller has been called if the user selected YES (or NO, if the NO link is not specified.</param>
|
||||
/// <param name="noRedirectURL">The URL to redirect to AFTER the controller has been called if the user selected NO, if not specified, the same link that is provided to yesOrDefaultRedirectURL is used.</param>
|
||||
/// <returns></returns>
|
||||
public static string GenerateSafeLink(string basePath, string message, string linkLabel, string controllerURL,
|
||||
string? yesOrDefaultRedirectURL, string? noRedirectURL = null)
|
||||
{
|
||||
noRedirectURL ??= yesOrDefaultRedirectURL;
|
||||
|
||||
yesOrDefaultRedirectURL.EnsureNotNull();
|
||||
noRedirectURL.EnsureNotNull();
|
||||
|
||||
var param = new StringBuilder();
|
||||
param.Append($"ControllerURL={Uri.EscapeDataString($"{basePath}{controllerURL}")}");
|
||||
param.Append($"&YesRedirectURL={Uri.EscapeDataString(yesOrDefaultRedirectURL)}");
|
||||
param.Append($"&NoRedirectURL={Uri.EscapeDataString(noRedirectURL)}");
|
||||
param.Append($"&Message={Uri.EscapeDataString(message)}");
|
||||
param.Append($"&Style=Safe");
|
||||
|
||||
return $"<a class=\"btn btn-success btn-thin\" href=\"{basePath}/Utility/ConfirmAction?{param}\">{linkLabel}</a>";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a link that navigates via GET to a "confirm action" page where the yes link is YELLOW, but the NO button is still GREEN.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to be displayed.</param>
|
||||
/// <param name="linkLabel">the label for the link that will redirect to this confirm action page.</param>
|
||||
/// <param name="controllerURL">The URL which will handle the click of the "yes" or "no" for the confirm action page.</param>
|
||||
/// <param name="parameter">An optional parameter to pass to the page and controller function.</param>
|
||||
/// <param name="yesOrDefaultRedirectURL">The URL to redirect to AFTER the controller has been called if the user selected YES (or NO, if the NO link is not specified.</param>
|
||||
/// <param name="noRedirectURL">The URL to redirect to AFTER the controller has been called if the user selected NO, if not specified, the same link that is provided to yesOrDefaultRedirectURL is used.</param>
|
||||
/// <returns></returns>
|
||||
public static string GenerateWarnLink(string basePath, string message, string linkLabel, string controllerURL,
|
||||
string? yesOrDefaultRedirectURL, string? noRedirectURL = null)
|
||||
{
|
||||
noRedirectURL ??= yesOrDefaultRedirectURL;
|
||||
|
||||
yesOrDefaultRedirectURL.EnsureNotNull();
|
||||
noRedirectURL.EnsureNotNull();
|
||||
|
||||
var param = new StringBuilder();
|
||||
param.Append($"ControllerURL={Uri.EscapeDataString($"{basePath}{controllerURL}")}");
|
||||
param.Append($"&YesRedirectURL={Uri.EscapeDataString(yesOrDefaultRedirectURL)}");
|
||||
param.Append($"&NoRedirectURL={Uri.EscapeDataString(noRedirectURL)}");
|
||||
param.Append($"&Message={Uri.EscapeDataString(message)}");
|
||||
param.Append($"&Style=Warn");
|
||||
|
||||
return $"<a class=\"btn btn-warning btn-thin\" href=\"{basePath}/Utility/ConfirmAction?{param}\">{linkLabel}</a>";
|
||||
}
|
||||
|
||||
/*
|
||||
/// <summary>
|
||||
/// Generates a link that navigates via POST to a "confirm action" page where the yes button is RED, but the NO button is still GREEN.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to be displayed.</param>
|
||||
/// <param name="buttonLabel">the label for the button that will redirect to this confirm action page.</param>
|
||||
/// <param name="controllerURL">The URL which will handle the click of the "yes" or "no" for the confirm action page.</param>
|
||||
/// <param name="parameter">An optional parameter to pass to the page and controller function.</param>
|
||||
/// <param name="yesOrDefaultRedirectURL">The URL to redirect to AFTER the controller has been called if the user selected YES (or NO, if the NO link is not specified.</param>
|
||||
/// <param name="noRedirectURL">The URL to redirect to AFTER the controller has been called if the user selected NO, if not specified, the same link that is provided to yesOrDefaultRedirectURL is used.</param>
|
||||
/// <returns></returns>
|
||||
public static string GenerateDangerButton(string message, string buttonLabel, string controllerURL,
|
||||
string? yesOrDefaultRedirectURL, string? noRedirectURL = null)
|
||||
{
|
||||
noRedirectURL ??= yesOrDefaultRedirectURL;
|
||||
|
||||
yesOrDefaultRedirectURL.EnsureNotNull();
|
||||
noRedirectURL.EnsureNotNull();
|
||||
|
||||
var html = new StringBuilder();
|
||||
html.Append("<form action='/Utility/ConfirmAction' method='post'>");
|
||||
html.Append($"<input type='hidden' name='ControllerURL' value='{controllerURL}' />");
|
||||
html.Append($"<input type='hidden' name='YesRedirectURL' value='{yesOrDefaultRedirectURL}' />");
|
||||
html.Append($"<input type='hidden' name='NoRedirectURL' value='{noRedirectURL}' />");
|
||||
html.Append($"<input type='hidden' name='Message' value='{message}' />");
|
||||
html.Append($"<input type='hidden' name='Style' value='Danger' />");
|
||||
html.Append($"<button type='submit' class='btn btn-danger rounded-0' name='ActionToConfirm' value='PurgeDeletedPages'>{buttonLabel}</button>");
|
||||
html.Append("</form>");
|
||||
|
||||
return html.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a link that navigates via POST to a "confirm action" page where the yes and no buttons are GREEN.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to be displayed.</param>
|
||||
/// <param name="buttonLabel">the label for the button that will redirect to this confirm action page.</param>
|
||||
/// <param name="controllerURL">The URL which will handle the click of the "yes" or "no" for the confirm action page.</param>
|
||||
/// <param name="parameter">An optional parameter to pass to the page and controller function.</param>
|
||||
/// <param name="yesOrDefaultRedirectURL">The URL to redirect to AFTER the controller has been called if the user selected YES (or NO, if the NO link is not specified.</param>
|
||||
/// <param name="noRedirectURL">The URL to redirect to AFTER the controller has been called if the user selected NO, if not specified, the same link that is provided to yesOrDefaultRedirectURL is used.</param>
|
||||
public static string GenerateSafeButton(string message, string buttonLabel, string controllerURL,
|
||||
string? yesOrDefaultRedirectURL, string? noRedirectURL = null)
|
||||
{
|
||||
noRedirectURL ??= yesOrDefaultRedirectURL;
|
||||
|
||||
yesOrDefaultRedirectURL.EnsureNotNull();
|
||||
noRedirectURL.EnsureNotNull();
|
||||
|
||||
var html = new StringBuilder();
|
||||
|
||||
html.Append("<form action='/Utility/ConfirmAction' method='post'>");
|
||||
html.Append($"<input type='hidden' name='ControllerURL' value='{controllerURL}' />");
|
||||
html.Append($"<input type='hidden' name='YesRedirectURL' value='{yesOrDefaultRedirectURL}' />");
|
||||
html.Append($"<input type='hidden' name='NoRedirectURL' value='{noRedirectURL}' />");
|
||||
html.Append($"<input type='hidden' name='Message' value='{message}' />");
|
||||
html.Append($"<input type='hidden' name='Style' value='Safe' />");
|
||||
html.Append($"<button type='submit' class='btn btn-success rounded-0' name='ActionToConfirm' value='PurgeDeletedPages'>{buttonLabel}</button>");
|
||||
html.Append("</form>");
|
||||
|
||||
return html.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a link that navigates via POST to a "confirm action" page where the yes button is YELLOW, but the NO button is still GREEN.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to be displayed.</param>
|
||||
/// <param name="buttonLabel">the label for the button that will redirect to this confirm action page.</param>
|
||||
/// <param name="controllerURL">The URL which will handle the click of the "yes" or "no" for the confirm action page.</param>
|
||||
/// <param name="parameter">An optional parameter to pass to the page and controller function.</param>
|
||||
/// <param name="yesOrDefaultRedirectURL">The URL to redirect to AFTER the controller has been called if the user selected YES (or NO, if the NO link is not specified.</param>
|
||||
/// <param name="noRedirectURL">The URL to redirect to AFTER the controller has been called if the user selected NO, if not specified, the same link that is provided to yesOrDefaultRedirectURL is used.</param>
|
||||
public static string GenerateWarnButton(string message, string buttonLabel, string controllerURL,
|
||||
string? yesOrDefaultRedirectURL, string? noRedirectURL = null)
|
||||
{
|
||||
noRedirectURL ??= yesOrDefaultRedirectURL;
|
||||
|
||||
yesOrDefaultRedirectURL.EnsureNotNull();
|
||||
noRedirectURL.EnsureNotNull();
|
||||
|
||||
var html = new StringBuilder();
|
||||
|
||||
html.Append("<form action='/Utility/ConfirmAction' method='post'>");
|
||||
html.Append($"<input type='hidden' name='ControllerURL' value='{controllerURL}' />");
|
||||
html.Append($"<input type='hidden' name='YesRedirectURL' value='{yesOrDefaultRedirectURL}' />");
|
||||
html.Append($"<input type='hidden' name='NoRedirectURL' value='{noRedirectURL}' />");
|
||||
html.Append($"<input type='hidden' name='Message' value='{message}' />");
|
||||
html.Append($"<input type='hidden' name='Style' value='Warn' />");
|
||||
html.Append($"<button type='submit' class='btn btn-warning rounded-0' name='ActionToConfirm' value='PurgeDeletedPages'>{buttonLabel}</button>");
|
||||
html.Append("</form>");
|
||||
|
||||
return html.ToString();
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
65
TightWiki.Library/Constants.cs
Normal file
65
TightWiki.Library/Constants.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
namespace TightWiki.Library
|
||||
{
|
||||
public static class Constants
|
||||
{
|
||||
public const string CRYPTOCHECK = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
public const string DEFAULTUSERNAME = "admin@tightwiki.com";
|
||||
public const string DEFAULTACCOUNT = "admin";
|
||||
public const string DEFAULTPASSWORD = "2Tight2Wiki@";
|
||||
|
||||
public enum WikiTheme
|
||||
{
|
||||
Light,
|
||||
Dark
|
||||
}
|
||||
|
||||
public enum AdminPasswordChangeState
|
||||
{
|
||||
/// <summary>
|
||||
/// The password has not been changed, display a big warning.
|
||||
/// </summary>
|
||||
IsDefault,
|
||||
/// <summary>
|
||||
/// All is well!
|
||||
/// </summary>
|
||||
HasBeenChanged,
|
||||
/// <summary>
|
||||
/// The default password status does not exist and the password needs to be set to default.
|
||||
/// </summary>
|
||||
NeedsToBeSet
|
||||
}
|
||||
|
||||
public static class WikiInstruction
|
||||
{
|
||||
public static string Deprecate { get; } = "Deprecate";
|
||||
public static string Protect { get; } = "Protect";
|
||||
public static string Template { get; } = "Template";
|
||||
public static string Review { get; } = "Review";
|
||||
public static string Include { get; } = "Include";
|
||||
public static string Draft { get; } = "Draft";
|
||||
public static string NoCache { get; } = "NoCache";
|
||||
public static string HideFooterComments { get; } = "HideFooterComments";
|
||||
public static string HideFooterLastModified { get; } = "HideFooterLastModified";
|
||||
}
|
||||
|
||||
public static class Roles
|
||||
{
|
||||
/// <summary>
|
||||
/// Administrators can do anything. Add, edit, delete, pages, users, etc.
|
||||
/// </summary>
|
||||
public const string Administrator = "Administrator";
|
||||
/// <summary>
|
||||
/// Read-only user with a profile.
|
||||
/// </summary>
|
||||
public const string Member = "Member";
|
||||
/// <summary>
|
||||
/// Contributor can add and edit pages.
|
||||
/// </summary>
|
||||
public const string Contributor = "Contributor";
|
||||
/// <summary>
|
||||
/// Moderators can add, edit and delete pages.
|
||||
/// </summary>
|
||||
public const string Moderator = "Moderator";
|
||||
}
|
||||
}
|
||||
}
|
||||
30
TightWiki.Library/CountryItem.cs
Normal file
30
TightWiki.Library/CountryItem.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace TightWiki.Library
|
||||
{
|
||||
public class CountryItem
|
||||
{
|
||||
public string Text { get; set; } = string.Empty;
|
||||
public string Value { get; set; } = string.Empty;
|
||||
|
||||
public static List<CountryItem> GetAll()
|
||||
{
|
||||
var list = new List<CountryItem>();
|
||||
|
||||
foreach (var ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
|
||||
{
|
||||
var regionInfo = new RegionInfo(ci.Name);
|
||||
if (list.Where(o => o.Value == regionInfo.Name).Any() == false)
|
||||
{
|
||||
list.Add(new CountryItem
|
||||
{
|
||||
Text = regionInfo.EnglishName,
|
||||
Value = regionInfo.Name
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return list.OrderBy(o => o.Text).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
18
TightWiki.Library/GuidTypeHandler.cs
Normal file
18
TightWiki.Library/GuidTypeHandler.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Dapper;
|
||||
using System.Data;
|
||||
|
||||
namespace TightWiki.Library
|
||||
{
|
||||
public class GuidTypeHandler : SqlMapper.TypeHandler<Guid>
|
||||
{
|
||||
public override void SetValue(IDbDataParameter parameter, Guid value)
|
||||
{
|
||||
parameter.Value = value.ToString();
|
||||
}
|
||||
|
||||
public override Guid Parse(object value)
|
||||
{
|
||||
return Guid.Parse((string)value);
|
||||
}
|
||||
}
|
||||
}
|
||||
72
TightWiki.Library/Images.cs
Normal file
72
TightWiki.Library/Images.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using ImageMagick;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
|
||||
namespace TightWiki.Library
|
||||
{
|
||||
public static class Images
|
||||
{
|
||||
public enum ImageFormat
|
||||
{
|
||||
Png,
|
||||
Jpeg,
|
||||
Bmp,
|
||||
Tiff,
|
||||
Gif
|
||||
}
|
||||
|
||||
public static byte[] ResizeGifImage(byte[] imageBytes, int width, int height)
|
||||
{
|
||||
using var imageCollection = new MagickImageCollection(imageBytes);
|
||||
|
||||
if (imageCollection.Count > 10)
|
||||
{
|
||||
Parallel.ForEach(imageCollection, frame =>
|
||||
{
|
||||
frame.Sample((uint)width, (uint)height);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Parallel.ForEach(imageCollection, frame =>
|
||||
{
|
||||
frame.Resize((uint)width, (uint)height);
|
||||
});
|
||||
}
|
||||
|
||||
return imageCollection.ToByteArray();
|
||||
}
|
||||
|
||||
public static Image ResizeImage(Image image, int width, int height)
|
||||
{
|
||||
image.Mutate(x => x.Resize(width, height));
|
||||
return image;
|
||||
}
|
||||
|
||||
public static string BestEffortConvertImage(Image image, MemoryStream ms, string preferredContentType)
|
||||
{
|
||||
switch (preferredContentType.ToLower())
|
||||
{
|
||||
case "image/png":
|
||||
image.SaveAsPng(ms);
|
||||
return preferredContentType;
|
||||
case "image/jpeg":
|
||||
image.SaveAsJpeg(ms);
|
||||
return preferredContentType;
|
||||
case "image/bmp":
|
||||
image.SaveAsBmp(ms);
|
||||
return preferredContentType;
|
||||
case "image/gif":
|
||||
throw new NotImplementedException("Use [ResizeGifImage] for saving animated images.");
|
||||
//image.SaveAsGif(ms);
|
||||
//return preferredContentType;
|
||||
case "image/tiff":
|
||||
image.SaveAsTiff(ms);
|
||||
return preferredContentType;
|
||||
default:
|
||||
image.SaveAsPng(ms);
|
||||
return "image/png";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
13
TightWiki.Library/Interfaces/IAccountProfile.cs
Normal file
13
TightWiki.Library/Interfaces/IAccountProfile.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace TightWiki.Library.Interfaces
|
||||
{
|
||||
public interface IAccountProfile
|
||||
{
|
||||
public string Role { get; set; }
|
||||
public Guid UserId { get; set; }
|
||||
public string EmailAddress { get; set; }
|
||||
public string AccountName { get; set; }
|
||||
public string Navigation { get; set; }
|
||||
public string? Theme { get; set; }
|
||||
public string TimeZone { get; set; }
|
||||
}
|
||||
}
|
||||
19
TightWiki.Library/Interfaces/IPage.cs
Normal file
19
TightWiki.Library/Interfaces/IPage.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
namespace TightWiki.Library.Interfaces
|
||||
{
|
||||
public interface IPage
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int Revision { get; set; }
|
||||
public int MostCurrentRevision { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string Namespace { get; }
|
||||
public string Title { get; }
|
||||
public string Body { get; }
|
||||
public string Navigation { get; }
|
||||
public DateTime CreatedDate { get; set; }
|
||||
public DateTime ModifiedDate { get; set; }
|
||||
public bool IsHistoricalVersion { get; }
|
||||
public bool Exists { get; }
|
||||
}
|
||||
}
|
||||
44
TightWiki.Library/Interfaces/ISessionState.cs
Normal file
44
TightWiki.Library/Interfaces/ISessionState.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace TightWiki.Library.Interfaces
|
||||
{
|
||||
public interface ISessionState
|
||||
{
|
||||
public IAccountProfile? Profile { get; set; }
|
||||
|
||||
IQueryCollection? QueryString { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Is the current user (or anonymous) allowed to view?
|
||||
/// </summary>
|
||||
public bool CanView => true;
|
||||
|
||||
/// <summary>
|
||||
/// Is the current user allowed to edit?
|
||||
/// </summary>
|
||||
public bool CanEdit { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Is the current user allowed to perform administrative functions?
|
||||
/// </summary>
|
||||
public bool CanAdmin { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Is the current user allowed to moderate content (such as delete comments, and view moderation tools)?
|
||||
/// </summary>
|
||||
public bool CanModerate { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Is the current user allowed to create pages?
|
||||
/// </summary>
|
||||
public bool CanCreate { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Is the current user allowed to delete unprotected pages?
|
||||
/// </summary>
|
||||
public bool CanDelete { get; }
|
||||
|
||||
public DateTime LocalizeDateTime(DateTime datetime);
|
||||
public TimeZoneInfo GetPreferredTimeZone();
|
||||
}
|
||||
}
|
||||
7
TightWiki.Library/Interfaces/IWikiEmailSender.cs
Normal file
7
TightWiki.Library/Interfaces/IWikiEmailSender.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace TightWiki.Library.Interfaces
|
||||
{
|
||||
public interface IWikiEmailSender
|
||||
{
|
||||
Task SendEmailAsync(string email, string subject, string htmlMessage);
|
||||
}
|
||||
}
|
||||
37
TightWiki.Library/LanguageItem.cs
Normal file
37
TightWiki.Library/LanguageItem.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace TightWiki.Library
|
||||
{
|
||||
public class LanguageItem
|
||||
{
|
||||
public string Text { get; set; } = string.Empty;
|
||||
public string Value { get; set; } = string.Empty;
|
||||
|
||||
public static List<LanguageItem> GetAll()
|
||||
{
|
||||
var list = new List<LanguageItem>();
|
||||
|
||||
var cultureInfo = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
|
||||
|
||||
foreach (var culture in cultureInfo)
|
||||
{
|
||||
var name = culture.NativeName;
|
||||
if (name.Contains('('))
|
||||
{
|
||||
name = name.Substring(0, name.IndexOf('(')).Trim();
|
||||
}
|
||||
|
||||
if (list.Where(o => o.Value == name).Any() == false)
|
||||
{
|
||||
list.Add(new LanguageItem
|
||||
{
|
||||
Text = name,
|
||||
Value = name
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return list.OrderBy(o => o.Text).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
410
TightWiki.Library/MimeTypes.cs
Normal file
410
TightWiki.Library/MimeTypes.cs
Normal file
@@ -0,0 +1,410 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace TightWiki.Library
|
||||
{
|
||||
internal static class MimeTypes
|
||||
{
|
||||
/// <summary>
|
||||
/// Given a file path, determine the MIME type
|
||||
/// </summary>
|
||||
/// <param name="subpath">A file path</param>
|
||||
/// <param name="contentType">The resulting MIME type</param>
|
||||
/// <returns>True if MIME type could be determined</returns>
|
||||
public static bool TryGetContentType(string filePath, [MaybeNullWhen(false)] out string contentType)
|
||||
{
|
||||
string extension = Path.GetExtension(filePath);
|
||||
if (extension == null)
|
||||
{
|
||||
contentType = null;
|
||||
return false;
|
||||
}
|
||||
return Collection.TryGetValue(extension, out contentType);
|
||||
}
|
||||
|
||||
//Borrowed from FileExtensionContentTypeProvider().TryGetContentType
|
||||
public static Dictionary<string, string> Collection = new(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
{ ".323", "text/h323" },
|
||||
{ ".3g2", "video/3gpp2" },
|
||||
{ ".3gp2", "video/3gpp2" },
|
||||
{ ".3gp", "video/3gpp" },
|
||||
{ ".3gpp", "video/3gpp" },
|
||||
{ ".aac", "audio/aac" },
|
||||
{ ".aaf", "application/octet-stream" },
|
||||
{ ".aca", "application/octet-stream" },
|
||||
{ ".accdb", "application/msaccess" },
|
||||
{ ".accde", "application/msaccess" },
|
||||
{ ".accdt", "application/msaccess" },
|
||||
{ ".acx", "application/internet-property-stream" },
|
||||
{ ".adt", "audio/vnd.dlna.adts" },
|
||||
{ ".adts", "audio/vnd.dlna.adts" },
|
||||
{ ".afm", "application/octet-stream" },
|
||||
{ ".ai", "application/postscript" },
|
||||
{ ".aif", "audio/x-aiff" },
|
||||
{ ".aifc", "audio/aiff" },
|
||||
{ ".aiff", "audio/aiff" },
|
||||
{ ".appcache", "text/cache-manifest" },
|
||||
{ ".application", "application/x-ms-application" },
|
||||
{ ".art", "image/x-jg" },
|
||||
{ ".asd", "application/octet-stream" },
|
||||
{ ".asf", "video/x-ms-asf" },
|
||||
{ ".asi", "application/octet-stream" },
|
||||
{ ".asm", "text/plain" },
|
||||
{ ".asr", "video/x-ms-asf" },
|
||||
{ ".asx", "video/x-ms-asf" },
|
||||
{ ".atom", "application/atom+xml" },
|
||||
{ ".au", "audio/basic" },
|
||||
{ ".avi", "video/x-msvideo" },
|
||||
{ ".axs", "application/olescript" },
|
||||
{ ".bas", "text/plain" },
|
||||
{ ".bcpio", "application/x-bcpio" },
|
||||
{ ".bin", "application/octet-stream" },
|
||||
{ ".bmp", "image/bmp" },
|
||||
{ ".c", "text/plain" },
|
||||
{ ".cab", "application/vnd.ms-cab-compressed" },
|
||||
{ ".calx", "application/vnd.ms-office.calx" },
|
||||
{ ".cat", "application/vnd.ms-pki.seccat" },
|
||||
{ ".cdf", "application/x-cdf" },
|
||||
{ ".chm", "application/octet-stream" },
|
||||
{ ".class", "application/x-java-applet" },
|
||||
{ ".clp", "application/x-msclip" },
|
||||
{ ".cmx", "image/x-cmx" },
|
||||
{ ".cnf", "text/plain" },
|
||||
{ ".cod", "image/cis-cod" },
|
||||
{ ".cpio", "application/x-cpio" },
|
||||
{ ".cpp", "text/plain" },
|
||||
{ ".crd", "application/x-mscardfile" },
|
||||
{ ".crl", "application/pkix-crl" },
|
||||
{ ".crt", "application/x-x509-ca-cert" },
|
||||
{ ".csh", "application/x-csh" },
|
||||
{ ".css", "text/css" },
|
||||
{ ".csv", "text/csv" }, // https://tools.ietf.org/html/rfc7111#section-5.1
|
||||
{ ".cur", "application/octet-stream" },
|
||||
{ ".dcr", "application/x-director" },
|
||||
{ ".deploy", "application/octet-stream" },
|
||||
{ ".der", "application/x-x509-ca-cert" },
|
||||
{ ".dib", "image/bmp" },
|
||||
{ ".dir", "application/x-director" },
|
||||
{ ".disco", "text/xml" },
|
||||
{ ".dlm", "text/dlm" },
|
||||
{ ".doc", "application/msword" },
|
||||
{ ".docm", "application/vnd.ms-word.document.macroEnabled.12" },
|
||||
{ ".docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document" },
|
||||
{ ".dot", "application/msword" },
|
||||
{ ".dotm", "application/vnd.ms-word.template.macroEnabled.12" },
|
||||
{ ".dotx", "application/vnd.openxmlformats-officedocument.wordprocessingml.template" },
|
||||
{ ".dsp", "application/octet-stream" },
|
||||
{ ".dtd", "text/xml" },
|
||||
{ ".dvi", "application/x-dvi" },
|
||||
{ ".dvr-ms", "video/x-ms-dvr" },
|
||||
{ ".dwf", "drawing/x-dwf" },
|
||||
{ ".dwp", "application/octet-stream" },
|
||||
{ ".dxr", "application/x-director" },
|
||||
{ ".eml", "message/rfc822" },
|
||||
{ ".emz", "application/octet-stream" },
|
||||
{ ".eot", "application/vnd.ms-fontobject" },
|
||||
{ ".eps", "application/postscript" },
|
||||
{ ".etx", "text/x-setext" },
|
||||
{ ".evy", "application/envoy" },
|
||||
{ ".exe", "application/vnd.microsoft.portable-executable" }, // https://www.iana.org/assignments/media-types/application/vnd.microsoft.portable-executable
|
||||
{ ".fdf", "application/vnd.fdf" },
|
||||
{ ".fif", "application/fractals" },
|
||||
{ ".fla", "application/octet-stream" },
|
||||
{ ".flr", "x-world/x-vrml" },
|
||||
{ ".flv", "video/x-flv" },
|
||||
{ ".gif", "image/gif" },
|
||||
{ ".gtar", "application/x-gtar" },
|
||||
{ ".gz", "application/x-gzip" },
|
||||
{ ".h", "text/plain" },
|
||||
{ ".hdf", "application/x-hdf" },
|
||||
{ ".hdml", "text/x-hdml" },
|
||||
{ ".hhc", "application/x-oleobject" },
|
||||
{ ".hhk", "application/octet-stream" },
|
||||
{ ".hhp", "application/octet-stream" },
|
||||
{ ".hlp", "application/winhlp" },
|
||||
{ ".hqx", "application/mac-binhex40" },
|
||||
{ ".hta", "application/hta" },
|
||||
{ ".htc", "text/x-component" },
|
||||
{ ".htm", "text/html" },
|
||||
{ ".html", "text/html" },
|
||||
{ ".htt", "text/webviewhtml" },
|
||||
{ ".hxt", "text/html" },
|
||||
{ ".ical", "text/calendar" },
|
||||
{ ".icalendar", "text/calendar" },
|
||||
{ ".ico", "image/x-icon" },
|
||||
{ ".ics", "text/calendar" },
|
||||
{ ".ief", "image/ief" },
|
||||
{ ".ifb", "text/calendar" },
|
||||
{ ".iii", "application/x-iphone" },
|
||||
{ ".inf", "application/octet-stream" },
|
||||
{ ".ins", "application/x-internet-signup" },
|
||||
{ ".isp", "application/x-internet-signup" },
|
||||
{ ".IVF", "video/x-ivf" },
|
||||
{ ".jar", "application/java-archive" },
|
||||
{ ".java", "application/octet-stream" },
|
||||
{ ".jck", "application/liquidmotion" },
|
||||
{ ".jcz", "application/liquidmotion" },
|
||||
{ ".jfif", "image/pjpeg" },
|
||||
{ ".jpb", "application/octet-stream" },
|
||||
{ ".jpe", "image/jpeg" },
|
||||
{ ".jpeg", "image/jpeg" },
|
||||
{ ".jpg", "image/jpeg" },
|
||||
{ ".js", "text/javascript" },
|
||||
{ ".json", "application/json" },
|
||||
{ ".jsx", "text/jscript" },
|
||||
{ ".latex", "application/x-latex" },
|
||||
{ ".lit", "application/x-ms-reader" },
|
||||
{ ".lpk", "application/octet-stream" },
|
||||
{ ".lsf", "video/x-la-asf" },
|
||||
{ ".lsx", "video/x-la-asf" },
|
||||
{ ".lzh", "application/octet-stream" },
|
||||
{ ".m13", "application/x-msmediaview" },
|
||||
{ ".m14", "application/x-msmediaview" },
|
||||
{ ".m1v", "video/mpeg" },
|
||||
{ ".m2ts", "video/vnd.dlna.mpeg-tts" },
|
||||
{ ".m3u", "audio/x-mpegurl" },
|
||||
{ ".m4a", "audio/mp4" },
|
||||
{ ".m4v", "video/mp4" },
|
||||
{ ".man", "application/x-troff-man" },
|
||||
{ ".manifest", "application/x-ms-manifest" },
|
||||
{ ".map", "text/plain" },
|
||||
{ ".markdown", "text/markdown" },
|
||||
{ ".md", "text/markdown" },
|
||||
{ ".mdb", "application/x-msaccess" },
|
||||
{ ".mdp", "application/octet-stream" },
|
||||
{ ".me", "application/x-troff-me" },
|
||||
{ ".mht", "message/rfc822" },
|
||||
{ ".mhtml", "message/rfc822" },
|
||||
{ ".mid", "audio/mid" },
|
||||
{ ".midi", "audio/mid" },
|
||||
{ ".mix", "application/octet-stream" },
|
||||
{ ".mjs", "text/javascript" },
|
||||
{ ".mmf", "application/x-smaf" },
|
||||
{ ".mno", "text/xml" },
|
||||
{ ".mny", "application/x-msmoney" },
|
||||
{ ".mov", "video/quicktime" },
|
||||
{ ".movie", "video/x-sgi-movie" },
|
||||
{ ".mp2", "video/mpeg" },
|
||||
{ ".mp3", "audio/mpeg" },
|
||||
{ ".mp4", "video/mp4" },
|
||||
{ ".mp4v", "video/mp4" },
|
||||
{ ".mpa", "video/mpeg" },
|
||||
{ ".mpe", "video/mpeg" },
|
||||
{ ".mpeg", "video/mpeg" },
|
||||
{ ".mpg", "video/mpeg" },
|
||||
{ ".mpp", "application/vnd.ms-project" },
|
||||
{ ".mpv2", "video/mpeg" },
|
||||
{ ".ms", "application/x-troff-ms" },
|
||||
{ ".msi", "application/octet-stream" },
|
||||
{ ".mso", "application/octet-stream" },
|
||||
{ ".mvb", "application/x-msmediaview" },
|
||||
{ ".mvc", "application/x-miva-compiled" },
|
||||
{ ".nc", "application/x-netcdf" },
|
||||
{ ".nsc", "video/x-ms-asf" },
|
||||
{ ".nws", "message/rfc822" },
|
||||
{ ".ocx", "application/octet-stream" },
|
||||
{ ".oda", "application/oda" },
|
||||
{ ".odc", "text/x-ms-odc" },
|
||||
{ ".ods", "application/oleobject" },
|
||||
{ ".oga", "audio/ogg" },
|
||||
{ ".ogg", "video/ogg" },
|
||||
{ ".ogv", "video/ogg" },
|
||||
{ ".ogx", "application/ogg" },
|
||||
{ ".one", "application/onenote" },
|
||||
{ ".onea", "application/onenote" },
|
||||
{ ".onetoc", "application/onenote" },
|
||||
{ ".onetoc2", "application/onenote" },
|
||||
{ ".onetmp", "application/onenote" },
|
||||
{ ".onepkg", "application/onenote" },
|
||||
{ ".osdx", "application/opensearchdescription+xml" },
|
||||
{ ".otf", "font/otf" },
|
||||
{ ".p10", "application/pkcs10" },
|
||||
{ ".p12", "application/x-pkcs12" },
|
||||
{ ".p7b", "application/x-pkcs7-certificates" },
|
||||
{ ".p7c", "application/pkcs7-mime" },
|
||||
{ ".p7m", "application/pkcs7-mime" },
|
||||
{ ".p7r", "application/x-pkcs7-certreqresp" },
|
||||
{ ".p7s", "application/pkcs7-signature" },
|
||||
{ ".pbm", "image/x-portable-bitmap" },
|
||||
{ ".pcx", "application/octet-stream" },
|
||||
{ ".pcz", "application/octet-stream" },
|
||||
{ ".pdf", "application/pdf" },
|
||||
{ ".pfb", "application/octet-stream" },
|
||||
{ ".pfm", "application/octet-stream" },
|
||||
{ ".pfx", "application/x-pkcs12" },
|
||||
{ ".pgm", "image/x-portable-graymap" },
|
||||
{ ".pko", "application/vnd.ms-pki.pko" },
|
||||
{ ".pma", "application/x-perfmon" },
|
||||
{ ".pmc", "application/x-perfmon" },
|
||||
{ ".pml", "application/x-perfmon" },
|
||||
{ ".pmr", "application/x-perfmon" },
|
||||
{ ".pmw", "application/x-perfmon" },
|
||||
{ ".png", "image/png" },
|
||||
{ ".pnm", "image/x-portable-anymap" },
|
||||
{ ".pnz", "image/png" },
|
||||
{ ".pot", "application/vnd.ms-powerpoint" },
|
||||
{ ".potm", "application/vnd.ms-powerpoint.template.macroEnabled.12" },
|
||||
{ ".potx", "application/vnd.openxmlformats-officedocument.presentationml.template" },
|
||||
{ ".ppam", "application/vnd.ms-powerpoint.addin.macroEnabled.12" },
|
||||
{ ".ppm", "image/x-portable-pixmap" },
|
||||
{ ".pps", "application/vnd.ms-powerpoint" },
|
||||
{ ".ppsm", "application/vnd.ms-powerpoint.slideshow.macroEnabled.12" },
|
||||
{ ".ppsx", "application/vnd.openxmlformats-officedocument.presentationml.slideshow" },
|
||||
{ ".ppt", "application/vnd.ms-powerpoint" },
|
||||
{ ".pptm", "application/vnd.ms-powerpoint.presentation.macroEnabled.12" },
|
||||
{ ".pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation" },
|
||||
{ ".prf", "application/pics-rules" },
|
||||
{ ".prm", "application/octet-stream" },
|
||||
{ ".prx", "application/octet-stream" },
|
||||
{ ".ps", "application/postscript" },
|
||||
{ ".psd", "application/octet-stream" },
|
||||
{ ".psm", "application/octet-stream" },
|
||||
{ ".psp", "application/octet-stream" },
|
||||
{ ".pub", "application/x-mspublisher" },
|
||||
{ ".qt", "video/quicktime" },
|
||||
{ ".qtl", "application/x-quicktimeplayer" },
|
||||
{ ".qxd", "application/octet-stream" },
|
||||
{ ".ra", "audio/x-pn-realaudio" },
|
||||
{ ".ram", "audio/x-pn-realaudio" },
|
||||
{ ".rar", "application/octet-stream" },
|
||||
{ ".ras", "image/x-cmu-raster" },
|
||||
{ ".rf", "image/vnd.rn-realflash" },
|
||||
{ ".rgb", "image/x-rgb" },
|
||||
{ ".rm", "application/vnd.rn-realmedia" },
|
||||
{ ".rmi", "audio/mid" },
|
||||
{ ".roff", "application/x-troff" },
|
||||
{ ".rpm", "audio/x-pn-realaudio-plugin" },
|
||||
{ ".rtf", "application/rtf" },
|
||||
{ ".rtx", "text/richtext" },
|
||||
{ ".scd", "application/x-msschedule" },
|
||||
{ ".sct", "text/scriptlet" },
|
||||
{ ".sea", "application/octet-stream" },
|
||||
{ ".setpay", "application/set-payment-initiation" },
|
||||
{ ".setreg", "application/set-registration-initiation" },
|
||||
{ ".sgml", "text/sgml" },
|
||||
{ ".sh", "application/x-sh" },
|
||||
{ ".shar", "application/x-shar" },
|
||||
{ ".sit", "application/x-stuffit" },
|
||||
{ ".sldm", "application/vnd.ms-powerpoint.slide.macroEnabled.12" },
|
||||
{ ".sldx", "application/vnd.openxmlformats-officedocument.presentationml.slide" },
|
||||
{ ".smd", "audio/x-smd" },
|
||||
{ ".smi", "application/octet-stream" },
|
||||
{ ".smx", "audio/x-smd" },
|
||||
{ ".smz", "audio/x-smd" },
|
||||
{ ".snd", "audio/basic" },
|
||||
{ ".snp", "application/octet-stream" },
|
||||
{ ".spc", "application/x-pkcs7-certificates" },
|
||||
{ ".spl", "application/futuresplash" },
|
||||
{ ".spx", "audio/ogg" },
|
||||
{ ".src", "application/x-wais-source" },
|
||||
{ ".ssm", "application/streamingmedia" },
|
||||
{ ".sst", "application/vnd.ms-pki.certstore" },
|
||||
{ ".stl", "application/vnd.ms-pki.stl" },
|
||||
{ ".sv4cpio", "application/x-sv4cpio" },
|
||||
{ ".sv4crc", "application/x-sv4crc" },
|
||||
{ ".svg", "image/svg+xml" },
|
||||
{ ".svgz", "image/svg+xml" },
|
||||
{ ".swf", "application/x-shockwave-flash" },
|
||||
{ ".t", "application/x-troff" },
|
||||
{ ".tar", "application/x-tar" },
|
||||
{ ".tcl", "application/x-tcl" },
|
||||
{ ".tex", "application/x-tex" },
|
||||
{ ".texi", "application/x-texinfo" },
|
||||
{ ".texinfo", "application/x-texinfo" },
|
||||
{ ".tgz", "application/x-compressed" },
|
||||
{ ".thmx", "application/vnd.ms-officetheme" },
|
||||
{ ".thn", "application/octet-stream" },
|
||||
{ ".tif", "image/tiff" },
|
||||
{ ".tiff", "image/tiff" },
|
||||
{ ".toc", "application/octet-stream" },
|
||||
{ ".tr", "application/x-troff" },
|
||||
{ ".trm", "application/x-msterminal" },
|
||||
{ ".ts", "video/vnd.dlna.mpeg-tts" },
|
||||
{ ".tsv", "text/tab-separated-values" },
|
||||
{ ".ttc", "application/x-font-ttf" },
|
||||
{ ".ttf", "application/x-font-ttf" },
|
||||
{ ".tts", "video/vnd.dlna.mpeg-tts" },
|
||||
{ ".txt", "text/plain" },
|
||||
{ ".u32", "application/octet-stream" },
|
||||
{ ".uls", "text/iuls" },
|
||||
{ ".ustar", "application/x-ustar" },
|
||||
{ ".vbs", "text/vbscript" },
|
||||
{ ".vcf", "text/x-vcard" },
|
||||
{ ".vcs", "text/plain" },
|
||||
{ ".vdx", "application/vnd.ms-visio.viewer" },
|
||||
{ ".vml", "text/xml" },
|
||||
{ ".vsd", "application/vnd.visio" },
|
||||
{ ".vss", "application/vnd.visio" },
|
||||
{ ".vst", "application/vnd.visio" },
|
||||
{ ".vsto", "application/x-ms-vsto" },
|
||||
{ ".vsw", "application/vnd.visio" },
|
||||
{ ".vsx", "application/vnd.visio" },
|
||||
{ ".vtx", "application/vnd.visio" },
|
||||
{ ".wasm", "application/wasm" },
|
||||
{ ".wav", "audio/wav" },
|
||||
{ ".wax", "audio/x-ms-wax" },
|
||||
{ ".wbmp", "image/vnd.wap.wbmp" },
|
||||
{ ".wcm", "application/vnd.ms-works" },
|
||||
{ ".wdb", "application/vnd.ms-works" },
|
||||
{ ".webm", "video/webm" },
|
||||
{ ".webmanifest", "application/manifest+json" }, // https://w3c.github.io/manifest/#media-type-registration
|
||||
{ ".webp", "image/webp" },
|
||||
{ ".wks", "application/vnd.ms-works" },
|
||||
{ ".wm", "video/x-ms-wm" },
|
||||
{ ".wma", "audio/x-ms-wma" },
|
||||
{ ".wmd", "application/x-ms-wmd" },
|
||||
{ ".wmf", "application/x-msmetafile" },
|
||||
{ ".wml", "text/vnd.wap.wml" },
|
||||
{ ".wmlc", "application/vnd.wap.wmlc" },
|
||||
{ ".wmls", "text/vnd.wap.wmlscript" },
|
||||
{ ".wmlsc", "application/vnd.wap.wmlscriptc" },
|
||||
{ ".wmp", "video/x-ms-wmp" },
|
||||
{ ".wmv", "video/x-ms-wmv" },
|
||||
{ ".wmx", "video/x-ms-wmx" },
|
||||
{ ".wmz", "application/x-ms-wmz" },
|
||||
{ ".woff", "application/font-woff" }, // https://www.w3.org/TR/WOFF/#appendix-b
|
||||
{ ".woff2", "font/woff2" }, // https://www.w3.org/TR/WOFF2/#IMT
|
||||
{ ".wps", "application/vnd.ms-works" },
|
||||
{ ".wri", "application/x-mswrite" },
|
||||
{ ".wrl", "x-world/x-vrml" },
|
||||
{ ".wrz", "x-world/x-vrml" },
|
||||
{ ".wsdl", "text/xml" },
|
||||
{ ".wtv", "video/x-ms-wtv" },
|
||||
{ ".wvx", "video/x-ms-wvx" },
|
||||
{ ".x", "application/directx" },
|
||||
{ ".xaf", "x-world/x-vrml" },
|
||||
{ ".xaml", "application/xaml+xml" },
|
||||
{ ".xap", "application/x-silverlight-app" },
|
||||
{ ".xbap", "application/x-ms-xbap" },
|
||||
{ ".xbm", "image/x-xbitmap" },
|
||||
{ ".xdr", "text/plain" },
|
||||
{ ".xht", "application/xhtml+xml" },
|
||||
{ ".xhtml", "application/xhtml+xml" },
|
||||
{ ".xla", "application/vnd.ms-excel" },
|
||||
{ ".xlam", "application/vnd.ms-excel.addin.macroEnabled.12" },
|
||||
{ ".xlc", "application/vnd.ms-excel" },
|
||||
{ ".xlm", "application/vnd.ms-excel" },
|
||||
{ ".xls", "application/vnd.ms-excel" },
|
||||
{ ".xlsb", "application/vnd.ms-excel.sheet.binary.macroEnabled.12" },
|
||||
{ ".xlsm", "application/vnd.ms-excel.sheet.macroEnabled.12" },
|
||||
{ ".xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" },
|
||||
{ ".xlt", "application/vnd.ms-excel" },
|
||||
{ ".xltm", "application/vnd.ms-excel.template.macroEnabled.12" },
|
||||
{ ".xltx", "application/vnd.openxmlformats-officedocument.spreadsheetml.template" },
|
||||
{ ".xlw", "application/vnd.ms-excel" },
|
||||
{ ".xml", "text/xml" },
|
||||
{ ".xof", "x-world/x-vrml" },
|
||||
{ ".xpm", "image/x-xpixmap" },
|
||||
{ ".xps", "application/vnd.ms-xpsdocument" },
|
||||
{ ".xsd", "text/xml" },
|
||||
{ ".xsf", "text/xml" },
|
||||
{ ".xsl", "text/xml" },
|
||||
{ ".xslt", "text/xml" },
|
||||
{ ".xsn", "application/octet-stream" },
|
||||
{ ".xtp", "application/octet-stream" },
|
||||
{ ".xwd", "image/x-xwindowdump" },
|
||||
{ ".z", "application/x-compress" },
|
||||
{ ".zip", "application/x-zip-compressed" },
|
||||
};
|
||||
}
|
||||
}
|
||||
144
TightWiki.Library/NamespaceNavigation.cs
Normal file
144
TightWiki.Library/NamespaceNavigation.cs
Normal file
@@ -0,0 +1,144 @@
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace TightWiki.Library
|
||||
{
|
||||
public class NamespaceNavigation
|
||||
{
|
||||
private string _namespace = string.Empty;
|
||||
private string _page = string.Empty;
|
||||
private readonly bool _lowerCase = false;
|
||||
|
||||
public string Namespace
|
||||
{
|
||||
get => _namespace;
|
||||
set => _namespace = CleanAndValidate(value.Replace("::", "_")).Trim();
|
||||
}
|
||||
|
||||
public string Page
|
||||
{
|
||||
get => _page;
|
||||
set => _page = CleanAndValidate(value.Replace("::", "_")).Trim();
|
||||
}
|
||||
|
||||
public string Canonical
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(Namespace))
|
||||
{
|
||||
return Page;
|
||||
}
|
||||
return $"{Namespace}::{Page}";
|
||||
}
|
||||
set
|
||||
{
|
||||
var cleanedAndValidatedValue = CleanAndValidate(value, _lowerCase);
|
||||
|
||||
var parts = cleanedAndValidatedValue.Split("::");
|
||||
if (parts.Length < 2)
|
||||
{
|
||||
Page = parts[0].Trim();
|
||||
}
|
||||
else
|
||||
{
|
||||
Namespace = parts[0].Trim();
|
||||
Page = string.Join("_", parts.Skip(1).Select(o => o.Trim())).Trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of NamespaceNavigation.
|
||||
/// </summary>
|
||||
/// <param name="givenCanonical">Page navigation with optional namespace.</param>
|
||||
public NamespaceNavigation(string givenCanonical)
|
||||
{
|
||||
_lowerCase = true;
|
||||
Canonical = givenCanonical;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of NamespaceNavigation.
|
||||
/// </summary>
|
||||
/// <param name="givenCanonical">Page navigation with optional namespace.</param>
|
||||
/// <param name="lowerCase">If false, the namespace and page name will not be lowercased.</param>
|
||||
public NamespaceNavigation(string givenCanonical, bool lowerCase)
|
||||
{
|
||||
_lowerCase = lowerCase;
|
||||
Canonical = givenCanonical;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Canonical;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Takes a page name with optional namespace and returns the cleaned version that can be used for matching Navigations.
|
||||
/// </summary>
|
||||
/// <param name="givenCanonical">Page navigation with optional namespace.</param>
|
||||
/// <param name="lowerCase">If false, the namespace and page name will not be lowercased.</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public static string CleanAndValidate(string? str, bool lowerCase = true)
|
||||
{
|
||||
if (str == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
//Fix names like "::Page" or "Namespace::".
|
||||
str = str.Trim().Trim([':']).Trim();
|
||||
|
||||
if (str.Contains("::"))
|
||||
{
|
||||
var parts = str.Split("::");
|
||||
if (parts.Length != 2)
|
||||
{
|
||||
throw new Exception("Navigation can not contain more than one namespace.");
|
||||
}
|
||||
return $"{CleanAndValidate(parts[0].Trim())}::{CleanAndValidate(parts[1].Trim(), lowerCase)}";
|
||||
}
|
||||
|
||||
// Decode common HTML entities
|
||||
str = str.Replace(""", "\"")
|
||||
.Replace("&", "&")
|
||||
.Replace("<", "<")
|
||||
.Replace(">", ">")
|
||||
.Replace(" ", " ");
|
||||
|
||||
// Normalize backslashes to forward slashes
|
||||
str = str.Replace('\\', '/');
|
||||
|
||||
var sb = new StringBuilder();
|
||||
foreach (char c in str)
|
||||
{
|
||||
if (char.IsWhiteSpace(c) || c == '.')
|
||||
{
|
||||
sb.Append('_');
|
||||
}
|
||||
else if (char.IsLetterOrDigit(c) || c == '_' || c == '/' || c == '-')
|
||||
{
|
||||
sb.Append(c);
|
||||
}
|
||||
}
|
||||
|
||||
string result = sb.ToString();
|
||||
|
||||
// Remove multiple consecutive underscores or slashes
|
||||
result = Regex.Replace(result, @"[_]{2,}", "_");
|
||||
result = Regex.Replace(result, @"[/]{2,}", "/");
|
||||
|
||||
|
||||
if (lowerCase)
|
||||
{
|
||||
return result.TrimEnd(['/', '\\']).ToLowerInvariant();
|
||||
}
|
||||
else
|
||||
{
|
||||
return result.TrimEnd(['/', '\\']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
58
TightWiki.Library/Navigation.cs
Normal file
58
TightWiki.Library/Navigation.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace TightWiki.Library
|
||||
{
|
||||
public class Navigation
|
||||
{
|
||||
public static string Clean(string? str)
|
||||
{
|
||||
if (str == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
//Fix names like "::Page" or "Namespace::".
|
||||
str = str.Trim().Trim([':']).Trim();
|
||||
|
||||
if (str.Contains("::"))
|
||||
{
|
||||
throw new Exception("Navigation can not contain a namespace.");
|
||||
}
|
||||
|
||||
// Decode common HTML entities
|
||||
str = str.Replace(""", "\"")
|
||||
.Replace("&", "&")
|
||||
.Replace("<", "<")
|
||||
.Replace(">", ">")
|
||||
.Replace(" ", " ");
|
||||
|
||||
// Normalize backslashes to forward slashes
|
||||
str = str.Replace('\\', '/');
|
||||
|
||||
// Replace special sequences
|
||||
str = str.Replace("::", "_").Trim();
|
||||
|
||||
var sb = new StringBuilder();
|
||||
foreach (char c in str)
|
||||
{
|
||||
if (char.IsWhiteSpace(c) || c == '.')
|
||||
{
|
||||
sb.Append('_');
|
||||
}
|
||||
else if (char.IsLetterOrDigit(c) || c == '_' || c == '/' || c == '-')
|
||||
{
|
||||
sb.Append(c);
|
||||
}
|
||||
}
|
||||
|
||||
string result = sb.ToString();
|
||||
|
||||
// Remove multiple consecutive underscores or slashes
|
||||
result = Regex.Replace(result, @"[_]{2,}", "_");
|
||||
result = Regex.Replace(result, @"[/]{2,}", "/");
|
||||
|
||||
return result.ToLower();
|
||||
}
|
||||
}
|
||||
}
|
||||
71
TightWiki.Library/PageSelectorGenerator.cs
Normal file
71
TightWiki.Library/PageSelectorGenerator.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Text;
|
||||
|
||||
namespace TightWiki.Library
|
||||
{
|
||||
public static class PageSelectorGenerator
|
||||
{
|
||||
public static string Generate(QueryString? queryString, int? totalPageCount)
|
||||
=> Generate(string.Empty, "page", QueryStringConverter.ToDictionary(queryString), totalPageCount);
|
||||
|
||||
public static string Generate(string queryToken, IQueryCollection? queryString, int? totalPageCount)
|
||||
=> Generate(string.Empty, queryToken, QueryStringConverter.ToDictionary(queryString), totalPageCount);
|
||||
|
||||
public static string Generate(string url, string queryToken, Dictionary<string, string>? queryString, int? totalPageCount)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
int currentPage = 1;
|
||||
|
||||
var firstPage = QueryStringConverter.Clone(queryString);
|
||||
if (firstPage.TryGetValue(queryToken, out var currentPageString))
|
||||
{
|
||||
currentPage = int.Parse(currentPageString);
|
||||
}
|
||||
|
||||
firstPage.Remove(queryToken);
|
||||
firstPage.Add(queryToken, "1");
|
||||
|
||||
var prevPage = QueryStringConverter.Clone(firstPage);
|
||||
prevPage.Remove(queryToken);
|
||||
prevPage.Add(queryToken, $"{currentPage - 1}");
|
||||
|
||||
var nextPage = QueryStringConverter.Clone(firstPage);
|
||||
nextPage.Remove(queryToken);
|
||||
nextPage.Add(queryToken, $"{currentPage + 1}");
|
||||
|
||||
var lastPage = QueryStringConverter.Clone(firstPage);
|
||||
lastPage.Remove(queryToken);
|
||||
lastPage.Add(queryToken, $"{totalPageCount}");
|
||||
|
||||
if ((totalPageCount ?? 0) > 1 || currentPage > 1)
|
||||
{
|
||||
sb.Append($"<center>");
|
||||
if (currentPage > 1)
|
||||
{
|
||||
sb.Append($"<a href=\"{url}?{QueryStringConverter.FromCollection(firstPage)}\"><< First</a>");
|
||||
sb.Append(" | ");
|
||||
sb.Append($"<a href=\"{url}?{QueryStringConverter.FromCollection(prevPage)}\">< Previous</a>");
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append($"<< First | < Previous");
|
||||
}
|
||||
sb.Append(" | ");
|
||||
|
||||
if (currentPage < totalPageCount)
|
||||
{
|
||||
sb.Append($"<a href=\"{url}?{QueryStringConverter.FromCollection(nextPage)}\">Next ></a>");
|
||||
sb.Append(" | ");
|
||||
sb.Append($"<a href=\"{url}?{QueryStringConverter.FromCollection(lastPage)}\">Last >></a>");
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append("Next > | Last >>");
|
||||
}
|
||||
sb.Append($"</center>");
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
182
TightWiki.Library/QueryStringConverter.cs
Normal file
182
TightWiki.Library/QueryStringConverter.cs
Normal file
@@ -0,0 +1,182 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using TightWiki.Library.Interfaces;
|
||||
|
||||
namespace TightWiki.Library
|
||||
{
|
||||
public static class QueryStringConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// Takes the current page query string and upserts the given order-by field,
|
||||
/// if the string already sorts on the given field then the order is inverted (asc/desc).
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string OrderHelper(ISessionState context, string value)
|
||||
{
|
||||
string orderByKey = "OrderBy";
|
||||
string orderByDirectionKey = "OrderByDirection";
|
||||
string? currentDirection = "asc";
|
||||
var collection = ToDictionary(context.QueryString);
|
||||
|
||||
//Check to see if we are sorting on the value that we are already sorted on, this would mean we need to invert the sort.
|
||||
if (collection.TryGetValue(orderByKey, out var currentValue))
|
||||
{
|
||||
bool invertDirection = string.Equals(currentValue, value, StringComparison.InvariantCultureIgnoreCase);
|
||||
|
||||
if (invertDirection)
|
||||
{
|
||||
if (collection.TryGetValue(orderByDirectionKey, out currentDirection))
|
||||
{
|
||||
if (currentDirection == "asc")
|
||||
{
|
||||
currentDirection = "desc";
|
||||
}
|
||||
else
|
||||
{
|
||||
currentDirection = "asc";
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
currentDirection = "asc";
|
||||
}
|
||||
}
|
||||
|
||||
collection.Remove(orderByKey);
|
||||
collection.Add(orderByKey, value);
|
||||
|
||||
collection.Remove(orderByDirectionKey);
|
||||
collection.Add(orderByDirectionKey, currentDirection ?? "asc");
|
||||
|
||||
return FromCollection(collection);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Takes the current page query string and upserts a query key/value, replacing any conflicting query string entry.
|
||||
/// </summary>
|
||||
/// <param name="queryString"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static string Upsert(IQueryCollection? queryString, string name, string value)
|
||||
{
|
||||
var collection = ToDictionary(queryString);
|
||||
collection.Remove(name);
|
||||
collection.Add(name, value);
|
||||
return FromCollection(collection);
|
||||
}
|
||||
|
||||
public static Dictionary<string, string> ToDictionary(IQueryCollection? queryString)
|
||||
{
|
||||
if (queryString == null)
|
||||
{
|
||||
return new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
var dictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
foreach (var item in queryString)
|
||||
{
|
||||
//Technically, keys can be duplicated in a IQueryCollection but we do not
|
||||
//support this. Use .Single() to throw exception if duplicates are found.
|
||||
dictionary.Add(item.Key, item.Value.Single() ?? string.Empty);
|
||||
}
|
||||
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
public static Dictionary<string, string> ToDictionary(QueryString? queryString)
|
||||
=> ToDictionary(queryString?.ToString());
|
||||
|
||||
public static Dictionary<string, string> ToDictionary(string? queryString)
|
||||
{
|
||||
var dictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
if (string.IsNullOrEmpty(queryString))
|
||||
{
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
// If the query string starts with '?', remove it
|
||||
if (queryString.StartsWith('?'))
|
||||
{
|
||||
queryString = queryString.Substring(1);
|
||||
}
|
||||
|
||||
// Split the query string into key-value pairs
|
||||
var keyValuePairs = queryString.Split('&');
|
||||
|
||||
foreach (var kvp in keyValuePairs)
|
||||
{
|
||||
var keyValue = kvp.Split('=');
|
||||
if (keyValue.Length == 2)
|
||||
{
|
||||
var key = HttpUtility.UrlDecode(keyValue[0]);
|
||||
var value = HttpUtility.UrlDecode(keyValue[1]);
|
||||
dictionary[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
public static string FromCollection(IQueryCollection? collection)
|
||||
{
|
||||
if (collection == null || collection.Count == 0)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
var queryString = new StringBuilder();
|
||||
|
||||
foreach (var kvp in collection)
|
||||
{
|
||||
if (queryString.Length > 0)
|
||||
{
|
||||
queryString.Append('&');
|
||||
}
|
||||
|
||||
queryString.Append($"{Uri.EscapeDataString(kvp.Key)}={Uri.EscapeDataString(kvp.Value.ToString())}");
|
||||
}
|
||||
|
||||
return queryString.ToString();
|
||||
}
|
||||
|
||||
public static string FromCollection(Dictionary<string, string>? collection)
|
||||
{
|
||||
if (collection == null || collection.Count == 0)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
var queryString = new StringBuilder();
|
||||
|
||||
foreach (var kvp in collection)
|
||||
{
|
||||
if (queryString.Length > 0)
|
||||
{
|
||||
queryString.Append('&');
|
||||
}
|
||||
queryString.Append($"{Uri.EscapeDataString(kvp.Key)}={Uri.EscapeDataString(kvp.Value)}");
|
||||
}
|
||||
|
||||
return queryString.ToString();
|
||||
}
|
||||
|
||||
public static Dictionary<string, string> Clone(Dictionary<string, string>? original)
|
||||
{
|
||||
if (original == null)
|
||||
{
|
||||
return new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
var clone = new Dictionary<string, string>(original.Count, original.Comparer);
|
||||
foreach (var kvp in original)
|
||||
{
|
||||
clone.Add(kvp.Key, kvp.Value);
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
}
|
||||
14
TightWiki.Library/Theme.cs
Normal file
14
TightWiki.Library/Theme.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace TightWiki.Library
|
||||
{
|
||||
public class Theme
|
||||
{
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string DelimitedFiles { get; set; } = string.Empty;
|
||||
public string ClassNavBar { get; set; } = string.Empty;
|
||||
public string ClassNavLink { get; set; } = string.Empty;
|
||||
public string ClassDropdown { get; set; } = string.Empty;
|
||||
public string ClassBranding { get; set; } = string.Empty;
|
||||
public string EditorTheme { get; set; } = string.Empty;
|
||||
public List<string> Files { get; set; } = new();
|
||||
}
|
||||
}
|
||||
26
TightWiki.Library/TightWiki.Library.csproj
Normal file
26
TightWiki.Library/TightWiki.Library.csproj
Normal file
@@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>2.20.1</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'">
|
||||
<DebugSymbols>False</DebugSymbols>
|
||||
<DebugType>None</DebugType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Magick.NET-Q8-AnyCPU" Version="14.4.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="9.0.1" />
|
||||
<PackageReference Include="NTDLS.Helpers" Version="1.3.11" />
|
||||
<PackageReference Include="NTDLS.SqliteDapperWrapper" Version="1.1.4" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.6" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
20
TightWiki.Library/TimeZoneItem.cs
Normal file
20
TightWiki.Library/TimeZoneItem.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
namespace TightWiki.Library
|
||||
{
|
||||
public class TimeZoneItem
|
||||
{
|
||||
public string Text { get; set; } = string.Empty;
|
||||
public string Value { get; set; } = string.Empty;
|
||||
|
||||
public static List<TimeZoneItem> GetAll()
|
||||
{
|
||||
var list = new List<TimeZoneItem>();
|
||||
|
||||
foreach (var item in TimeZoneInfo.GetSystemTimeZones())
|
||||
{
|
||||
list.Add(new TimeZoneItem { Value = item.Id, Text = item.DisplayName });
|
||||
}
|
||||
|
||||
return list.OrderBy(o => o.Text).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
108
TightWiki.Library/Utility.cs
Normal file
108
TightWiki.Library/Utility.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.IO.Compression;
|
||||
|
||||
namespace TightWiki.Library
|
||||
{
|
||||
public static class Utility
|
||||
{
|
||||
public static int PadVersionString(string versionString, int padLength = 3)
|
||||
=> int.Parse(string.Join("", versionString.Split('.').Select(x => x.Trim().PadLeft(padLength, '0'))));
|
||||
|
||||
public static string SanitizeAccountName(string fileName, char[]? extraInvalidCharacters = null)
|
||||
{
|
||||
// Get array of invalid characters for file names
|
||||
var invalidChars = Path.GetInvalidFileNameChars().ToList();
|
||||
|
||||
if (extraInvalidCharacters != null)
|
||||
{
|
||||
invalidChars.AddRange(extraInvalidCharacters);
|
||||
}
|
||||
|
||||
foreach (char invalidChar in invalidChars)
|
||||
{
|
||||
fileName = fileName.Replace(invalidChar, '_');
|
||||
}
|
||||
|
||||
return fileName.Replace("__", "_").Replace("__", "_");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Take a height and width and enforces a max on both dimensions while maintaining the ratio.
|
||||
/// </summary>
|
||||
/// <param name="originalWidth"></param>
|
||||
/// <param name="originalHeight"></param>
|
||||
/// <param name="maxSize"></param>
|
||||
/// <returns></returns>
|
||||
public static (int Width, int Height) ScaleToMaxOf(int originalWidth, int originalHeight, int maxSize)
|
||||
{
|
||||
// Calculate aspect ratio
|
||||
float aspectRatio = (float)originalWidth / originalHeight;
|
||||
|
||||
// Determine new dimensions based on the larger dimension
|
||||
int newWidth, newHeight;
|
||||
if (originalWidth > originalHeight)
|
||||
{
|
||||
// Scale down the width to the maxSize and calculate the height
|
||||
newWidth = maxSize;
|
||||
newHeight = (int)(maxSize / aspectRatio);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Scale down the height to the maxSize and calculate the width
|
||||
newHeight = maxSize;
|
||||
newWidth = (int)(maxSize * aspectRatio);
|
||||
}
|
||||
|
||||
return (newWidth, newHeight);
|
||||
}
|
||||
|
||||
public static List<string> SplitToTokens(string? tokenString)
|
||||
{
|
||||
var tokens = (tokenString ?? string.Empty).Trim().ToLower()
|
||||
.Split([' ', ',', '\t'], StringSplitOptions.RemoveEmptyEntries).Distinct().ToList();
|
||||
return tokens;
|
||||
}
|
||||
|
||||
public static string GetMimeType(string fileName)
|
||||
{
|
||||
MimeTypes.TryGetContentType(fileName, out var contentType);
|
||||
return contentType ?? "application/octet-stream";
|
||||
}
|
||||
|
||||
public static byte[] ConvertHttpFileToBytes(IFormFile image)
|
||||
{
|
||||
using var stream = image.OpenReadStream();
|
||||
using BinaryReader reader = new BinaryReader(stream);
|
||||
return reader.ReadBytes((int)image.Length);
|
||||
}
|
||||
|
||||
public static byte[] Compress(byte[]? data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
return Array.Empty<byte>();
|
||||
}
|
||||
|
||||
using var compressedStream = new MemoryStream();
|
||||
using (var compressor = new GZipStream(compressedStream, CompressionMode.Compress))
|
||||
{
|
||||
compressor.Write(data, 0, data.Length);
|
||||
}
|
||||
return compressedStream.ToArray();
|
||||
}
|
||||
|
||||
public static byte[] Decompress(byte[] data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
return Array.Empty<byte>();
|
||||
}
|
||||
|
||||
using var compressedStream = new MemoryStream(data);
|
||||
using var decompressor = new GZipStream(compressedStream, CompressionMode.Decompress);
|
||||
using var decompressedStream = new MemoryStream();
|
||||
decompressor.CopyTo(decompressedStream);
|
||||
return decompressedStream.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user