+
Skip to content

Update Mix Application #703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/applications/Mixcore/Controllers/AppController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ protected override void ValidateRequest()
}

#region Routes
[Route("{baseRoute}/{param1?}/{param2?}/{param3?}/{param4?}/{param5?}/{param6?}")]
public async Task<IActionResult> Index(string baseRoute)
[Route("{appName}/{param1?}/{param2?}/{param3?}/{param4?}/{param5?}/{param6?}")]
public async Task<IActionResult> Index(string appName)
{
if (IsValid)
{
return await App(baseRoute);
return await App($"/app/{appName}");
}
else
{
Expand All @@ -69,11 +69,11 @@ public async Task<IActionResult> Index(string baseRoute)
#endregion Routes

#region Helper
protected async Task<IActionResult> App(string baseRoute)
protected async Task<IActionResult> App(string baseHref)
{
// Home App
var pageRepo = ApplicationViewModel.GetRepository(Uow, _cacheService);
var page = await pageRepo.GetSingleAsync(m => m.BaseRoute == baseRoute && m.MixTenantId == CurrentTenant.Id);
var page = await pageRepo.GetSingleAsync(m => m.BaseHref == baseHref && m.MixTenantId == CurrentTenant.Id);
if (page == null)
return NotFound();

Expand Down
55 changes: 35 additions & 20 deletions src/applications/Mixcore/Controllers/PostContentApiController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using Mix.Heart.Exceptions;
using Mix.Heart.Extensions;
using Mix.Heart.Helpers;
using Mix.Lib.Models.Common;
Expand All @@ -9,6 +11,7 @@

namespace Mixcore.Controllers
{
[EnableCors(MixCorsPolicies.PublicApis)]
[Route("api/v2/rest/mixcore/post-content")]
public sealed class PostContentApiController : MixQueryApiControllerBase<PostContentViewModel, MixCmsContext, MixPostContent, int>
{
Expand All @@ -29,8 +32,8 @@ public PostContentApiController(
IMixMetadataService metadataService,
MixRepoDbRepository repoDbRepository,
IPortalHubClientService portalHub,
IMixTenantService mixTenantService)
: base(httpContextAccessor, configuration,
IMixTenantService mixTenantService)
: base(httpContextAccessor, configuration,
cacheService, translator, mixIdentityService, uow, queueService, portalHub, mixTenantService)
{
_postService = postService;
Expand All @@ -42,36 +45,48 @@ public PostContentApiController(
[HttpPost("filter")]
public async Task<ActionResult<PagingResponseModel<PostContentViewModel>>> Filter([FromBody] FilterContentRequestDto req)
{
var searchRequest = BuildSearchRequest(req);
searchRequest.Predicate = searchRequest.Predicate.AndAlsoIf(
!string.IsNullOrEmpty(req.MixDatabaseName), m => m.MixDatabaseName == req.MixDatabaseName);
if (!string.IsNullOrEmpty(req.MixDatabaseName) && req.Queries.Count > 0)
try
{
_mixRepoDbRepository.InitTableName(req.MixDatabaseName);
var listData = await _mixRepoDbRepository.GetListByAsync(req.Queries, "id, parentId");
if (listData != null)
var searchRequest = BuildSearchRequest(req);
searchRequest.Predicate = searchRequest.Predicate.AndAlsoIf(
!string.IsNullOrEmpty(req.MixDatabaseName), m => m.MixDatabaseName == req.MixDatabaseName);
if (!string.IsNullOrEmpty(req.MixDatabaseName) && req.Queries.Count > 0)
{
List<int> allowIds = new();
foreach (var data in listData)
_mixRepoDbRepository.InitTableName(req.MixDatabaseName);
var listData = await _mixRepoDbRepository.GetListByAsync(req.Queries, "Id, ParentId");
if (listData != null)
{
allowIds.Add(ReflectionHelper.ParseObject(data).Value<int>("parentId"));
List<int> allowIds = new();
foreach (var data in listData)
{
// used JObject.FromObject to keep original reponse fieldName
allowIds.Add(JObject.FromObject(data).Value<int>("ParentId"));
}
searchRequest.Predicate = searchRequest.Predicate.AndAlso(m => allowIds.Contains(m.Id));
}
searchRequest.Predicate = searchRequest.Predicate.AndAlso(m => allowIds.Contains(m.Id));
}
var result = await Repository.GetPagingAsync(searchRequest.Predicate, searchRequest.PagingData);
foreach (var item in result.Items)
{
await item.LoadAdditionalDataAsync(_repoDbRepository, _metadataService, CacheService);
}
return Ok(ParseSearchResult(req, result));
}
var result = await Repository.GetPagingAsync(searchRequest.Predicate, searchRequest.PagingData);
foreach (var item in result.Items)
catch (MixException)
{
await item.LoadAdditionalDataAsync(_repoDbRepository, _metadataService, CacheService);
throw;
}
catch (Exception ex)
{
throw new MixException(MixErrorStatus.Badrequest, ex);
}
return Ok(ParseSearchResult(req, result));
}

protected override async Task<PagingResponseModel<PostContentViewModel>> SearchHandler(SearchRequestDto req, CancellationToken cancellationToken = default)
{
var searchPostQuery = new SearchPostQueryModel(Request, req, CurrentTenant.Id);
var result= await _postService.SearchPosts(searchPostQuery, cancellationToken);

var result = await _postService.SearchPosts(searchPostQuery, cancellationToken);
foreach (var item in result.Items)
{
await item.LoadAdditionalDataAsync(_mixRepoDbRepository, _metadataService, CacheService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public ApplicationViewModel(UnitOfWorkInfo unitOfWorkInfo) : base(unitOfWorkInfo
#endregion

#region Properties
public string Title { get; set; }
public string BaseHref { get; set; }
public string BaseRoute { get; set; }
public string DeployUrl { get; set; }
public JObject AppSettings { get; set; }
public string Domain { get; set; }
public string BaseApiUrl { get; set; }
public int? TemplateId { get; set; }
Expand Down
22 changes: 14 additions & 8 deletions src/applications/Mixcore/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,14 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseMixCors();

app.UseMixTenant();

app.UseMiddleware<AuditlogMiddleware>();

app.UseRouting();

// must go between app.UseRouting() and app.UseEndpoints.
app.UseMixAuth();

app.UseMixApps(Assembly.GetExecutingAssembly(), Configuration, env.ContentRootPath, env.IsDevelopment());

app.UseResponseCompression();
app.UseMixResponseCaching();
// Typically, UseStaticFiles is called before UseCors. Apps that use JavaScript to retrieve static files cross site must call UseCors before UseStaticFiles.
app.UseMixStaticFiles(env.ContentRootPath);
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions
Expand All @@ -68,6 +61,19 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
Path.Combine(env.ContentRootPath, MixFolders.TemplatesFolder))
});

// UseCors must be placed after UseRouting and before UseAuthorization. This is to ensure that CORS headers are included in the response for both authorized and unauthorized calls.
app.UseMixCors();

// must go between app.UseRouting() and app.UseEndpoints.
app.UseMixAuth();

app.UseMixApps(Assembly.GetExecutingAssembly(), Configuration, env.ContentRootPath, env.IsDevelopment());

app.UseResponseCompression();
app.UseMixResponseCaching();



if (GlobalConfigService.Instance.AppSettings.IsHttps)
{
app.UseHttpsRedirection();
Expand Down
2 changes: 1 addition & 1 deletion src/applications/Mixcore/Views/App/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ else
</section>
}
@section Seo{
<title>@Model.Title</title>
<title>@Model.DisplayName</title>
<meta property="og:type" content="post" />
<!--points to the regular HTML version of the AMP HTML document or to itself if no such HTML version exists-->
}
Expand Down
2 changes: 1 addition & 1 deletion src/applications/Mixcore/Views/Home/App.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ else
</section>
}
@section Seo{
<title>@Model.Title</title>
<title>@Model.DisplayName</title>
<meta property="og:type" content="post" />
<!--points to the regular HTML version of the AMP HTML document or to itself if no such HTML version exists-->
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"isCache": true,
"connectionString": "Data Source=MixContent\\mix-cms.db",
"connectionString": "Data Source=mixcontent\\mix-cms.sqlite",
"databaseProvider": "SQLITE",
"cacheMode": "JSON",
"cacheFolder": "MixContent/cache"
Expand Down
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载