2021-02-10 14:53:56 +01:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using zero.Core.Database;
|
|
|
|
|
using zero.Core.Entities;
|
|
|
|
|
using zero.Core.Routing;
|
|
|
|
|
using zero.Core.Utils;
|
|
|
|
|
|
|
|
|
|
namespace zero.Web.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class LinksController : BackofficeController
|
|
|
|
|
{
|
2021-10-28 12:11:07 +02:00
|
|
|
IZeroStore Store;
|
2021-02-10 14:53:56 +01:00
|
|
|
ILinks Links;
|
|
|
|
|
|
2021-10-28 12:11:07 +02:00
|
|
|
public LinksController(IZeroStore store, ILinks links)
|
2021-02-10 14:53:56 +01:00
|
|
|
{
|
2021-10-28 12:11:07 +02:00
|
|
|
Store = store;
|
2021-02-10 14:53:56 +01:00
|
|
|
Links = links;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<IList<PreviewModel>> GetPreviews([FromBody] List<Link> links)
|
|
|
|
|
{
|
2021-10-28 12:11:07 +02:00
|
|
|
IZeroDocumentSession session = Store.Session();
|
2021-02-10 14:53:56 +01:00
|
|
|
IList<PreviewModel> previews = new List<PreviewModel>();
|
|
|
|
|
|
|
|
|
|
foreach (Link link in links)
|
|
|
|
|
{
|
|
|
|
|
ILinkProvider provider = Links.GetProvider(link);
|
|
|
|
|
PreviewModel model = null;
|
|
|
|
|
|
|
|
|
|
if (provider != null)
|
|
|
|
|
{
|
2021-10-28 12:11:07 +02:00
|
|
|
model = await provider.Preview(session, link);
|
2021-02-10 14:53:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|