diff --git a/src/modules/mix.portal/Domain/Services/MixApplicationService.cs b/src/modules/mix.portal/Domain/Services/MixApplicationService.cs index f32991b74..94db10711 100644 --- a/src/modules/mix.portal/Domain/Services/MixApplicationService.cs +++ b/src/modules/mix.portal/Domain/Services/MixApplicationService.cs @@ -10,12 +10,13 @@ using Mix.SignalR.Hubs; using System.IO.Packaging; using System.Text.RegularExpressions; +using static NuGet.Packaging.PackagingConstants; namespace Mix.Portal.Domain.Services { public sealed class MixApplicationService : TenantServiceBase, IMixApplicationService { - static string[] excludeFileNames = { "jquery" }; + static string[] excludeFileNames = { "jquery", "index" }; private readonly IQueueService _queueService; private readonly IThemeService _themeService; private readonly MixIdentityService _mixIdentityService; @@ -67,16 +68,12 @@ public async Task Install(MixApplicationViewModel app, { try { - var files = MixFileHelper.GetTopFiles(deployUrl, true); - var folders = string.Join('|', MixFileHelper.GetTopDirectories(deployUrl)); + var folders = MixFileHelper.GetTopDirectories(deployUrl); + var topFolderPattern = string.Join('|', folders); templateId = await ReplaceIndex(templateId, name, deployUrl, baseHref); - foreach (var file in files) - { - if (file.Extension == MixFileExtensions.Js || file.Extension == MixFileExtensions.Css) - { - await ReplaceContent(file, folders, deployUrl); - } - } + + await ModifyFilesAndFolders(deployUrl, deployUrl, topFolderPattern); + return templateId; } catch (Exception ex) @@ -85,6 +82,24 @@ public async Task Install(MixApplicationViewModel app, } } + private async Task ModifyFilesAndFolders(string deployUrl, string topFolder, string topFolderPattern) + { + var files = MixFileHelper.GetTopFiles(topFolder, true); + var folders = MixFileHelper.GetTopDirectories(topFolder); + + foreach (var file in files) + { + if (file.Extension == MixFileExtensions.Js || file.Extension == MixFileExtensions.Css || file.Extension == MixFileExtensions.Html) + { + await ReplaceContent(file, topFolderPattern, deployUrl); + } + } + foreach (var folder in folders) + { + await ModifyFilesAndFolders(deployUrl, $"{topFolder}/{folder}", topFolderPattern); + } + } + private async Task ReplaceIndex(int? templateId, string name, string deployUrl, string baseHref) { try @@ -99,10 +114,10 @@ public async Task Install(MixApplicationViewModel app, } - Regex regex = new("((\\\"|\\'|\\(|\\`){1}(\\.)?(\\/)?(([0-9a-zA-Z\\/\\._-])+).(js|css|svg|png|PNG|gif|GIF|jp[e]?g|JP[E]?G))"); + Regex regex = new("((\\\"|\\'|\\(|\\`){1}(\\.)?(\\/)?(([0-9a-zA-Z\\/\\._-])+)\\.{1}(\\w+)(\"|\\'|\\(|\\`){1})"); Regex baseHrefRegex = new("(base href=\"(.+?)\")"); indexFile.Content = indexFile.Content.Replace("[basePath]/", string.Empty); - indexFile.Content = regex.Replace(indexFile.Content, $"$2/{deployUrl}/$5.$7"); + indexFile.Content = regex.Replace(indexFile.Content, $"$2/{deployUrl}/$5.$7$2"); indexFile.Content = baseHrefRegex.Replace(indexFile.Content, $"base href=\"{baseHref}\"") .Replace("[baseRoute]", deployUrl) @@ -148,21 +163,21 @@ private Task ReplaceContent(FileModel file, string folders, string deployUrl) Regex rg = null; if (string.IsNullOrEmpty(folders)) { - rg = new($"((\\\"|\\'|\\(|\\`){1}(\\.)?(\\/)?(([0-9a-zA-Z\\/\\._-])+).(js|css|svg|png|PNG|gif|GIF|jp[e]?g|JP[E]?G))"); + rg = new("((\\\"|\\'|\\(|\\`){1}(\\.)?(\\/)?(([0-9a-zA-Z\\/\\._-])+)\\.{1}(\\w+)(\"|\\'|\\(|\\`){1})"); if (rg.IsMatch(file.Content)) { - file.Content = rg.Replace(file.Content, $"$2/{deployUrl}/$5.$7"); + file.Content = rg.Replace(file.Content, $"$2/{deployUrl}/$5.$7$2"); } } else { - rg = new($"((\\\"|\\'|\\(|\\`)(\\.)?(\\/)?({folders})(([0-9a-zA-Z\\/\\._-])+).(js|css|svg|png|PNG|gif|GIF|jp[e]?g|JP[E]?G))"); + rg = new($"((\\\"|\\'|\\(|\\`)(\\.)?(\\/)?({folders})(([0-9a-zA-Z\\/\\._-])+)(\\\"|\\'|\\(|\\`))"); if (rg.IsMatch(file.Content)) { - file.Content = rg.Replace(file.Content, $"$2/{deployUrl}/$5$6.$8"); + file.Content = rg.Replace(file.Content, $"$2/{deployUrl}/$5$6$2"); } } - + file.Content = file.Content.Replace("[basePath]", $"/{deployUrl}"); MixFileHelper.SaveFile(file); diff --git a/src/platform/mix.service/Services/MixPermissionService.cs b/src/platform/mix.service/Services/MixPermissionService.cs index bb27eac8c..8c6e3edd9 100644 --- a/src/platform/mix.service/Services/MixPermissionService.cs +++ b/src/platform/mix.service/Services/MixPermissionService.cs @@ -2,6 +2,7 @@ using Microsoft.EntityFrameworkCore; using Mix.Constant.Constants; using Mix.Database.Entities.Account; +using Mix.Database.Entities.Cms; using Mix.Database.Entities.MixDb; using Mix.Database.Services; using Mix.Heart.Exceptions; @@ -32,28 +33,26 @@ public async Task Reload() { if (!GlobalConfigService.Instance.IsInit) { - if (_databaseService.DatabaseProvider == Heart.Enums.MixDatabaseProvider.SQLITE) - { - return; - } UnitOfWorkInfo uow = new(new MixDbDbContext(_databaseService)); try { RoleEndpoints = new Dictionary(); accountDbContext = new MixCmsAccountContext(_databaseService); + using var cmsDbContext = new MixCmsContext(_databaseService); var roles = await accountDbContext.MixRoles.ToListAsync(); foreach (var role in roles) { - var permissionIds = uow.DbContext.MixDatabaseAssociation + var permissionIds = cmsDbContext.MixDatabaseAssociation .Where(m => m.GuidParentId == role.Id) .Select(m => m.ChildId); - var endpointIds = uow.DbContext.MixDatabaseAssociation + var endpointIds = cmsDbContext.MixDatabaseAssociation .Where(m => m.ParentDatabaseName == MixDatabaseNames.SYSTEM_PERMISSION && m.ChildDatabaseName == MixDatabaseNames.SYSTEM_PERMISSION_ENDPOINT && permissionIds.Contains(m.ParentId)) - .Select(m => m.ChildId); + .Select(m => m.ChildId) + .ToList(); // TODO: PermissionEndpoint cannot initial at first time var endpoints = await uow.DbContext.PermissionEndpoint.Where(