Assorted enhancements

This commit is contained in:
Shaun Walker
2021-11-24 08:08:39 -05:00
parent df00f53e54
commit 53ff491efd
20 changed files with 322 additions and 238 deletions

View File

@ -508,8 +508,8 @@ namespace Oqtane.Controllers
return System.IO.File.Exists(errorPath) ? PhysicalFile(errorPath, MimeUtilities.GetMimeType(errorPath)) : null;
}
[HttpGet("image/{id}/{width}/{height}/{mode?}")]
public IActionResult GetImage(int id, int width, int height, string mode)
[HttpGet("image/{id}/{width}/{height}/{mode?}/{rotate?}")]
public IActionResult GetImage(int id, int width, int height, string mode, string rotate)
{
var file = _files.GetFile(id);
if (file != null && file.Folder.SiteId == _alias.SiteId && _userPermissions.IsAuthorized(User, PermissionNames.View, file.Folder.Permissions))
@ -520,6 +520,7 @@ namespace Oqtane.Controllers
if (System.IO.File.Exists(filepath))
{
mode = (string.IsNullOrEmpty(mode)) ? "crop" : mode;
rotate = (string.IsNullOrEmpty(rotate)) ? "0" : rotate;
string imagepath = filepath.Replace(Path.GetExtension(filepath), "." + width.ToString() + "x" + height.ToString() + "." + mode.ToLower() + ".png");
if (!System.IO.File.Exists(imagepath))
@ -528,7 +529,7 @@ namespace Oqtane.Controllers
!string.IsNullOrEmpty(file.Folder.ImageSizes) && file.Folder.ImageSizes.ToLower().Split(",").Contains(width.ToString() + "x" + height.ToString()))
&& Enum.TryParse(mode, true, out ResizeMode resizemode))
{
imagepath = CreateImage(filepath, width, height, resizemode.ToString(), imagepath);
imagepath = CreateImage(filepath, width, height, resizemode.ToString(), rotate, imagepath);
}
else
{
@ -568,7 +569,7 @@ namespace Oqtane.Controllers
return System.IO.File.Exists(errorPath) ? PhysicalFile(errorPath, MimeUtilities.GetMimeType(errorPath)) : null;
}
private string CreateImage(string filepath, int width, int height, string mode, string imagepath)
private string CreateImage(string filepath, int width, int height, string mode, string rotate, string imagepath)
{
try
{
@ -585,6 +586,11 @@ namespace Oqtane.Controllers
})
.BackgroundColor(new Rgba32(255, 255, 255, 0)));
if (rotate != "0" && int.TryParse(rotate, out int angle))
{
image.Mutate(x => x.Rotate(angle));
}
image.Save(imagepath, new PngEncoder());
}
stream.Close();

View File

@ -0,0 +1,44 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Oqtane.Databases.Interfaces;
using Oqtane.Migrations.EntityBuilders;
using Oqtane.Repository;
namespace Oqtane.Migrations.Tenant
{
[DbContext(typeof(TenantDBContext))]
[Migration("Tenant.03.00.01.01")]
public class ChangeFileNameColumnsSize : MultiDatabaseMigration
{
public ChangeFileNameColumnsSize(IDatabase database) : base(database)
{
}
protected override void Up(MigrationBuilder migrationBuilder)
{
if (ActiveDatabase.Name != "Sqlite")
{
var fileEntityBuilder = new FileEntityBuilder(migrationBuilder, ActiveDatabase);
// Drop the index is needed because the Name is already associated with IX_File
fileEntityBuilder.DropForeignKey("FK_File_Folder");
fileEntityBuilder.DropIndex("IX_File");
fileEntityBuilder.AlterStringColumn("Name", 256);
fileEntityBuilder.AddIndex("IX_File", new[] { "FolderId", "Name" }, true);
fileEntityBuilder.AddForeignKey("FK_File_Folder");
}
}
protected override void Down(MigrationBuilder migrationBuilder)
{
if (ActiveDatabase.Name != "Sqlite")
{
var fileEntityBuilder = new FileEntityBuilder(migrationBuilder, ActiveDatabase);
fileEntityBuilder.DropIndex("IX_File");
fileEntityBuilder.AlterStringColumn("Name", 50);
fileEntityBuilder.AddIndex("IX_File", new[] { "FolderId", "Name" }, true);
}
}
}
}

View File

@ -7,7 +7,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width">
<title>Oqtane</title>
<title>@Model.Title</title>
<base href="~/" />
<link id="app-favicon" rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
<!-- stub the PWA manifest but defer the assignment of href -->

View File

@ -40,6 +40,7 @@ namespace Oqtane.Pages
public RenderMode RenderMode = RenderMode.Server;
public string HeadResources = "";
public string BodyResources = "";
public string Title = "";
public void OnGet()
{
@ -80,6 +81,7 @@ namespace Oqtane.Pages
{
RenderMode = (RenderMode)Enum.Parse(typeof(RenderMode), site.RenderMode, true);
}
Title = site.Name;
}
// if culture not specified

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 318 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB