mirror of https://github.com/Squidex/squidex.git
14 changed files with 338 additions and 18 deletions
@ -0,0 +1,28 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using Squidex.Infrastructure.Commands; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Entities.Assets |
||||
|
{ |
||||
|
public sealed class AssetCreatedResult : EntitySavedResult |
||||
|
{ |
||||
|
public Guid Id { get; } |
||||
|
|
||||
|
public HashSet<string> Tags { get; } |
||||
|
|
||||
|
public AssetCreatedResult(Guid id, HashSet<string> tags, long version) |
||||
|
: base(version) |
||||
|
{ |
||||
|
Id = id; |
||||
|
|
||||
|
Tags = tags; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Collections.Generic; |
||||
|
using Squidex.Domain.Apps.Entities.Assets.Commands; |
||||
|
using Squidex.Domain.Apps.Entities.Tags; |
||||
|
using Squidex.Infrastructure; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Entities.Assets |
||||
|
{ |
||||
|
public sealed class FileTypeTagGenerator : ITagGenerator<CreateAsset> |
||||
|
{ |
||||
|
public void GenerateTags(CreateAsset source, HashSet<string> tags) |
||||
|
{ |
||||
|
var extension = source.File?.FileName?.FileType(); |
||||
|
|
||||
|
if (!string.IsNullOrWhiteSpace(extension)) |
||||
|
{ |
||||
|
tags.Add($"type/{extension.ToLowerInvariant()}"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,39 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Collections.Generic; |
||||
|
using Squidex.Domain.Apps.Entities.Assets.Commands; |
||||
|
using Squidex.Domain.Apps.Entities.Tags; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Entities.Assets |
||||
|
{ |
||||
|
public sealed class ImageTagGenerator : ITagGenerator<CreateAsset> |
||||
|
{ |
||||
|
public void GenerateTags(CreateAsset source, HashSet<string> tags) |
||||
|
{ |
||||
|
if (source.ImageInfo != null) |
||||
|
{ |
||||
|
tags.Add("image"); |
||||
|
|
||||
|
var wh = source.ImageInfo.PixelWidth + source.ImageInfo.PixelHeight; |
||||
|
|
||||
|
if (wh > 2000) |
||||
|
{ |
||||
|
tags.Add("image/large"); |
||||
|
} |
||||
|
else if (wh > 1000) |
||||
|
{ |
||||
|
tags.Add("image/medium"); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
tags.Add("image/small"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Entities.Tags |
||||
|
{ |
||||
|
public interface ITagGenerator<T> |
||||
|
{ |
||||
|
void GenerateTags(T source, HashSet<string> tags); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,56 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Collections.Generic; |
||||
|
using Squidex.Domain.Apps.Entities.Assets.Commands; |
||||
|
using Squidex.Infrastructure.Assets; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Entities.Assets |
||||
|
{ |
||||
|
public class FileTypeTagGeneratorTests |
||||
|
{ |
||||
|
private readonly HashSet<string> tags = new HashSet<string>(); |
||||
|
private readonly FileTypeTagGenerator sut = new FileTypeTagGenerator(); |
||||
|
|
||||
|
[Fact] |
||||
|
public void Should_not_add_tag_if_no_file_info() |
||||
|
{ |
||||
|
var command = new CreateAsset(); |
||||
|
|
||||
|
sut.GenerateTags(command, tags); |
||||
|
|
||||
|
Assert.Empty(tags); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Should_add_file_type() |
||||
|
{ |
||||
|
var command = new CreateAsset |
||||
|
{ |
||||
|
File = new AssetFile("File.DOCX", "Mime", 100, () => null) |
||||
|
}; |
||||
|
|
||||
|
sut.GenerateTags(command, tags); |
||||
|
|
||||
|
Assert.Contains("type/docx", tags); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Should_add_blob_if_without_extension() |
||||
|
{ |
||||
|
var command = new CreateAsset |
||||
|
{ |
||||
|
File = new AssetFile("File", "Mime", 100, () => null) |
||||
|
}; |
||||
|
|
||||
|
sut.GenerateTags(command, tags); |
||||
|
|
||||
|
Assert.Contains("type/blob", tags); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,72 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Collections.Generic; |
||||
|
using Squidex.Domain.Apps.Entities.Assets.Commands; |
||||
|
using Squidex.Infrastructure.Assets; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Entities.Assets |
||||
|
{ |
||||
|
public class ImageTagGeneratorTests |
||||
|
{ |
||||
|
private readonly HashSet<string> tags = new HashSet<string>(); |
||||
|
private readonly ImageTagGenerator sut = new ImageTagGenerator(); |
||||
|
|
||||
|
[Fact] |
||||
|
public void Should_not_add_tag_if_no_image() |
||||
|
{ |
||||
|
var command = new CreateAsset(); |
||||
|
|
||||
|
sut.GenerateTags(command, tags); |
||||
|
|
||||
|
Assert.Empty(tags); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Should_add_image_tag_if_small() |
||||
|
{ |
||||
|
var command = new CreateAsset |
||||
|
{ |
||||
|
ImageInfo = new ImageInfo(100, 100) |
||||
|
}; |
||||
|
|
||||
|
sut.GenerateTags(command, tags); |
||||
|
|
||||
|
Assert.Contains("image", tags); |
||||
|
Assert.Contains("image/small", tags); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Should_add_image_tag_if_medium() |
||||
|
{ |
||||
|
var command = new CreateAsset |
||||
|
{ |
||||
|
ImageInfo = new ImageInfo(800, 600) |
||||
|
}; |
||||
|
|
||||
|
sut.GenerateTags(command, tags); |
||||
|
|
||||
|
Assert.Contains("image", tags); |
||||
|
Assert.Contains("image/medium", tags); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Should_add_image_tag_if_large() |
||||
|
{ |
||||
|
var command = new CreateAsset |
||||
|
{ |
||||
|
ImageInfo = new ImageInfo(1200, 1400) |
||||
|
}; |
||||
|
|
||||
|
sut.GenerateTags(command, tags); |
||||
|
|
||||
|
Assert.Contains("image", tags); |
||||
|
Assert.Contains("image/large", tags); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue