|
|
|
@ -8,6 +8,7 @@ |
|
|
|
using System; |
|
|
|
using System.IO; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.Net.Http.Headers; |
|
|
|
using Squidex.Domain.Apps.Entities.Assets; |
|
|
|
@ -47,7 +48,8 @@ namespace Squidex.Areas.Api.Controllers.Assets |
|
|
|
/// <summary>
|
|
|
|
/// Get the asset content.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id">The id of the asset.</param>
|
|
|
|
/// <param name="app">The name of the app.</param>
|
|
|
|
/// <param name="idOrSlug">The id or slug of the asset.</param>
|
|
|
|
/// <param name="more">Optional suffix that can be used to seo-optimize the link to the image Has not effect.</param>
|
|
|
|
/// <param name="version">The optional version of the asset.</param>
|
|
|
|
/// <param name="width">The target width of the asset, if it is an image.</param>
|
|
|
|
@ -59,17 +61,27 @@ namespace Squidex.Areas.Api.Controllers.Assets |
|
|
|
/// 404 => Asset or app not found.
|
|
|
|
/// </returns>
|
|
|
|
[HttpGet] |
|
|
|
[Route("assets/{id}/{*more}")] |
|
|
|
[Route("assets/{app}/{idOrSlug}/{*more}")] |
|
|
|
[ProducesResponseType(typeof(FileResult), 200)] |
|
|
|
[ApiCosts(0.5)] |
|
|
|
public async Task<IActionResult> GetAssetContent(Guid id, string more, |
|
|
|
[AllowAnonymous] |
|
|
|
public async Task<IActionResult> GetAssetContentBySlug(string app, string idOrSlug, string more, |
|
|
|
[FromQuery] long version = EtagVersion.Any, |
|
|
|
[FromQuery] int? width = null, |
|
|
|
[FromQuery] int? height = null, |
|
|
|
[FromQuery] int? quality = null, |
|
|
|
[FromQuery] string mode = null) |
|
|
|
{ |
|
|
|
var entity = await assetRepository.FindAssetAsync(id); |
|
|
|
IAssetEntity entity; |
|
|
|
|
|
|
|
if (Guid.TryParse(idOrSlug, out var guid)) |
|
|
|
{ |
|
|
|
entity = await assetRepository.FindAssetAsync(guid); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
entity = await assetRepository.FindAssetBySlugAsync(App.Id, idOrSlug); |
|
|
|
} |
|
|
|
|
|
|
|
return DeliverAsset(entity, version, width, height, quality, mode); |
|
|
|
} |
|
|
|
@ -77,8 +89,7 @@ namespace Squidex.Areas.Api.Controllers.Assets |
|
|
|
/// <summary>
|
|
|
|
/// Get the asset content.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="app">The name of the app.</param>
|
|
|
|
/// <param name="idOrSlug">The id or slug of the asset.</param>
|
|
|
|
/// <param name="id">The id of the asset.</param>
|
|
|
|
/// <param name="more">Optional suffix that can be used to seo-optimize the link to the image Has not effect.</param>
|
|
|
|
/// <param name="version">The optional version of the asset.</param>
|
|
|
|
/// <param name="width">The target width of the asset, if it is an image.</param>
|
|
|
|
@ -90,26 +101,17 @@ namespace Squidex.Areas.Api.Controllers.Assets |
|
|
|
/// 404 => Asset or app not found.
|
|
|
|
/// </returns>
|
|
|
|
[HttpGet] |
|
|
|
[Route("assets/{app}/{idOrSlug}/{*more}")] |
|
|
|
[Route("assets/{id}/{*more}")] |
|
|
|
[ProducesResponseType(typeof(FileResult), 200)] |
|
|
|
[ApiCosts(0.5)] |
|
|
|
public async Task<IActionResult> GetAssetContent(string app, string idOrSlug, string more, |
|
|
|
public async Task<IActionResult> GetAssetContent(Guid id, string more, |
|
|
|
[FromQuery] long version = EtagVersion.Any, |
|
|
|
[FromQuery] int? width = null, |
|
|
|
[FromQuery] int? height = null, |
|
|
|
[FromQuery] int? quality = null, |
|
|
|
[FromQuery] string mode = null) |
|
|
|
{ |
|
|
|
IAssetEntity entity; |
|
|
|
|
|
|
|
if (Guid.TryParse(idOrSlug, out var guid)) |
|
|
|
{ |
|
|
|
entity = await assetRepository.FindAssetAsync(guid); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
entity = await assetRepository.FindAssetBySlugAsync(App.Id, idOrSlug); |
|
|
|
} |
|
|
|
var entity = await assetRepository.FindAssetAsync(id); |
|
|
|
|
|
|
|
return DeliverAsset(entity, version, width, height, quality, mode); |
|
|
|
} |
|
|
|
|