mirror of https://github.com/Squidex/squidex.git
13 changed files with 228 additions and 21 deletions
@ -0,0 +1,23 @@ |
|||||
|
// ==========================================================================
|
||||
|
// IGraphQLUrlGenerator.cs
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex Group
|
||||
|
// All rights reserved.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using Squidex.Domain.Apps.Read.Apps; |
||||
|
using Squidex.Domain.Apps.Read.Assets; |
||||
|
using Squidex.Domain.Apps.Read.Schemas; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Read.Contents.GraphQL |
||||
|
{ |
||||
|
public interface IGraphQLUrlGenerator |
||||
|
{ |
||||
|
string GenerateAssetUrl(IAppEntity appEntity, IAssetEntity assetEntity); |
||||
|
|
||||
|
string GenerateAssetThumbnailUrl(IAppEntity appEntity, IAssetEntity assetEntity); |
||||
|
|
||||
|
string GenerateContentUrl(IAppEntity appEntity, ISchemaEntity schemaEntity, IContentEntity contentEntity); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,50 @@ |
|||||
|
// ==========================================================================
|
||||
|
// GraphQLUrlGenerator.cs
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex Group
|
||||
|
// All rights reserved.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using Microsoft.Extensions.Options; |
||||
|
using Squidex.Config; |
||||
|
using Squidex.Domain.Apps.Read.Apps; |
||||
|
using Squidex.Domain.Apps.Read.Assets; |
||||
|
using Squidex.Domain.Apps.Read.Contents; |
||||
|
using Squidex.Domain.Apps.Read.Contents.GraphQL; |
||||
|
using Squidex.Domain.Apps.Read.Schemas; |
||||
|
|
||||
|
// ReSharper disable ConvertIfStatementToReturnStatement
|
||||
|
|
||||
|
namespace Squidex.Pipeline |
||||
|
{ |
||||
|
public sealed class GraphQLUrlGenerator : IGraphQLUrlGenerator |
||||
|
{ |
||||
|
private readonly MyUrlsOptions urlsOptions; |
||||
|
|
||||
|
public GraphQLUrlGenerator(IOptions<MyUrlsOptions> urlsOptions) |
||||
|
{ |
||||
|
this.urlsOptions = urlsOptions.Value; |
||||
|
} |
||||
|
|
||||
|
public string GenerateAssetThumbnailUrl(IAppEntity appEntity, IAssetEntity assetEntity) |
||||
|
{ |
||||
|
if (!assetEntity.IsImage) |
||||
|
{ |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
return urlsOptions.BuildUrl($"api/assets/{assetEntity.Id}?version={assetEntity.Version}&width=100&mode=Max"); |
||||
|
} |
||||
|
|
||||
|
public string GenerateAssetUrl(IAppEntity appEntity, IAssetEntity assetEntity) |
||||
|
{ |
||||
|
return urlsOptions.BuildUrl($"api/assets/{assetEntity.Id}?version={assetEntity.Version}"); |
||||
|
} |
||||
|
|
||||
|
public string GenerateContentUrl(IAppEntity appEntity, ISchemaEntity schemaEntity, IContentEntity contentEntity) |
||||
|
{ |
||||
|
return urlsOptions.BuildUrl($"api/content/{appEntity.Name}/{schemaEntity.Name}/{contentEntity.Id}"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,33 @@ |
|||||
|
// ==========================================================================
|
||||
|
// FakeUrlGenerator.cs
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex Group
|
||||
|
// All rights reserved.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using Squidex.Domain.Apps.Read.Apps; |
||||
|
using Squidex.Domain.Apps.Read.Assets; |
||||
|
using Squidex.Domain.Apps.Read.Contents.GraphQL; |
||||
|
using Squidex.Domain.Apps.Read.Schemas; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Read.Contents.TestData |
||||
|
{ |
||||
|
public sealed class FakeUrlGenerator : IGraphQLUrlGenerator |
||||
|
{ |
||||
|
public string GenerateAssetUrl(IAppEntity appEntity, IAssetEntity assetEntity) |
||||
|
{ |
||||
|
return $"assets/{assetEntity.Id}"; |
||||
|
} |
||||
|
|
||||
|
public string GenerateAssetThumbnailUrl(IAppEntity appEntity, IAssetEntity assetEntity) |
||||
|
{ |
||||
|
return $"assets/{assetEntity.Id}?width=100"; |
||||
|
} |
||||
|
|
||||
|
public string GenerateContentUrl(IAppEntity appEntity, ISchemaEntity schemaEntity, IContentEntity contentEntity) |
||||
|
{ |
||||
|
return $"contents/{schemaEntity.Name}/{contentEntity.Id}"; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue