link providers
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using zero.Core.Api;
|
||||
using zero.Core.Entities;
|
||||
|
||||
namespace zero.Web.Controllers
|
||||
{
|
||||
public class LinkPickerController : BackofficeController
|
||||
{
|
||||
IPageTreeApi Api;
|
||||
IPagesApi PagesApi;
|
||||
|
||||
public LinkPickerController(IPageTreeApi api, IPagesApi pagesApi)
|
||||
{
|
||||
Api = api;
|
||||
PagesApi = pagesApi;
|
||||
}
|
||||
|
||||
|
||||
public async Task<IList<TreeItem>> GetChildren([FromQuery] string areaAlias, [FromQuery] string parent = null, [FromQuery] string active = null)
|
||||
{
|
||||
return await Api.GetChildren(parent, active);
|
||||
}
|
||||
|
||||
//public async Task<IList<PreviewModel>> GetPreviews([FromQuery] List<string> ids)
|
||||
//{
|
||||
// return Previews(await PagesApi.GetByIds(ids.ToArray()), PreviewTransform);
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Raven.Client.Documents.Session;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using zero.Core.Api;
|
||||
using zero.Core.Database;
|
||||
using zero.Core.Entities;
|
||||
using zero.Core.Routing;
|
||||
using zero.Core.Utils;
|
||||
|
||||
namespace zero.Web.Controllers
|
||||
{
|
||||
public class LinksController : BackofficeController
|
||||
{
|
||||
IZeroStore Store;
|
||||
ILinks Links;
|
||||
|
||||
public LinksController(IZeroStore store, ILinks links)
|
||||
{
|
||||
Store = store;
|
||||
Links = links;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IList<PreviewModel>> GetPreviews([FromBody] List<Link> links)
|
||||
{
|
||||
IList<PreviewModel> previews = new List<PreviewModel>();
|
||||
using IAsyncDocumentSession session = Store.OpenAsyncSession();
|
||||
|
||||
foreach (Link link in links)
|
||||
{
|
||||
ILinkProvider provider = Links.GetProvider(link);
|
||||
PreviewModel model = null;
|
||||
|
||||
if (provider != null)
|
||||
{
|
||||
model = await provider.Preview(session, link);
|
||||
}
|
||||
|
||||
previews.Add(model ?? new PreviewModel()
|
||||
{
|
||||
HasError = true,
|
||||
Icon = "fth-alert-circle color-red",
|
||||
Id = IdGenerator.Create(),
|
||||
Name = "@errors.preview.notfound",
|
||||
Text = "@errors.preview.notfound_text"
|
||||
});
|
||||
}
|
||||
|
||||
return previews;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user