diff --git a/src/modules/mix.portal/Domain/Services/MixApplicationService.cs b/src/modules/mix.portal/Domain/Services/MixApplicationService.cs index 13d4ec7df..f32991b74 100644 --- a/src/modules/mix.portal/Domain/Services/MixApplicationService.cs +++ b/src/modules/mix.portal/Domain/Services/MixApplicationService.cs @@ -15,6 +15,7 @@ namespace Mix.Portal.Domain.Services { public sealed class MixApplicationService : TenantServiceBase, IMixApplicationService { + static string[] excludeFileNames = { "jquery" }; private readonly IQueueService _queueService; private readonly IThemeService _themeService; private readonly MixIdentityService _mixIdentityService; @@ -66,9 +67,9 @@ public async Task Install(MixApplicationViewModel app, { try { - templateId = await ReplaceIndex(templateId, name, deployUrl, baseHref); var files = MixFileHelper.GetTopFiles(deployUrl, true); var folders = string.Join('|', MixFileHelper.GetTopDirectories(deployUrl)); + templateId = await ReplaceIndex(templateId, name, deployUrl, baseHref); foreach (var file in files) { if (file.Extension == MixFileExtensions.Js || file.Extension == MixFileExtensions.Css) @@ -97,11 +98,11 @@ public async Task Install(MixApplicationViewModel app, throw new MixException(MixErrorStatus.Badrequest, "Invalid Application Package"); } - - Regex regex = new("((?<=src=\")|(?<=href=\"))(?!(http[^\\s]+))(.+?)(\\.+?)"); + + Regex regex = new("((\\\"|\\'|\\(|\\`){1}(\\.)?(\\/)?(([0-9a-zA-Z\\/\\._-])+).(js|css|svg|png|PNG|gif|GIF|jp[e]?g|JP[E]?G))"); Regex baseHrefRegex = new("(base href=\"(.+?)\")"); indexFile.Content = indexFile.Content.Replace("[basePath]/", string.Empty); - indexFile.Content = regex.Replace(indexFile.Content, $"/{deployUrl}/$3$4"); + indexFile.Content = regex.Replace(indexFile.Content, $"$2/{deployUrl}/$5.$7"); indexFile.Content = baseHrefRegex.Replace(indexFile.Content, $"base href=\"{baseHref}\"") .Replace("[baseRoute]", deployUrl) @@ -137,29 +138,39 @@ public async Task Install(MixApplicationViewModel app, } } - private Task ReplaceContent(FileModel file, string folders, string appFolder) + private Task ReplaceContent(FileModel file, string folders, string deployUrl) { - if (!string.IsNullOrEmpty(file.Content)) + if (!string.IsNullOrEmpty(file.Content) && !excludeFileNames.Contains(file.Filename)) { - _ = AlertAsync(_hubContext.Clients.Group("Theme"), "Status", 200, $"Modifying {file.Filename}{file.Extension}"); - Regex rg = new($"((\\\"|\\')(({folders})))"); - Regex rgSplash = new($"((\\.\\/)({folders}))"); - Regex rgSplash1 = new($"((\\(\\/|\\`\\/)(({folders})))"); - if (rgSplash.IsMatch(file.Content)) + try { - file.Content = rgSplash.Replace(file.Content, $"/{appFolder}/$3"); - } - if (rgSplash1.IsMatch(file.Content)) - { - file.Content = rgSplash1.Replace(file.Content, $"$2{appFolder}/$3"); + _ = AlertAsync(_hubContext.Clients.Group("Theme"), "Status", 200, $"Modifying {file.Filename}{file.Extension}"); + 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))"); + if (rg.IsMatch(file.Content)) + { + file.Content = rg.Replace(file.Content, $"$2/{deployUrl}/$5.$7"); + } + } + else + { + rg = new($"((\\\"|\\'|\\(|\\`)(\\.)?(\\/)?({folders})(([0-9a-zA-Z\\/\\._-])+).(js|css|svg|png|PNG|gif|GIF|jp[e]?g|JP[E]?G))"); + if (rg.IsMatch(file.Content)) + { + file.Content = rg.Replace(file.Content, $"$2/{deployUrl}/$5$6.$8"); + } + } + + file.Content = file.Content.Replace("[basePath]", $"/{deployUrl}"); + + MixFileHelper.SaveFile(file); } - if (rg.IsMatch(file.Content)) + catch (Exception ex) { - file.Content = rg.Replace(file.Content, $"$2/{appFolder}/$3"); + throw new MixException(MixErrorStatus.ServerError, ex); } - file.Content = file.Content.Replace("[basePath]", $"/{appFolder}"); - - MixFileHelper.SaveFile(file); } return Task.CompletedTask; } diff --git a/src/platform/mix.service/Services/MixPermissionService.cs b/src/platform/mix.service/Services/MixPermissionService.cs index 25564c921..bb27eac8c 100644 --- a/src/platform/mix.service/Services/MixPermissionService.cs +++ b/src/platform/mix.service/Services/MixPermissionService.cs @@ -2,7 +2,6 @@ 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; @@ -33,8 +32,11 @@ public async Task Reload() { if (!GlobalConfigService.Instance.IsInit) { - UnitOfWorkInfo cmsUow = new(new MixCmsContext(_databaseService)); - UnitOfWorkInfo mixdbUow = new(new MixDbDbContext(_databaseService)); + if (_databaseService.DatabaseProvider == Heart.Enums.MixDatabaseProvider.SQLITE) + { + return; + } + UnitOfWorkInfo uow = new(new MixDbDbContext(_databaseService)); try { RoleEndpoints = new Dictionary(); @@ -44,19 +46,17 @@ public async Task Reload() foreach (var role in roles) { - var permissionIds = cmsUow.DbContext.MixDatabaseAssociation + var permissionIds = uow.DbContext.MixDatabaseAssociation .Where(m => m.GuidParentId == role.Id) - .Select(m => m.ChildId) - .ToList(); - var endpointIds = cmsUow.DbContext.MixDatabaseAssociation + .Select(m => m.ChildId); + var endpointIds = uow.DbContext.MixDatabaseAssociation .Where(m => m.ParentDatabaseName == MixDatabaseNames.SYSTEM_PERMISSION && m.ChildDatabaseName == MixDatabaseNames.SYSTEM_PERMISSION_ENDPOINT && permissionIds.Contains(m.ParentId)) - .Select(m => m.ChildId) - .ToList(); + .Select(m => m.ChildId); // TODO: PermissionEndpoint cannot initial at first time - var endpoints = await mixdbUow.DbContext.PermissionEndpoint.Where( + var endpoints = await uow.DbContext.PermissionEndpoint.Where( m => endpointIds.Contains(m.Id) && !string.IsNullOrEmpty(m.Path) ) @@ -87,8 +87,7 @@ public async Task Reload() } finally { - cmsUow.Dispose(); - mixdbUow.Dispose(); + uow.Dispose(); accountDbContext.Dispose(); } }