|
|
|
@ -5,6 +5,7 @@ |
|
|
|
// All rights reserved. Licensed under the MIT license.
|
|
|
|
// ==========================================================================
|
|
|
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Microsoft.AspNetCore.Http; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
@ -13,6 +14,7 @@ using Squidex.Areas.Api.Controllers.Assets.Models; |
|
|
|
using Squidex.Domain.Apps.Entities.Assets; |
|
|
|
using Squidex.Domain.Apps.Entities.Assets.Commands; |
|
|
|
using Squidex.Infrastructure; |
|
|
|
using Squidex.Infrastructure.Collections; |
|
|
|
using Squidex.Infrastructure.Commands; |
|
|
|
using Squidex.Infrastructure.Tasks; |
|
|
|
using Squidex.Shared; |
|
|
|
@ -39,6 +41,7 @@ namespace Squidex.Areas.Api.Controllers.Assets |
|
|
|
/// </summary>
|
|
|
|
/// <param name="app">The name of the app.</param>
|
|
|
|
/// <param name="parentId">The optional parent folder id.</param>
|
|
|
|
/// <param name="scope">The scope of the query.</param>
|
|
|
|
/// <returns>
|
|
|
|
/// 200 => Asset folders returned.
|
|
|
|
/// 404 => App not found.
|
|
|
|
@ -51,11 +54,11 @@ namespace Squidex.Areas.Api.Controllers.Assets |
|
|
|
[ProducesResponseType(typeof(AssetFoldersDto), StatusCodes.Status200OK)] |
|
|
|
[ApiPermissionOrAnonymous(Permissions.AppAssetsRead)] |
|
|
|
[ApiCosts(1)] |
|
|
|
public async Task<IActionResult> GetAssetFolders(string app, [FromQuery] DomainId parentId) |
|
|
|
public async Task<IActionResult> GetAssetFolders(string app, [FromQuery] DomainId parentId, [FromQuery] AssetFolderScope scope = AssetFolderScope.PathAndItems) |
|
|
|
{ |
|
|
|
var (folders, path) = await AsyncHelper.WhenAll( |
|
|
|
assetQuery.QueryAssetFoldersAsync(Context, parentId, HttpContext.RequestAborted), |
|
|
|
assetQuery.FindAssetFolderAsync(Context.App.Id, parentId, HttpContext.RequestAborted)); |
|
|
|
GetAssetFoldersAsync(parentId, scope), |
|
|
|
GetAssetPathAsync(parentId, scope)); |
|
|
|
|
|
|
|
var response = Deferred.Response(() => |
|
|
|
{ |
|
|
|
@ -170,5 +173,25 @@ namespace Squidex.Areas.Api.Controllers.Assets |
|
|
|
|
|
|
|
return AssetFolderDto.FromAssetFolder(context.Result<IAssetFolderEntity>(), Resources); |
|
|
|
} |
|
|
|
|
|
|
|
private Task<IReadOnlyList<IAssetFolderEntity>> GetAssetPathAsync(DomainId parentId, AssetFolderScope scope) |
|
|
|
{ |
|
|
|
if (scope == AssetFolderScope.Items) |
|
|
|
{ |
|
|
|
return Task.FromResult<IReadOnlyList<IAssetFolderEntity>>(ImmutableList.Empty<IAssetFolderEntity>()); |
|
|
|
} |
|
|
|
|
|
|
|
return assetQuery.FindAssetFolderAsync(Context.App.Id, parentId, HttpContext.RequestAborted); |
|
|
|
} |
|
|
|
|
|
|
|
private Task<IResultList<IAssetFolderEntity>> GetAssetFoldersAsync(DomainId parentId, AssetFolderScope scope) |
|
|
|
{ |
|
|
|
if (scope == AssetFolderScope.Path) |
|
|
|
{ |
|
|
|
return Task.FromResult(ResultList.CreateFrom<IAssetFolderEntity>(0)); |
|
|
|
} |
|
|
|
|
|
|
|
return assetQuery.QueryAssetFoldersAsync(Context, parentId, HttpContext.RequestAborted); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|