From a59fa91a269f3214ba566e58d9ad6f391b1cc214 Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Tue, 30 Jan 2024 17:44:43 +0100 Subject: [PATCH] Fix SVG (#1070) * Fix SVG * Update editor. --- .../Squidex.Extensions.csproj | 4 +- backend/src/Migrations/Migrations.csproj | 2 +- .../src/Migrations/OldEvents/AssetCreated.cs | 4 +- .../src/Migrations/OldEvents/AssetUpdated.cs | 4 +- .../Assets/AssetMetadata.cs | 81 +---------- .../Assets/KnownMetadataKeys.cs | 29 ++++ .../Squidex.Domain.Apps.Core.Model.csproj | 2 +- ...Squidex.Domain.Apps.Core.Operations.csproj | 4 +- .../Validators/AssetsValidator.cs | 30 ++-- ...quidex.Domain.Apps.Entities.MongoDb.csproj | 2 +- .../Assets/AssetChangedTriggerHandler.cs | 9 +- .../Assets/FileTagAssetMetadataSource.cs | 38 +++-- .../Assets/ImageAssetMetadataSource.cs | 20 +-- .../Assets/SvgAssetMetadataSource.cs | 66 ++++++--- .../GraphQL/Types/Assets/AssetGraphType.cs | 4 +- .../Assets/EnrichedAssetEventGraphType.cs | 4 +- .../Squidex.Domain.Apps.Entities.csproj | 4 +- .../Squidex.Domain.Apps.Events.csproj | 2 +- .../Squidex.Domain.Users.MongoDb.csproj | 2 +- .../Squidex.Domain.Users.csproj | 2 +- ...quidex.Infrastructure.GetEventStore.csproj | 2 +- .../Squidex.Infrastructure.MongoDb.csproj | 2 +- .../Squidex.Infrastructure.csproj | 14 +- .../src/Squidex.Shared/Squidex.Shared.csproj | 2 +- backend/src/Squidex.Web/Squidex.Web.csproj | 2 +- .../Assets/Models/AssetContentQueryDto.cs | 4 +- .../Api/Controllers/Assets/Models/AssetDto.cs | 4 +- backend/src/Squidex/Squidex.csproj | 26 ++-- .../Squidex/wwwroot/editor/squidex-editor.js | 2 +- .../Model/Assets/AssetMetadataTests.cs | 36 ++--- .../Model/Assets/AssetTests.cs | 4 +- .../Scripting/JintScriptEngineTests.cs | 18 +++ .../Squidex.Domain.Apps.Core.Tests.csproj | 2 +- .../TestHelpers/TestAssets.cs | 18 +-- .../Assets/AssetsJintExtensionTests.cs | 4 +- .../DomainObject/AssetDomainObjectTests.cs | 2 +- .../Assets/FileTagAssetMetadataSourceTests.cs | 36 ++--- .../Assets/ImageAssetMetadataSourceTests.cs | 28 ++-- .../Assets/SvgAssetMetadataSourceTests.cs | 74 +++++++--- .../Assets/TestFiles/SvgInvalid.svg | 5 + .../Assets/TestFiles/SvgValid.svg | 6 + .../Contents/GraphQL/TestAsset.cs | 17 +-- .../Properties/Resources.Designer.cs | 90 ------------ .../Properties/Resources.resx | 135 ------------------ .../Squidex.Domain.Apps.Entities.Tests.csproj | 21 +-- .../Squidex.Domain.Users.Tests.csproj | 2 +- .../Squidex.Infrastructure.Tests.csproj | 2 +- .../Squidex.Web.Tests.csproj | 2 +- .../TestSuite.ApiTests/AnonymousTests.cs | 1 - .../TestSuite.ApiTests/AppClientsTests.cs | 1 - .../AppContributorsTests.cs | 1 - .../TestSuite.ApiTests/AppCreationTests.cs | 1 - .../TestSuite.ApiTests/AppLanguagesTests.cs | 1 - .../TestSuite.ApiTests/AppRolesTests.cs | 1 - .../TestSuite/TestSuite.ApiTests/AppTests.cs | 1 - .../TestSuite.ApiTests/AppWorkflowsTests.cs | 1 - .../TestSuite.ApiTests/AssetFoldersTests.cs | 1 - .../TestSuite.ApiTests/AssetFormatTests.cs | 1 - .../TestSuite.ApiTests/AssetTests.cs | 1 - .../TestSuite.ApiTests/ContentUpdateTests.cs | 1 - .../TestSuite/TestSuite.ApiTests/RuleTests.cs | 1 - .../TestSuite.ApiTests/SchemaTests.cs | 1 - .../TeamContributorTests.cs | 1 - .../TestSuite/TestSuite.ApiTests/TeamTests.cs | 1 - .../TestSuite.ApiTests.csproj | 14 +- .../TestSuite.LoadTests.csproj | 4 +- .../TestSuite.Shared/TestSuite.Shared.csproj | 12 +- 67 files changed, 355 insertions(+), 564 deletions(-) create mode 100644 backend/src/Squidex.Domain.Apps.Core.Model/Assets/KnownMetadataKeys.cs create mode 100644 backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/TestFiles/SvgInvalid.svg create mode 100644 backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/TestFiles/SvgValid.svg delete mode 100644 backend/tests/Squidex.Domain.Apps.Entities.Tests/Properties/Resources.Designer.cs delete mode 100644 backend/tests/Squidex.Domain.Apps.Entities.Tests/Properties/Resources.resx diff --git a/backend/extensions/Squidex.Extensions/Squidex.Extensions.csproj b/backend/extensions/Squidex.Extensions/Squidex.Extensions.csproj index 2bc06f676..319d0b3e5 100644 --- a/backend/extensions/Squidex.Extensions/Squidex.Extensions.csproj +++ b/backend/extensions/Squidex.Extensions/Squidex.Extensions.csproj @@ -11,7 +11,7 @@ - + @@ -19,7 +19,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/backend/src/Migrations/Migrations.csproj b/backend/src/Migrations/Migrations.csproj index f6691ffc3..dd5435bf3 100644 --- a/backend/src/Migrations/Migrations.csproj +++ b/backend/src/Migrations/Migrations.csproj @@ -6,7 +6,7 @@ enable - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/backend/src/Migrations/OldEvents/AssetCreated.cs b/backend/src/Migrations/OldEvents/AssetCreated.cs index 716246d0e..46c76c78b 100644 --- a/backend/src/Migrations/OldEvents/AssetCreated.cs +++ b/backend/src/Migrations/OldEvents/AssetCreated.cs @@ -50,8 +50,8 @@ public sealed class AssetCreated : AssetEvent, IMigrated { result.Type = AssetType.Image; - result.Metadata.SetPixelWidth(PixelWidth.Value); - result.Metadata.SetPixelHeight(PixelHeight.Value); + result.Metadata[KnownMetadataKeys.PixelWidth] = PixelWidth.Value; + result.Metadata[KnownMetadataKeys.PixelHeight] = PixelHeight.Value; } return result; diff --git a/backend/src/Migrations/OldEvents/AssetUpdated.cs b/backend/src/Migrations/OldEvents/AssetUpdated.cs index 376463a92..ab094f5f5 100644 --- a/backend/src/Migrations/OldEvents/AssetUpdated.cs +++ b/backend/src/Migrations/OldEvents/AssetUpdated.cs @@ -41,8 +41,8 @@ public sealed class AssetUpdated : AssetEvent, IMigrated { result.Type = AssetType.Image; - result.Metadata.SetPixelWidth(PixelWidth.Value); - result.Metadata.SetPixelHeight(PixelHeight.Value); + result.Metadata[KnownMetadataKeys.PixelWidth] = PixelWidth.Value; + result.Metadata[KnownMetadataKeys.PixelHeight] = PixelHeight.Value; } return result; diff --git a/backend/src/Squidex.Domain.Apps.Core.Model/Assets/AssetMetadata.cs b/backend/src/Squidex.Domain.Apps.Core.Model/Assets/AssetMetadata.cs index 4d9b29cd7..7147ba951 100644 --- a/backend/src/Squidex.Domain.Apps.Core.Model/Assets/AssetMetadata.cs +++ b/backend/src/Squidex.Domain.Apps.Core.Model/Assets/AssetMetadata.cs @@ -14,86 +14,7 @@ public sealed class AssetMetadata : Dictionary { private static readonly char[] PathSeparators = ['.', '[', ']']; - public const string FocusX = "focusX"; - public const string FocusY = "focusY"; - public const string PixelWidth = "pixelWidth"; - public const string PixelHeight = "pixelHeight"; - public const string VideoWidth = "videoWidth"; - public const string VideoHeight = "videoHeight"; - - public AssetMetadata SetFocusX(float value) - { - this[FocusX] = (double)value; - - return this; - } - - public AssetMetadata SetFocusY(float value) - { - this[FocusY] = (double)value; - - return this; - } - - public AssetMetadata SetPixelWidth(int value) - { - this[PixelWidth] = value; - - return this; - } - - public AssetMetadata SetPixelHeight(int value) - { - this[PixelHeight] = value; - - return this; - } - - public AssetMetadata SetVideoWidth(int value) - { - this[VideoWidth] = value; - - return this; - } - - public AssetMetadata SetVideoHeight(int value) - { - this[VideoHeight] = value; - - return this; - } - - public float? GetFocusX() - { - return GetSingle(FocusX); - } - - public float? GetFocusY() - { - return GetSingle(FocusY); - } - - public int? GetPixelWidth() - { - return GetIn32(PixelWidth); - } - - public int? GetPixelHeight() - { - return GetIn32(PixelHeight); - } - - public int? GetVideoWidth() - { - return GetIn32(VideoWidth); - } - - public int? GetVideoHeight() - { - return GetIn32(VideoHeight); - } - - public int? GetIn32(string name) + public int? GetInt32(string name) { if (TryGetValue(name, out var value) && value.Value is double n) { diff --git a/backend/src/Squidex.Domain.Apps.Core.Model/Assets/KnownMetadataKeys.cs b/backend/src/Squidex.Domain.Apps.Core.Model/Assets/KnownMetadataKeys.cs new file mode 100644 index 000000000..03a731650 --- /dev/null +++ b/backend/src/Squidex.Domain.Apps.Core.Model/Assets/KnownMetadataKeys.cs @@ -0,0 +1,29 @@ +// ========================================================================== +// Squidex Headless CMS +// ========================================================================== +// Copyright (c) Squidex UG (haftungsbeschraenkt) +// All rights reserved. Licensed under the MIT license. +// ========================================================================== + +namespace Squidex.Domain.Apps.Core.Assets; + +public static class KnownMetadataKeys +{ + public const string AudioBitrate = "audioBitrate"; + public const string AudioChannels = "audioChannels"; + public const string AudioSampleRate = "audioSampleRate"; + public const string BitsPerSample = "bitsPerSample"; + public const string Created = "created"; + public const string Description = "description"; + public const string Duration = "duration"; + public const string FocusX = "focusX"; + public const string FocusY = "focusY"; + public const string ImageQuality = "imageQuality"; + public const string Latitude = "latitude"; + public const string Longitude = "longitude"; + public const string PixelHeight = "pixelHeight"; + public const string PixelWidth = "pixelWidth"; + public const string VideoHeight = "videoHeight"; + public const string VideoWidth = "videoWidth"; + public const string ViewBox = "viewBox"; +} diff --git a/backend/src/Squidex.Domain.Apps.Core.Model/Squidex.Domain.Apps.Core.Model.csproj b/backend/src/Squidex.Domain.Apps.Core.Model/Squidex.Domain.Apps.Core.Model.csproj index 08cc9807b..560e691de 100644 --- a/backend/src/Squidex.Domain.Apps.Core.Model/Squidex.Domain.Apps.Core.Model.csproj +++ b/backend/src/Squidex.Domain.Apps.Core.Model/Squidex.Domain.Apps.Core.Model.csproj @@ -12,7 +12,7 @@ True - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/backend/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj b/backend/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj index 18b5c7a8b..712e8cd48 100644 --- a/backend/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj +++ b/backend/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj @@ -21,14 +21,14 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/backend/src/Squidex.Domain.Apps.Core.Operations/ValidateContent/Validators/AssetsValidator.cs b/backend/src/Squidex.Domain.Apps.Core.Operations/ValidateContent/Validators/AssetsValidator.cs index d7fde413d..5d4405768 100644 --- a/backend/src/Squidex.Domain.Apps.Core.Operations/ValidateContent/Validators/AssetsValidator.cs +++ b/backend/src/Squidex.Domain.Apps.Core.Operations/ValidateContent/Validators/AssetsValidator.cs @@ -63,9 +63,9 @@ public sealed class AssetsValidator : IValidator foreach (var assetId in assetIds) { var assetPath = context.Path.Enqueue($"[{index}]"); - var assetItem = assets.FirstOrDefault(x => x.Id == assetId); + var assetFound = assets.FirstOrDefault(x => x.Id == assetId); - if (assetItem == null) + if (assetFound == null) { if (context.Action == ValidationAction.Upsert) { @@ -75,29 +75,25 @@ public sealed class AssetsValidator : IValidator continue; } - foundIds.Add(assetItem.Id); + foundIds.Add(assetFound.Id); - ValidateCommon(assetItem, assetPath, context); - ValidateType(assetItem, assetPath, context); + ValidateCommon(assetFound, assetPath, context); + ValidateType(assetFound, assetPath, context); - if (assetItem.Type == AssetType.Image) + if (assetFound.Type == AssetType.Image) { - var w = assetItem.Metadata.GetPixelWidth(); - var h = assetItem.Metadata.GetPixelHeight(); - - if (w != null && h != null) + if (assetFound.Metadata.TryGetNumber(KnownMetadataKeys.PixelWidth, out var w) && + assetFound.Metadata.TryGetNumber(KnownMetadataKeys.PixelHeight, out var h)) { - ValidateDimensions(w.Value, h.Value, assetPath, context); + ValidateDimensions((int)w, (int)h, assetPath, context); } } - else if (assetItem.Type == AssetType.Video) + else if (assetFound.Type == AssetType.Video) { - var w = assetItem.Metadata.GetVideoWidth(); - var h = assetItem.Metadata.GetVideoHeight(); - - if (w != null && h != null) + if (assetFound.Metadata.TryGetNumber(KnownMetadataKeys.VideoWidth, out var w) && + assetFound.Metadata.TryGetNumber(KnownMetadataKeys.VideoHeight, out var h)) { - ValidateDimensions(w.Value, h.Value, assetPath, context); + ValidateDimensions((int)w, (int)h, assetPath, context); } } diff --git a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Squidex.Domain.Apps.Entities.MongoDb.csproj b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Squidex.Domain.Apps.Entities.MongoDb.csproj index 62163e0d6..6afe1e9d2 100644 --- a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Squidex.Domain.Apps.Entities.MongoDb.csproj +++ b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Squidex.Domain.Apps.Entities.MongoDb.csproj @@ -19,7 +19,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/backend/src/Squidex.Domain.Apps.Entities/Assets/AssetChangedTriggerHandler.cs b/backend/src/Squidex.Domain.Apps.Entities/Assets/AssetChangedTriggerHandler.cs index 1fd191862..b0c81be07 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Assets/AssetChangedTriggerHandler.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Assets/AssetChangedTriggerHandler.cs @@ -6,6 +6,7 @@ // ========================================================================== using System.Runtime.CompilerServices; +using Squidex.Domain.Apps.Core.Assets; using Squidex.Domain.Apps.Core.HandleRules; using Squidex.Domain.Apps.Core.Rules; using Squidex.Domain.Apps.Core.Rules.EnrichedEvents; @@ -58,8 +59,8 @@ public sealed class AssetChangedTriggerHandler : IRuleTriggerHandler, ISubscript SimpleMapper.Map(asset, result); result.Actor = asset.LastModifiedBy; - result.PixelHeight = asset.Metadata?.GetPixelHeight(); - result.PixelWidth = asset.Metadata?.GetPixelWidth(); + result.PixelHeight = asset.Metadata?.GetInt32(KnownMetadataKeys.PixelHeight); + result.PixelWidth = asset.Metadata?.GetInt32(KnownMetadataKeys.PixelWidth); result.Name = "AssetQueried"; yield return result; @@ -95,8 +96,8 @@ public sealed class AssetChangedTriggerHandler : IRuleTriggerHandler, ISubscript { SimpleMapper.Map(asset, result); - result.PixelHeight = asset.Metadata?.GetPixelHeight(); - result.PixelWidth = asset.Metadata?.GetPixelWidth(); + result.PixelHeight = asset.Metadata?.GetInt32(KnownMetadataKeys.PixelHeight); + result.PixelWidth = asset.Metadata?.GetInt32(KnownMetadataKeys.PixelWidth); result.AssetType = asset.Type; } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Assets/FileTagAssetMetadataSource.cs b/backend/src/Squidex.Domain.Apps.Entities/Assets/FileTagAssetMetadataSource.cs index f33225744..dccbbaeef 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Assets/FileTagAssetMetadataSource.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Assets/FileTagAssetMetadataSource.cs @@ -79,8 +79,8 @@ public sealed class FileTagAssetMetadataSource : IAssetMetadataSource if (pw > 0 && ph > 0) { - command.Metadata.SetPixelWidth(pw); - command.Metadata.SetPixelHeight(ph); + command.Metadata[KnownMetadataKeys.PixelWidth] = pw; + command.Metadata[KnownMetadataKeys.PixelHeight] = ph; } void TryAddString(string name, string? value) @@ -117,24 +117,24 @@ public sealed class FileTagAssetMetadataSource : IAssetMetadataSource if (file.Tag is ImageTag imageTag) { - TryAddDouble("latitude", imageTag.Latitude); - TryAddDouble("longitude", imageTag.Longitude); + TryAddDouble(KnownMetadataKeys.Latitude, imageTag.Latitude); + TryAddDouble(KnownMetadataKeys.Longitude, imageTag.Longitude); - TryAddString("created", imageTag.DateTime?.ToIso8601()); + TryAddString(KnownMetadataKeys.Created, imageTag.DateTime?.ToIso8601()); } - TryAddTimeSpan("duration", file.Properties.Duration); + TryAddTimeSpan(KnownMetadataKeys.Duration, file.Properties.Duration); - TryAddInt("bitsPerSample", file.Properties.BitsPerSample); - TryAddInt("audioBitrate", file.Properties.AudioBitrate); - TryAddInt("audioChannels", file.Properties.AudioChannels); - TryAddInt("audioSampleRate", file.Properties.AudioSampleRate); - TryAddInt("imageQuality", file.Properties.PhotoQuality); + TryAddInt(KnownMetadataKeys.BitsPerSample, file.Properties.BitsPerSample); + TryAddInt(KnownMetadataKeys.AudioBitrate, file.Properties.AudioBitrate); + TryAddInt(KnownMetadataKeys.AudioChannels, file.Properties.AudioChannels); + TryAddInt(KnownMetadataKeys.AudioSampleRate, file.Properties.AudioSampleRate); + TryAddInt(KnownMetadataKeys.ImageQuality, file.Properties.PhotoQuality); - TryAddInt(AssetMetadata.VideoWidth, file.Properties.VideoWidth); - TryAddInt(AssetMetadata.VideoHeight, file.Properties.VideoHeight); + TryAddInt(KnownMetadataKeys.VideoWidth, file.Properties.VideoWidth); + TryAddInt(KnownMetadataKeys.VideoHeight, file.Properties.VideoHeight); - TryAddString("description", file.Properties.Description); + TryAddString(KnownMetadataKeys.Description, file.Properties.Description); } return Task.CompletedTask; @@ -149,22 +149,20 @@ public sealed class FileTagAssetMetadataSource : IAssetMetadataSource { if (asset.Type == AssetType.Video) { - var w = asset.Metadata.GetVideoWidth(); - var h = asset.Metadata.GetVideoHeight(); - - if (w != null && h != null) + if (asset.Metadata.TryGetNumber(KnownMetadataKeys.VideoWidth, out var w) && + asset.Metadata.TryGetNumber(KnownMetadataKeys.VideoHeight, out var h)) { yield return $"{w}x{h}pt"; } - if (asset.Metadata.TryGetString("duration", out var duration)) + if (asset.Metadata.TryGetString(KnownMetadataKeys.Duration, out var duration)) { yield return duration; } } else if (asset.Type == AssetType.Audio) { - if (asset.Metadata.TryGetString("duration", out var duration)) + if (asset.Metadata.TryGetString(KnownMetadataKeys.Duration, out var duration)) { yield return duration; } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Assets/ImageAssetMetadataSource.cs b/backend/src/Squidex.Domain.Apps.Entities/Assets/ImageAssetMetadataSource.cs index 0693c8522..d1a9fe2fc 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Assets/ImageAssetMetadataSource.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Assets/ImageAssetMetadataSource.cs @@ -66,8 +66,8 @@ public sealed class ImageAssetMetadataSource : IAssetMetadataSource { command.Type = AssetType.Image; - command.Metadata.SetPixelWidth(imageInfo.PixelWidth); - command.Metadata.SetPixelHeight(imageInfo.PixelHeight); + command.Metadata[KnownMetadataKeys.PixelWidth] = imageInfo.PixelWidth; + command.Metadata[KnownMetadataKeys.PixelHeight] = imageInfo.PixelHeight; } } } @@ -81,7 +81,7 @@ public sealed class ImageAssetMetadataSource : IAssetMetadataSource { command.Tags.Add("image"); - var wh = command.Metadata.GetPixelWidth() + command.Metadata.GetPixelWidth(); + var wh = command.Metadata.GetInt32(KnownMetadataKeys.PixelWidth) + command.Metadata.GetInt32(KnownMetadataKeys.PixelWidth); if (wh > 2000) { @@ -100,15 +100,15 @@ public sealed class ImageAssetMetadataSource : IAssetMetadataSource public IEnumerable Format(Asset asset) { - if (asset.Type == AssetType.Image) + if (asset.Type != AssetType.Image) { - var w = asset.Metadata.GetPixelWidth(); - var h = asset.Metadata.GetPixelHeight(); + yield break; + } - if (w != null && h != null) - { - yield return $"{w}x{h}px"; - } + if (asset.Metadata.TryGetNumber(KnownMetadataKeys.PixelWidth, out var w) && + asset.Metadata.TryGetNumber(KnownMetadataKeys.PixelHeight, out var h)) + { + yield return $"{w}x{h}px"; } } } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Assets/SvgAssetMetadataSource.cs b/backend/src/Squidex.Domain.Apps.Entities/Assets/SvgAssetMetadataSource.cs index 3b90ff281..556e6fc34 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Assets/SvgAssetMetadataSource.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Assets/SvgAssetMetadataSource.cs @@ -24,38 +24,68 @@ public sealed class SvgAssetMetadataSource : IAssetMetadataSource command.File.MimeType == "image/svg+xml" || command.File.FileName.EndsWith(".svg", StringComparison.OrdinalIgnoreCase); - if (isSvg) + if (!isSvg) { - command.Tags.Add("image"); + return; + } + + command.Tags.Add("image"); + + if (command.File.FileSize >= FileSizeLimit) + { + return; + } - if (command.File.FileSize < FileSizeLimit) + try + { + using (var reader = new StreamReader(command.File.OpenRead())) { - try + var text = await reader.ReadToEndAsync(ct); + + if (!text.IsValidSvg()) { - using (var reader = new StreamReader(command.File.OpenRead())) - { - var text = await reader.ReadToEndAsync(); - - if (!text.IsValidSvg()) - { - throw new ValidationException(T.Get("validation.notAnValidSvg")); - } - } + throw new ValidationException(T.Get("validation.notAnValidSvg")); } - catch (ValidationException) + + var (width, height, viewBox) = text.GetSvgMetadata(); + + if (!string.IsNullOrWhiteSpace(width) && !string.IsNullOrWhiteSpace(height)) { - throw; + command.Metadata[KnownMetadataKeys.PixelWidth] = width; + command.Metadata[KnownMetadataKeys.PixelHeight] = height; } - catch + + if (!string.IsNullOrWhiteSpace(viewBox)) { - return; + command.Metadata[KnownMetadataKeys.ViewBox] = viewBox; } } } + catch (ValidationException) + { + throw; + } + catch + { + return; + } } public IEnumerable Format(Asset asset) { - yield break; + var isSvg = + asset.MimeType == "image/svg+xml" || + asset.FileName.EndsWith(".svg", StringComparison.OrdinalIgnoreCase); + + if (!isSvg) + { + yield break; + } + + if (asset.Metadata.TryGetString(KnownMetadataKeys.PixelWidth, out var w) && + asset.Metadata.TryGetString(KnownMetadataKeys.PixelHeight, out var h)) + { + yield return $"{w}x{h}"; + } } } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Assets/AssetGraphType.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Assets/AssetGraphType.cs index 8a4c313dd..5e74d0e60 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Assets/AssetGraphType.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Assets/AssetGraphType.cs @@ -188,7 +188,7 @@ internal sealed class AssetGraphType : SharedObjectGraphType { Name = "pixelWidth", ResolvedType = Scalars.Int, - Resolver = Resolve(x => x.Metadata.GetPixelWidth()), + Resolver = Resolve(x => x.Metadata.GetInt32(KnownMetadataKeys.PixelWidth)), Description = FieldDescriptions.AssetPixelWidth, DeprecationReason = "Use 'metadata' field instead." }); @@ -197,7 +197,7 @@ internal sealed class AssetGraphType : SharedObjectGraphType { Name = "pixelHeight", ResolvedType = Scalars.Int, - Resolver = Resolve(x => x.Metadata.GetPixelHeight()), + Resolver = Resolve(x => x.Metadata.GetInt32(KnownMetadataKeys.PixelHeight)), Description = FieldDescriptions.AssetPixelHeight, DeprecationReason = "Use 'metadata' field instead." }); diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Assets/EnrichedAssetEventGraphType.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Assets/EnrichedAssetEventGraphType.cs index 28ca24d6a..99f43a9b5 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Assets/EnrichedAssetEventGraphType.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Assets/EnrichedAssetEventGraphType.cs @@ -195,7 +195,7 @@ internal sealed class EnrichedAssetEventGraphType : SharedObjectGraphType x.Metadata.GetPixelWidth()), + Resolver = Resolve(x => x.Metadata.GetInt32(KnownMetadataKeys.PixelWidth)), Description = FieldDescriptions.AssetPixelWidth, DeprecationReason = "Use 'metadata' field instead." }); @@ -204,7 +204,7 @@ internal sealed class EnrichedAssetEventGraphType : SharedObjectGraphType x.Metadata.GetPixelHeight()), + Resolver = Resolve(x => x.Metadata.GetInt32(KnownMetadataKeys.PixelHeight)), Description = FieldDescriptions.AssetPixelHeight, DeprecationReason = "Use 'metadata' field instead." }); diff --git a/backend/src/Squidex.Domain.Apps.Entities/Squidex.Domain.Apps.Entities.csproj b/backend/src/Squidex.Domain.Apps.Entities/Squidex.Domain.Apps.Entities.csproj index 8d2f53cc3..963611fba 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Squidex.Domain.Apps.Entities.csproj +++ b/backend/src/Squidex.Domain.Apps.Entities/Squidex.Domain.Apps.Entities.csproj @@ -24,10 +24,10 @@ - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/backend/src/Squidex.Domain.Apps.Events/Squidex.Domain.Apps.Events.csproj b/backend/src/Squidex.Domain.Apps.Events/Squidex.Domain.Apps.Events.csproj index 388880730..1486d859f 100644 --- a/backend/src/Squidex.Domain.Apps.Events/Squidex.Domain.Apps.Events.csproj +++ b/backend/src/Squidex.Domain.Apps.Events/Squidex.Domain.Apps.Events.csproj @@ -14,7 +14,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/backend/src/Squidex.Domain.Users.MongoDb/Squidex.Domain.Users.MongoDb.csproj b/backend/src/Squidex.Domain.Users.MongoDb/Squidex.Domain.Users.MongoDb.csproj index 83f7b27d0..60a317c13 100644 --- a/backend/src/Squidex.Domain.Users.MongoDb/Squidex.Domain.Users.MongoDb.csproj +++ b/backend/src/Squidex.Domain.Users.MongoDb/Squidex.Domain.Users.MongoDb.csproj @@ -19,7 +19,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/backend/src/Squidex.Domain.Users/Squidex.Domain.Users.csproj b/backend/src/Squidex.Domain.Users/Squidex.Domain.Users.csproj index 93c9b8cd2..cebbfd461 100644 --- a/backend/src/Squidex.Domain.Users/Squidex.Domain.Users.csproj +++ b/backend/src/Squidex.Domain.Users/Squidex.Domain.Users.csproj @@ -18,7 +18,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/backend/src/Squidex.Infrastructure.GetEventStore/Squidex.Infrastructure.GetEventStore.csproj b/backend/src/Squidex.Infrastructure.GetEventStore/Squidex.Infrastructure.GetEventStore.csproj index 286176647..f6081a278 100644 --- a/backend/src/Squidex.Infrastructure.GetEventStore/Squidex.Infrastructure.GetEventStore.csproj +++ b/backend/src/Squidex.Infrastructure.GetEventStore/Squidex.Infrastructure.GetEventStore.csproj @@ -15,7 +15,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/backend/src/Squidex.Infrastructure.MongoDb/Squidex.Infrastructure.MongoDb.csproj b/backend/src/Squidex.Infrastructure.MongoDb/Squidex.Infrastructure.MongoDb.csproj index 47c66e37d..62b4188b5 100644 --- a/backend/src/Squidex.Infrastructure.MongoDb/Squidex.Infrastructure.MongoDb.csproj +++ b/backend/src/Squidex.Infrastructure.MongoDb/Squidex.Infrastructure.MongoDb.csproj @@ -14,7 +14,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/backend/src/Squidex.Infrastructure/Squidex.Infrastructure.csproj b/backend/src/Squidex.Infrastructure/Squidex.Infrastructure.csproj index 15fc970eb..46843f7dd 100644 --- a/backend/src/Squidex.Infrastructure/Squidex.Infrastructure.csproj +++ b/backend/src/Squidex.Infrastructure/Squidex.Infrastructure.csproj @@ -13,7 +13,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -24,12 +24,12 @@ - - - - - - + + + + + + diff --git a/backend/src/Squidex.Shared/Squidex.Shared.csproj b/backend/src/Squidex.Shared/Squidex.Shared.csproj index b95dab58b..a39f5b184 100644 --- a/backend/src/Squidex.Shared/Squidex.Shared.csproj +++ b/backend/src/Squidex.Shared/Squidex.Shared.csproj @@ -10,7 +10,7 @@ True - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/backend/src/Squidex.Web/Squidex.Web.csproj b/backend/src/Squidex.Web/Squidex.Web.csproj index a7cb88ceb..414ca50c9 100644 --- a/backend/src/Squidex.Web/Squidex.Web.csproj +++ b/backend/src/Squidex.Web/Squidex.Web.csproj @@ -16,7 +16,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/backend/src/Squidex/Areas/Api/Controllers/Assets/Models/AssetContentQueryDto.cs b/backend/src/Squidex/Areas/Api/Controllers/Assets/Models/AssetContentQueryDto.cs index 912386b54..5a4cf9144 100644 --- a/backend/src/Squidex/Areas/Api/Controllers/Assets/Models/AssetContentQueryDto.cs +++ b/backend/src/Squidex/Areas/Api/Controllers/Assets/Models/AssetContentQueryDto.cs @@ -176,8 +176,8 @@ public sealed class AssetContentQueryDto return (FocusX.Value, FocusY.Value); } - var focusX = asset.Metadata.GetFocusX(); - var focusY = asset.Metadata.GetFocusY(); + var focusX = asset.Metadata.GetSingle(KnownMetadataKeys.FocusX); + var focusY = asset.Metadata.GetSingle(KnownMetadataKeys.FocusY); if (focusX != null && focusY != null) { diff --git a/backend/src/Squidex/Areas/Api/Controllers/Assets/Models/AssetDto.cs b/backend/src/Squidex/Areas/Api/Controllers/Assets/Models/AssetDto.cs index 677671b14..cbce83097 100644 --- a/backend/src/Squidex/Areas/Api/Controllers/Assets/Models/AssetDto.cs +++ b/backend/src/Squidex/Areas/Api/Controllers/Assets/Models/AssetDto.cs @@ -138,7 +138,7 @@ public sealed class AssetDto : Resource [Obsolete("Use 'metadata' field now.")] public int? PixelWidth { - get => Metadata.GetPixelWidth(); + get => Metadata.GetInt32(KnownMetadataKeys.PixelWidth); } /// @@ -147,7 +147,7 @@ public sealed class AssetDto : Resource [Obsolete("Use 'metadata' field now.")] public int? PixelHeight { - get => Metadata.GetPixelHeight(); + get => Metadata.GetInt32(KnownMetadataKeys.PixelHeight); } public static AssetDto FromDomain(EnrichedAsset asset, Resources resources, bool isDuplicate = false) diff --git a/backend/src/Squidex/Squidex.csproj b/backend/src/Squidex/Squidex.csproj index 83022eb75..d1e17a3fe 100644 --- a/backend/src/Squidex/Squidex.csproj +++ b/backend/src/Squidex/Squidex.csproj @@ -37,7 +37,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -63,18 +63,18 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/backend/src/Squidex/wwwroot/editor/squidex-editor.js b/backend/src/Squidex/wwwroot/editor/squidex-editor.js index f8738c4b1..922d91ab4 100644 --- a/backend/src/Squidex/wwwroot/editor/squidex-editor.js +++ b/backend/src/Squidex/wwwroot/editor/squidex-editor.js @@ -6234,7 +6234,7 @@ ${u} background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1MAAA6mAAADqYAAAXb5JfxUYAAAAZSURBVHjaYvj///9/hivKyv8BAAAA//8DACLqBhbvk+/eAAAAAElFTkSuQmCC") right repeat-y; } `}),ace.define("ace/theme/github",["require","exports","module","ace/theme/github-css","ace/lib/dom"],function(n,r,o){r.isDark=!1,r.cssClass="ace-github",r.cssText=n("./github-css");var i=n("../lib/dom");i.importCssString(r.cssText,r.cssClass,!1)}),function(){ace.require(["ace/theme/github"],function(n){t&&(t.exports=n)})}()})(pge);const gge=({mode:t,value:e})=>{const n=D.useMemo(()=>{if(!PE(e))return{mode:"markdown",value:null};switch(t){case"Markdown":return{mode:"markdown",value:e};case"Html":return{mode:"html",value:mge(e||"")};default:return{mode:"markdown",value:null}}},[t,e]);return(n==null?void 0:n.value)==null?null:V.jsx(dge,{mode:n.mode,value:n.value,height:"100%",width:"100%",readOnly:!0,wrapEnabled:!0})},Z_=" ";function mge(t){let e="",n="";return t.split(/>\s*{r.match(/^\/\w/)&&(n=n.substring(Z_.length)),e+=n+"<"+r+`>\r -`,r.match(/^]*[^/]$/)&&!r.startsWith("input")&&(n+=Z_)}),e.substring(1,e.length-3)}const vge=t=>{const{onClose:e,node:n}=t,[r,o,i]=d$(""),s=hn();D.useEffect(()=>{o(n.node.attrs.title||"")},[n,o]);const l=D.useCallback(c=>{o(c.target.value)},[o]),a=D.useCallback(()=>{s.updateNodeAttributes(n.getPos()||0,{...n.node.attrs||{},title:i.current}),e()},[s,n,e,i]),u=D.useCallback(c=>{const{code:d}=c;d==="Enter"&&a(),d==="Escape"&&e()},[e,a]);return V.jsxs(k$,{title:"Change Image Title",children:[V.jsx(x$,{value:r,onChange:l,onKeyDown:u,placeholder:"Enter Title..."}),V.jsxs(Br,{children:[V.jsx(Rt,{commandName:"submitLink",enabled:!0,onSelect:a,icon:V.jsx(eo,{type:"Check"})}),V.jsx(Rt,{commandName:"cancelLink",enabled:!0,onSelect:e,icon:V.jsx(eo,{type:"Cancel"})})]})]})};const yge=t=>{const{annotations:e,appName:n,canAddAnnotation:r,canSelectAIText:o,canSelectAssets:i,canSelectContents:s,classNames:l,isDisabled:a,mode:u,onAnnotationCreate:c,onAnnotationsFocus:d,onAnnotationsUpdate:h,onChange:f,onEditAsset:p,onEditContent:g,onSelectAIText:m,onSelectAssets:v,onSelectContents:y,onUpload:b,value:w}=t,k=D.useMemo(()=>{let L=t.baseUrl;return L.endsWith("/")&&(L=L.substring(0,L.length-1)),L},[t.baseUrl]),[x,S]=D.useState(),[T,C]=D.useState(!1),[I,_]=D.useState(!1),R=D.useCallback(()=>{C(!0)},[]),A=D.useCallback(()=>{C(!1)},[]),E=D.useCallback(()=>{S(null)},[]),M=D.useCallback(()=>{_(L=>!L)},[]),O=D.useCallback(()=>[new Nn,new yk,new pl({}),new _h({enableSpine:!0}),new su({classNames:l}),new bo({supportedLanguages:rfe}),new Mh,new Ph({appName:n,baseUrl:k,onEditContent:g}),new Ys({}),new Kg,new Yg({}),new Xg,new Afe({copyAsHtml:u==="Html"}),new Oh({uploadHandler:b}),new Ih,new gl({autoLink:!0}),new fl({enableCollapsible:!0}),new iu({copyAsMarkdown:u==="Markdown",htmlToMarkdown:wfe,markdownToHtml:xfe}),new Rh,new rm,new Nh,new ob,new $h],[n,k,l,u,g,b]),{manager:N}=MQ({stringHandler:u==="Markdown"?"markdown":"html",content:w,nodeViewComponents:{image:L=>V.jsx(Tfe,{...L,appName:n,baseUrl:k,onEditNode:S,onEditAsset:p})},extensions:O});return V.jsx(jue,{children:V.jsx(Fue,{theme:{color:{primary:"#3389ff",active:{primary:"#3389ff"}}},children:V.jsxs(LQ,{classNames:a?["squidex-editor-disabled"]:[],manager:N,children:[V.jsx("div",{className:"squidex-editor-menu",children:V.jsxs(FN,{children:[V.jsxs("fieldset",{disabled:I,className:"MuiStack-root",children:[V.jsx(Due,{}),V.jsx($ue,{showAll:!0}),V.jsxs(Br,{children:[V.jsx(Yx,{}),V.jsx(qx,{}),V.jsx(Zx,{}),V.jsx(Xx,{})]}),V.jsxs(Br,{children:[V.jsx(kue,{}),V.jsx(Sue,{}),V.jsx(wue,{})]}),V.jsxs(Br,{children:[V.jsx(Eue,{}),V.jsx(Cue,{})]}),u!=="Markdown"&&l&&l.length>0&&V.jsx(Br,{children:V.jsx(jfe,{})}),V.jsx(Br,{children:V.jsx(E$,{onEdit:R})}),V.jsxs(Br,{children:[i&&v&&V.jsx(zfe,{onSelectAssets:v}),s&&y&&V.jsx(Ffe,{onSelectContents:y}),o&&m&&V.jsx(Dfe,{onSelectAIText:m})]}),r&&c&&V.jsx(Br,{children:V.jsx(Hfe,{onAnnotationCreate:c})}),u==="Html"&&V.jsx(Br,{children:V.jsx(Bfe,{})})]}),V.jsx(Rt,{commandName:"toggleMarkup",enabled:!0,onSelect:M,label:"Show Markup (readonly)",icon:V.jsx(eo,{type:"Preview"})})]})}),V.jsxs("div",{className:"squidex-editor-main",children:[V.jsx(_fe,{mode:u,onChange:f,value:w}),V.jsx(Wy,{}),I&&V.jsx(gge,{value:w,mode:u}),T?V.jsx(Kfe,{onClose:A}):x?V.jsx(vge,{node:x,onClose:E}):V.jsx(bge,{onLinkModal:R}),V.jsx(Uue,{offset:{x:5,y:5},className:Bc(V0.LANGUAGE_SELECT_POSITIONER,V0.LANGUAGE_SELECT_WIDTH)}),V.jsx(Ufe,{annotations:e,onAnnotationsFocus:d,onAnnotationsUpdate:h})]}),V.jsx(Gfe,{})]})})})},bge=({onLinkModal:t})=>pr().codeBlock()?null:V.jsxs(Hue,{className:"squidex-editor-floating",children:[V.jsx(Yx,{}),V.jsx(qx,{}),V.jsx(Zx,{}),V.jsx(Xx,{}),V.jsx(E$,{onEdit:t})]});var D$,Q_=of;D$=Q_.createRoot,Q_.hydrateRoot;class wge{constructor(e,n){dt(this,"root");this.element=e,this.props=n,this.root=D$(this.element),this.render()}update(e){this.props={...this.props,...e},this.render()}setValue(e){this.update({value:e})}setAnnotations(e){this.update({annotations:e})}setIsDisabled(e){this.update({isDisabled:e})}destroy(){this.root.unmount()}render(){this.root.render(V.jsx(yge,{...this.props}))}}/* +`,r.match(/^]*[^/]$/)&&!r.startsWith("input")&&(n+=Z_)}),e.substring(1,e.length-3)}const vge=t=>{const{onClose:e,node:n}=t,[r,o,i]=d$(""),s=hn();D.useEffect(()=>{o(n.node.attrs.title||"")},[n,o]);const l=D.useCallback(c=>{o(c.target.value)},[o]),a=D.useCallback(()=>{s.updateNodeAttributes(n.getPos()||0,{...n.node.attrs||{},title:i.current}),e()},[s,n,e,i]),u=D.useCallback(c=>{const{code:d}=c;d==="Enter"&&a(),d==="Escape"&&e()},[e,a]);return V.jsxs(k$,{title:"Change Image Title",children:[V.jsx(x$,{value:r,onChange:l,onKeyDown:u,placeholder:"Enter Title..."}),V.jsxs(Br,{children:[V.jsx(Rt,{commandName:"submitLink",enabled:!0,onSelect:a,icon:V.jsx(eo,{type:"Check"})}),V.jsx(Rt,{commandName:"cancelLink",enabled:!0,onSelect:e,icon:V.jsx(eo,{type:"Cancel"})})]})]})};const yge=t=>{const{annotations:e,appName:n,canAddAnnotation:r,canSelectAIText:o,canSelectAssets:i,canSelectContents:s,classNames:l,isDisabled:a,mode:u,onAnnotationCreate:c,onAnnotationsFocus:d,onAnnotationsUpdate:h,onChange:f,onEditAsset:p,onEditContent:g,onSelectAIText:m,onSelectAssets:v,onSelectContents:y,onUpload:b,value:w}=t,k=D.useMemo(()=>{let L=t.baseUrl;return L.endsWith("/")&&(L=L.substring(0,L.length-1)),L},[t.baseUrl]),[x,S]=D.useState(),[T,C]=D.useState(!1),[I,_]=D.useState(!1),R=D.useCallback(()=>{C(!0)},[]),A=D.useCallback(()=>{C(!1)},[]),E=D.useCallback(()=>{S(null)},[]),M=D.useCallback(()=>{_(L=>!L)},[]),O=D.useCallback(()=>[new Nn,new yk,new pl({}),new _h({enableSpine:!0}),new su({classNames:l}),new bo({supportedLanguages:rfe}),new Mh,new Ph({appName:n,baseUrl:k,onEditContent:g}),new Ys({}),new Kg,new Yg({}),new Xg,new Afe({copyAsHtml:u==="Html"}),new Oh({uploadHandler:b}),new Ih,new gl({autoLink:!0}),new fl({enableCollapsible:!0}),new iu({copyAsMarkdown:u==="Markdown",htmlToMarkdown:wfe,markdownToHtml:xfe}),new Rh,new rm,new Nh,new ob,new $h],[n,k,l,u,g,b]),{manager:N}=MQ({stringHandler:u==="Markdown"?"markdown":"html",content:w,nodeViewComponents:{image:L=>V.jsx(Tfe,{...L,appName:n,baseUrl:k,onEditNode:S,onEditAsset:p})},extensions:O});return V.jsx(jue,{children:V.jsx(Fue,{theme:{color:{primary:"#3389ff",active:{primary:"#3389ff"}}},children:V.jsxs(LQ,{classNames:a?["squidex-editor-disabled"]:[],manager:N,children:[V.jsx("div",{className:"squidex-editor-menu",children:V.jsxs(FN,{children:[V.jsxs("fieldset",{disabled:I||a,className:"MuiStack-root",children:[V.jsx(Due,{}),V.jsx($ue,{showAll:!0}),V.jsxs(Br,{children:[V.jsx(Yx,{}),V.jsx(qx,{}),V.jsx(Zx,{}),V.jsx(Xx,{})]}),V.jsxs(Br,{children:[V.jsx(kue,{}),V.jsx(Sue,{}),V.jsx(wue,{})]}),V.jsxs(Br,{children:[V.jsx(Eue,{}),V.jsx(Cue,{})]}),u!=="Markdown"&&l&&l.length>0&&V.jsx(Br,{children:V.jsx(jfe,{})}),V.jsx(Br,{children:V.jsx(E$,{onEdit:R})}),V.jsxs(Br,{children:[i&&v&&V.jsx(zfe,{onSelectAssets:v}),s&&y&&V.jsx(Ffe,{onSelectContents:y}),o&&m&&V.jsx(Dfe,{onSelectAIText:m})]}),r&&c&&V.jsx(Br,{children:V.jsx(Hfe,{onAnnotationCreate:c})}),u==="Html"&&V.jsx(Br,{children:V.jsx(Bfe,{})})]}),V.jsx(Rt,{commandName:"toggleMarkup",enabled:!0,onSelect:M,label:"Show Markup (readonly)",icon:V.jsx(eo,{type:"Preview"})})]})}),V.jsxs("div",{className:"squidex-editor-main",children:[V.jsx(_fe,{mode:u,onChange:f,value:w}),V.jsx(Wy,{}),I&&V.jsx(gge,{value:w,mode:u}),T?V.jsx(Kfe,{onClose:A}):x?V.jsx(vge,{node:x,onClose:E}):V.jsx(bge,{onLinkModal:R}),V.jsx(Uue,{offset:{x:5,y:5},className:Bc(V0.LANGUAGE_SELECT_POSITIONER,V0.LANGUAGE_SELECT_WIDTH)}),V.jsx(Ufe,{annotations:e,onAnnotationsFocus:d,onAnnotationsUpdate:h})]}),V.jsx(Gfe,{})]})})})},bge=({onLinkModal:t})=>pr().codeBlock()?null:V.jsxs(Hue,{className:"squidex-editor-floating",children:[V.jsx(Yx,{}),V.jsx(qx,{}),V.jsx(Zx,{}),V.jsx(Xx,{}),V.jsx(E$,{onEdit:t})]});var D$,Q_=of;D$=Q_.createRoot,Q_.hydrateRoot;class wge{constructor(e,n){dt(this,"root");this.element=e,this.props=n,this.root=D$(this.element),this.render()}update(e){this.props={...this.props,...e},this.render()}setValue(e){this.update({value:e})}setAnnotations(e){this.update({annotations:e})}setIsDisabled(e){this.update({isDisabled:e})}destroy(){this.root.unmount()}render(){this.root.render(V.jsx(yge,{...this.props}))}}/* * Squidex Headless CMS * * @license diff --git a/backend/tests/Squidex.Domain.Apps.Core.Tests/Model/Assets/AssetMetadataTests.cs b/backend/tests/Squidex.Domain.Apps.Core.Tests/Model/Assets/AssetMetadataTests.cs index 9a6df44bb..14bdfa5f2 100644 --- a/backend/tests/Squidex.Domain.Apps.Core.Tests/Model/Assets/AssetMetadataTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Core.Tests/Model/Assets/AssetMetadataTests.cs @@ -16,12 +16,14 @@ public class AssetMetadataTests public void Should_return_focus_infos_if_found() { var sut = - new AssetMetadata() - .SetFocusX(.5f) - .SetFocusY(.2f); - - Assert.Equal(.5f, sut.GetFocusX()); - Assert.Equal(.2f, sut.GetFocusY()); + new AssetMetadata + { + [KnownMetadataKeys.FocusX] = .5f, + [KnownMetadataKeys.FocusY] = .2f, + }; + + Assert.Equal(.5f, sut.GetSingle(KnownMetadataKeys.FocusX)); + Assert.Equal(.2f, sut.GetSingle(KnownMetadataKeys.FocusY)); } [Fact] @@ -29,20 +31,22 @@ public class AssetMetadataTests { var sut = new AssetMetadata(); - Assert.Null(sut.GetFocusX()); - Assert.Null(sut.GetFocusY()); + Assert.Null(sut.GetSingle(KnownMetadataKeys.FocusX)); + Assert.Null(sut.GetSingle(KnownMetadataKeys.FocusY)); } [Fact] public void Should_return_pixel_infos_if_found() { var sut = - new AssetMetadata() - .SetPixelWidth(800) - .SetPixelHeight(600); - - Assert.Equal(800, sut.GetPixelWidth()); - Assert.Equal(600, sut.GetPixelHeight()); + new AssetMetadata + { + [KnownMetadataKeys.PixelWidth] = 800, + [KnownMetadataKeys.PixelHeight] = 600, + }; + + Assert.Equal(800, sut.GetInt32(KnownMetadataKeys.PixelWidth)); + Assert.Equal(600, sut.GetInt32(KnownMetadataKeys.PixelHeight)); } [Fact] @@ -50,8 +54,8 @@ public class AssetMetadataTests { var sut = new AssetMetadata(); - Assert.Null(sut.GetPixelWidth()); - Assert.Null(sut.GetPixelHeight()); + Assert.Null(sut.GetInt32(KnownMetadataKeys.PixelWidth)); + Assert.Null(sut.GetInt32(KnownMetadataKeys.PixelHeight)); } [Fact] diff --git a/backend/tests/Squidex.Domain.Apps.Core.Tests/Model/Assets/AssetTests.cs b/backend/tests/Squidex.Domain.Apps.Core.Tests/Model/Assets/AssetTests.cs index 6ba820c45..af94e0052 100644 --- a/backend/tests/Squidex.Domain.Apps.Core.Tests/Model/Assets/AssetTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Core.Tests/Model/Assets/AssetTests.cs @@ -131,8 +131,8 @@ public class AssetTests [Fact] public void Should_annotate_with_metadata() { - var newMetadata1 = new AssetMetadata().SetPixelWidth(1024); - var newMetadata2 = new AssetMetadata().SetPixelWidth(1024); + var newMetadata1 = new AssetMetadata { [KnownMetadataKeys.PixelWidth] = 1024 }; + var newMetadata2 = new AssetMetadata { [KnownMetadataKeys.PixelWidth] = 1024 }; var asset_1 = asset_0.Annotate(metadata: newMetadata1); var asset_2 = asset_1.Annotate(metadata: newMetadata2); diff --git a/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/Scripting/JintScriptEngineTests.cs b/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/Scripting/JintScriptEngineTests.cs index 7d9e9a93d..4bbf21baa 100644 --- a/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/Scripting/JintScriptEngineTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/Scripting/JintScriptEngineTests.cs @@ -9,6 +9,7 @@ using System.Net; using System.Security.Claims; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Options; +using Squidex.Domain.Apps.Core.Assets; using Squidex.Domain.Apps.Core.Contents; using Squidex.Domain.Apps.Core.Scripting; using Squidex.Domain.Apps.Core.Scripting.Extensions; @@ -680,4 +681,21 @@ public class JintScriptEngineTests : IClassFixture Assert.Equal(113.0, vars["shared"]); } + + [Fact] + public async Task Should_set_metadata() + { + var vars = new DataScriptVars + { + ["metadata"] = new AssetMetadata() + }; + + var script = @$" + ctx.metadata['pixelWidth'] = 100; + "; + + await sut.ExecuteAsync(vars, script, new ScriptOptions { AsContext = true }); + + Assert.Equal(100, ((AssetMetadata)vars["metadata"]!).GetInt32(KnownMetadataKeys.PixelWidth)); + } } diff --git a/backend/tests/Squidex.Domain.Apps.Core.Tests/Squidex.Domain.Apps.Core.Tests.csproj b/backend/tests/Squidex.Domain.Apps.Core.Tests/Squidex.Domain.Apps.Core.Tests.csproj index 96a7c8538..d0c2147fa 100644 --- a/backend/tests/Squidex.Domain.Apps.Core.Tests/Squidex.Domain.Apps.Core.Tests.csproj +++ b/backend/tests/Squidex.Domain.Apps.Core.Tests/Squidex.Domain.Apps.Core.Tests.csproj @@ -16,7 +16,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/backend/tests/Squidex.Domain.Apps.Core.Tests/TestHelpers/TestAssets.cs b/backend/tests/Squidex.Domain.Apps.Core.Tests/TestHelpers/TestAssets.cs index 847c6ffe6..5802a633c 100644 --- a/backend/tests/Squidex.Domain.Apps.Core.Tests/TestHelpers/TestAssets.cs +++ b/backend/tests/Squidex.Domain.Apps.Core.Tests/TestHelpers/TestAssets.cs @@ -31,10 +31,11 @@ public static class TestAssets FileName = "MyImage.png", FileSize = 1024 * 8, Type = AssetType.Image, - Metadata = - new AssetMetadata() - .SetPixelWidth(800) - .SetPixelHeight(600) + Metadata = new AssetMetadata + { + [KnownMetadataKeys.PixelWidth] = 800, + [KnownMetadataKeys.PixelHeight] = 600, + } }; } @@ -46,10 +47,11 @@ public static class TestAssets FileName = "MyImage.png", FileSize = 1024 * 8, Type = AssetType.Video, - Metadata = - new AssetMetadata() - .SetVideoWidth(800) - .SetVideoHeight(600) + Metadata = new AssetMetadata + { + [KnownMetadataKeys.VideoWidth] = 800, + [KnownMetadataKeys.VideoHeight] = 600, + } }; } diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetsJintExtensionTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetsJintExtensionTests.cs index ce4ff0fa0..c2aa45277 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetsJintExtensionTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetsJintExtensionTests.cs @@ -354,8 +354,8 @@ public class AssetsJintExtensionTests : GivenContext, IClassFixture [Fact] public async Task AnnotateMetadata_should_create_events_and_update_metadata() { - var command = new AnnotateAsset { Metadata = new AssetMetadata().SetPixelWidth(800) }; + var command = new AnnotateAsset { Metadata = new AssetMetadata { [KnownMetadataKeys.PixelWidth] = 800 } }; await ExecuteCreateAsync(); diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/FileTagAssetMetadataSourceTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/FileTagAssetMetadataSourceTests.cs index df51c6d5b..0a702c3c0 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/FileTagAssetMetadataSourceTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/FileTagAssetMetadataSourceTests.cs @@ -36,8 +36,8 @@ public class FileTagAssetMetadataSourceTests : GivenContext Assert.Equal(AssetType.Image, command.Type); - Assert.Equal(272, command.Metadata.GetPixelWidth()); - Assert.Equal(170, command.Metadata.GetPixelHeight()); + Assert.Equal(272, command.Metadata.GetInt32(KnownMetadataKeys.PixelWidth)); + Assert.Equal(170, command.Metadata.GetInt32(KnownMetadataKeys.PixelHeight)); } [Fact] @@ -47,8 +47,8 @@ public class FileTagAssetMetadataSourceTests : GivenContext await sut.EnhanceAsync(command, default); - Assert.Null(command.Metadata.GetPixelWidth()); - Assert.Null(command.Metadata.GetPixelHeight()); + Assert.Null(command.Metadata.GetInt32(KnownMetadataKeys.PixelWidth)); + Assert.Null(command.Metadata.GetInt32(KnownMetadataKeys.PixelHeight)); } [Fact] @@ -60,10 +60,10 @@ public class FileTagAssetMetadataSourceTests : GivenContext Assert.Equal(AssetType.Audio, command.Type); - Assert.Equal(JsonValue.Create("00:00:28.2708750"), command.Metadata["duration"]); - Assert.Equal(JsonValue.Create(128L), command.Metadata["audioBitrate"]); - Assert.Equal(JsonValue.Create(2L), command.Metadata["audioChannels"]); - Assert.Equal(JsonValue.Create(44100L), command.Metadata["audioSampleRate"]); + Assert.Equal(JsonValue.Create("00:00:28.2708750"), command.Metadata[KnownMetadataKeys.Duration]); + Assert.Equal(JsonValue.Create(2L), command.Metadata[KnownMetadataKeys.AudioChannels]); + Assert.Equal(JsonValue.Create(128L), command.Metadata[KnownMetadataKeys.AudioBitrate]); + Assert.Equal(JsonValue.Create(44100L), command.Metadata[KnownMetadataKeys.AudioSampleRate]); } [Fact] @@ -75,12 +75,12 @@ public class FileTagAssetMetadataSourceTests : GivenContext Assert.Equal(AssetType.Video, command.Type); - Assert.Equal(JsonValue.Create("00:00:05.3120000"), command.Metadata["duration"]); - Assert.Equal(JsonValue.Create(384L), command.Metadata["audioBitrate"]); - Assert.Equal(JsonValue.Create(2L), command.Metadata["audioChannels"]); - Assert.Equal(JsonValue.Create(48000L), command.Metadata["audioSampleRate"]); - Assert.Equal(JsonValue.Create(1280L), command.Metadata["videoWidth"]); - Assert.Equal(JsonValue.Create(720L), command.Metadata["videoHeight"]); + Assert.Equal(JsonValue.Create("00:00:05.3120000"), command.Metadata[KnownMetadataKeys.Duration]); + Assert.Equal(JsonValue.Create(2L), command.Metadata[KnownMetadataKeys.AudioChannels]); + Assert.Equal(JsonValue.Create(384L), command.Metadata[KnownMetadataKeys.AudioBitrate]); + Assert.Equal(JsonValue.Create(48000L), command.Metadata[KnownMetadataKeys.AudioSampleRate]); + Assert.Equal(JsonValue.Create(720L), command.Metadata[KnownMetadataKeys.VideoHeight]); + Assert.Equal(JsonValue.Create(1280L), command.Metadata[KnownMetadataKeys.VideoWidth]); } [Fact] @@ -90,9 +90,9 @@ public class FileTagAssetMetadataSourceTests : GivenContext { Metadata = new AssetMetadata { - ["videoWidth"] = JsonValue.Create(128), - ["videoHeight"] = JsonValue.Create(55), - ["duration"] = JsonValue.Create("00:10:12") + [KnownMetadataKeys.VideoWidth] = JsonValue.Create(128), + [KnownMetadataKeys.VideoHeight] = JsonValue.Create(55), + [KnownMetadataKeys.Duration] = JsonValue.Create("00:10:12") }, Type = AssetType.Video }; @@ -109,7 +109,7 @@ public class FileTagAssetMetadataSourceTests : GivenContext { Metadata = new AssetMetadata { - ["duration"] = JsonValue.Create("00:10:12") + [KnownMetadataKeys.Duration] = JsonValue.Create("00:10:12") }, Type = AssetType.Audio }; diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/ImageAssetMetadataSourceTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/ImageAssetMetadataSourceTests.cs index 3441341f4..5b83a489b 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/ImageAssetMetadataSourceTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/ImageAssetMetadataSourceTests.cs @@ -61,8 +61,8 @@ public class ImageAssetMetadataSourceTests : GivenContext await sut.EnhanceAsync(command, CancellationToken); - Assert.Equal(800, command.Metadata.GetPixelWidth()); - Assert.Equal(600, command.Metadata.GetPixelHeight()); + Assert.Equal(800, command.Metadata.GetInt32(KnownMetadataKeys.PixelWidth)); + Assert.Equal(600, command.Metadata.GetInt32(KnownMetadataKeys.PixelHeight)); Assert.Equal(AssetType.Image, command.Type); A.CallTo(() => assetGenerator.FixAsync(stream, file.MimeType, A._, A._)) @@ -82,8 +82,8 @@ public class ImageAssetMetadataSourceTests : GivenContext await sut.EnhanceAsync(command, CancellationToken); - Assert.Equal(800, command.Metadata.GetPixelWidth()); - Assert.Equal(600, command.Metadata.GetPixelHeight()); + Assert.Equal(800, command.Metadata.GetInt32(KnownMetadataKeys.PixelWidth)); + Assert.Equal(600, command.Metadata.GetInt32(KnownMetadataKeys.PixelHeight)); Assert.Equal(AssetType.Image, command.Type); A.CallTo(() => assetGenerator.FixAsync(stream, file.MimeType, A._, CancellationToken)) @@ -103,8 +103,8 @@ public class ImageAssetMetadataSourceTests : GivenContext await sut.EnhanceAsync(command, CancellationToken); - Assert.Equal(800, command.Metadata.GetPixelWidth()); - Assert.Equal(600, command.Metadata.GetPixelHeight()); + Assert.Equal(800, command.Metadata.GetInt32(KnownMetadataKeys.PixelWidth)); + Assert.Equal(600, command.Metadata.GetInt32(KnownMetadataKeys.PixelHeight)); Assert.Equal(AssetType.Image, command.Type); A.CallTo(() => assetGenerator.FixAsync(stream, file.MimeType, A._, CancellationToken)) @@ -116,8 +116,8 @@ public class ImageAssetMetadataSourceTests : GivenContext { var command = new CreateAsset { File = file, Type = AssetType.Image }; - command.Metadata.SetPixelWidth(100); - command.Metadata.SetPixelWidth(100); + command.Metadata[KnownMetadataKeys.PixelWidth] = 100; + command.Metadata[KnownMetadataKeys.PixelHeight] = 50; await sut.EnhanceAsync(command, CancellationToken); @@ -130,8 +130,8 @@ public class ImageAssetMetadataSourceTests : GivenContext { var command = new CreateAsset { File = file, Type = AssetType.Image }; - command.Metadata.SetPixelWidth(800); - command.Metadata.SetPixelWidth(600); + command.Metadata[KnownMetadataKeys.PixelWidth] = 800; + command.Metadata[KnownMetadataKeys.PixelHeight] = 600; await sut.EnhanceAsync(command, CancellationToken); @@ -144,8 +144,8 @@ public class ImageAssetMetadataSourceTests : GivenContext { var command = new CreateAsset { File = file, Type = AssetType.Image }; - command.Metadata.SetPixelWidth(1200); - command.Metadata.SetPixelWidth(1400); + command.Metadata[KnownMetadataKeys.PixelWidth] = 1400; + command.Metadata[KnownMetadataKeys.PixelHeight] = 1200; await sut.EnhanceAsync(command, CancellationToken); @@ -160,8 +160,8 @@ public class ImageAssetMetadataSourceTests : GivenContext { Metadata = new AssetMetadata { - ["pixelWidth"] = JsonValue.Create(128), - ["pixelHeight"] = JsonValue.Create(55) + [KnownMetadataKeys.PixelWidth] = 128, + [KnownMetadataKeys.PixelHeight] = 55 }, Type = AssetType.Image }; diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/SvgAssetMetadataSourceTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/SvgAssetMetadataSourceTests.cs index 3e333f286..60c58cde4 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/SvgAssetMetadataSourceTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/SvgAssetMetadataSourceTests.cs @@ -5,17 +5,16 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== -using System.Text; using Squidex.Assets; +using Squidex.Domain.Apps.Core.Assets; using Squidex.Domain.Apps.Entities.Assets.Commands; -using Squidex.Domain.Apps.Entities.Properties; +using Squidex.Domain.Apps.Entities.TestHelpers; using Squidex.Infrastructure.Validation; namespace Squidex.Domain.Apps.Entities.Assets; -public class SvgAssetMetadataSourceTests +public class SvgAssetMetadataSourceTests : GivenContext { - private readonly MemoryStream stream = new MemoryStream(); private readonly SvgAssetMetadataSource sut = new SvgAssetMetadataSource(); public SvgAssetMetadataSourceTests() @@ -26,9 +25,7 @@ public class SvgAssetMetadataSourceTests [Fact] public async Task Should_add_image_tag_if_svg_mime() { - var svg = new DelegateAssetFile("MyImage.png", "image/svg+xml", 1024, () => stream); - - var command = new CreateAsset { File = svg }; + var command = FakeCommand("image.svg"); await sut.EnhanceAsync(command, default); @@ -38,9 +35,7 @@ public class SvgAssetMetadataSourceTests [Fact] public async Task Should_add_image_tag_if_svg_extension() { - var svg = new DelegateAssetFile("MyImage.svg", "other", 1024, () => stream); - - var command = new CreateAsset { File = svg }; + var command = FakeCommand("image.svg"); await sut.EnhanceAsync(command, default); @@ -50,30 +45,63 @@ public class SvgAssetMetadataSourceTests [Fact] public async Task Should_throw_exception_if_svg_is_malicious() { - var bytes = Encoding.UTF8.GetBytes(Resources.SvgInvalid); + var command = Command("SvgInvalid.svg"); - stream.Write(bytes); - stream.Seek(0, SeekOrigin.Begin); + await Assert.ThrowsAsync(() => sut.EnhanceAsync(command, default)); - var svg = new DelegateAssetFile("MyImage.svg", "other", 1024, () => stream); + Assert.False(command.Metadata.ContainsKey(KnownMetadataKeys.PixelWidth)); + Assert.False(command.Metadata.ContainsKey(KnownMetadataKeys.PixelHeight)); + Assert.False(command.Metadata.ContainsKey(KnownMetadataKeys.ViewBox)); + } - var command = new CreateAsset { File = svg }; + [Fact] + public async Task Should_not_throw_exception_if_svg_is_not_malicious() + { + var command = Command("SvgValid.svg"); - await Assert.ThrowsAsync(() => sut.EnhanceAsync(command, default)); + await sut.EnhanceAsync(command, default); + + Assert.Equal("20", command.Metadata[KnownMetadataKeys.PixelWidth].AsString); + Assert.Equal("30", command.Metadata[KnownMetadataKeys.PixelHeight].AsString); + + Assert.Equal("0 0 100 100", command.Metadata[KnownMetadataKeys.ViewBox].AsString); } [Fact] - public async Task Should_not_throw_exception_if_svg_is_not_malicious() + public void Should_describe_metadata() { - var bytes = Encoding.UTF8.GetBytes(Resources.SvgValid); + var source = CreateAsset() with + { + Metadata = new AssetMetadata + { + [KnownMetadataKeys.PixelWidth] = "128", + [KnownMetadataKeys.PixelHeight] = "55" + }, + MimeType = "image/svg+xml" + }; + + var formatted = sut.Format(source); + + Assert.Equal(new[] { "128x55" }, formatted); + } - stream.Write(bytes); - stream.Seek(0, SeekOrigin.Begin); + private static UploadAssetCommand Command(string path) + { + var file = new FileInfo(Path.Combine("Assets", "TestFiles", path)); - var svg = new DelegateAssetFile("MyImage.svg", "other", 1024, () => stream); + return new CreateAsset + { + File = new DelegateAssetFile(file.Name, "mime", file.Length, file.OpenRead) + }; + } - var command = new CreateAsset { File = svg }; + private static UploadAssetCommand FakeCommand(string name) + { + var stream = new MemoryStream(); - await sut.EnhanceAsync(command, default); + return new CreateAsset + { + File = new DelegateAssetFile(name, "mime", stream.Length, () => stream) + }; } } diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/TestFiles/SvgInvalid.svg b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/TestFiles/SvgInvalid.svg new file mode 100644 index 000000000..8d5ab0b6b --- /dev/null +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/TestFiles/SvgInvalid.svg @@ -0,0 +1,5 @@ + + + + 410 + \ No newline at end of file diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/TestFiles/SvgValid.svg b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/TestFiles/SvgValid.svg new file mode 100644 index 000000000..2cdc45489 --- /dev/null +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/TestFiles/SvgValid.svg @@ -0,0 +1,6 @@ + + + + 410 + + \ No newline at end of file diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/TestAsset.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/TestAsset.cs index 6c257d873..de9fd1414 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/TestAsset.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/TestAsset.cs @@ -76,10 +76,11 @@ public static class TestAsset MimeType = "image/png", Type = AssetType.Image, MetadataText = "metadata-text", - Metadata = - new AssetMetadata() - .SetPixelWidth(800) - .SetPixelHeight(600), + Metadata =new AssetMetadata + { + [KnownMetadataKeys.PixelWidth] = 800, + [KnownMetadataKeys.PixelHeight] = 600, + }, TagNames = new[] { "tag1", @@ -123,8 +124,8 @@ public static class TestAsset fileVersion = asset.FileVersion, isImage = true, isProtected = asset.IsProtected, - pixelWidth = asset.Metadata.GetPixelWidth(), - pixelHeight = asset.Metadata.GetPixelHeight(), + pixelWidth = asset.Metadata.GetInt32(KnownMetadataKeys.PixelWidth), + pixelHeight = asset.Metadata.GetInt32(KnownMetadataKeys.PixelHeight), parentId = asset.Id, tags = asset.TagNames, type = "IMAGE", @@ -133,8 +134,8 @@ public static class TestAsset metadataUnknown = (string?)null, metadata = new { - pixelWidth = asset.Metadata.GetPixelWidth(), - pixelHeight = asset.Metadata.GetPixelHeight() + pixelWidth = asset.Metadata.GetInt32(KnownMetadataKeys.PixelWidth), + pixelHeight = asset.Metadata.GetInt32(KnownMetadataKeys.PixelHeight) }, slug = asset.Slug }; diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Properties/Resources.Designer.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Properties/Resources.Designer.cs deleted file mode 100644 index 0fcda2945..000000000 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Properties/Resources.Designer.cs +++ /dev/null @@ -1,90 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace Squidex.Domain.Apps.Entities.Properties { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Squidex.Domain.Apps.Entities.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized string similar to <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" onload="alert(localStorage.getItem('oidc.user:https://cloud.squidex.io/identity-server/:squidex-frontend'))"> - /// <path d="M30,1h40l29,29v40l-29,29h-40l-29-29v-40z" stroke="#000" fill="none"/> - /// <path d="M31,3h38l28,28v38l-28,28h-38l-28-28v-38z" fill="#a23"/> - /// <text x="50" y="68" font-size="48" fill="#FFF" text-anchor="middle"><![CDATA[410]]></text> - ///</svg>. - /// - internal static string SvgInvalid { - get { - return ResourceManager.GetString("SvgInvalid", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"> - /// <path d="M30,1h40l29,29v40l-29,29h-40l-29-29v-40z" stroke="#000" fill="none"/> - /// <path d="M31,3h38l28,28v38l-28,28h-38l-28-28v-38z" fill="#a23"/> - /// <text x="50" y="68" font-size="48" fill="#FFF" text-anchor="middle"><![CDATA[410]]></text> - /// <use id="#other"/> - ///</svg>. - /// - internal static string SvgValid { - get { - return ResourceManager.GetString("SvgValid", resourceCulture); - } - } - } -} diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Properties/Resources.resx b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Properties/Resources.resx deleted file mode 100644 index ca1e8db98..000000000 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Properties/Resources.resx +++ /dev/null @@ -1,135 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" onload="alert(localStorage.getItem('oidc.user:https://cloud.squidex.io/identity-server/:squidex-frontend'))"> - <path d="M30,1h40l29,29v40l-29,29h-40l-29-29v-40z" stroke="#000" fill="none"/> - <path d="M31,3h38l28,28v38l-28,28h-38l-28-28v-38z" fill="#a23"/> - <text x="50" y="68" font-size="48" fill="#FFF" text-anchor="middle"><![CDATA[410]]></text> -</svg> - - - <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"> - <path d="M30,1h40l29,29v40l-29,29h-40l-29-29v-40z" stroke="#000" fill="none"/> - <path d="M31,3h38l28,28v38l-28,28h-38l-28-28v-38z" fill="#a23"/> - <text x="50" y="68" font-size="48" fill="#FFF" text-anchor="middle"><![CDATA[410]]></text> - <use id="#other"/> -</svg> - - \ No newline at end of file diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Squidex.Domain.Apps.Entities.Tests.csproj b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Squidex.Domain.Apps.Entities.Tests.csproj index 1562afd8d..7f8207324 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Squidex.Domain.Apps.Entities.Tests.csproj +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Squidex.Domain.Apps.Entities.Tests.csproj @@ -27,7 +27,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -54,19 +54,6 @@ - - - True - True - Resources.resx - - - - - ResXFileCodeGenerator - Resources.Designer.cs - - PreserveNewest @@ -77,5 +64,11 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + \ No newline at end of file diff --git a/backend/tests/Squidex.Domain.Users.Tests/Squidex.Domain.Users.Tests.csproj b/backend/tests/Squidex.Domain.Users.Tests/Squidex.Domain.Users.Tests.csproj index 7648e1b6a..00edd3e24 100644 --- a/backend/tests/Squidex.Domain.Users.Tests/Squidex.Domain.Users.Tests.csproj +++ b/backend/tests/Squidex.Domain.Users.Tests/Squidex.Domain.Users.Tests.csproj @@ -16,7 +16,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/backend/tests/Squidex.Infrastructure.Tests/Squidex.Infrastructure.Tests.csproj b/backend/tests/Squidex.Infrastructure.Tests/Squidex.Infrastructure.Tests.csproj index e52febda4..905a2660e 100644 --- a/backend/tests/Squidex.Infrastructure.Tests/Squidex.Infrastructure.Tests.csproj +++ b/backend/tests/Squidex.Infrastructure.Tests/Squidex.Infrastructure.Tests.csproj @@ -16,7 +16,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/backend/tests/Squidex.Web.Tests/Squidex.Web.Tests.csproj b/backend/tests/Squidex.Web.Tests/Squidex.Web.Tests.csproj index 7de6b220c..f77956452 100644 --- a/backend/tests/Squidex.Web.Tests/Squidex.Web.Tests.csproj +++ b/backend/tests/Squidex.Web.Tests/Squidex.Web.Tests.csproj @@ -16,7 +16,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/tools/TestSuite/TestSuite.ApiTests/AnonymousTests.cs b/tools/TestSuite/TestSuite.ApiTests/AnonymousTests.cs index 893ecd6b4..44229be7a 100644 --- a/tools/TestSuite/TestSuite.ApiTests/AnonymousTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/AnonymousTests.cs @@ -14,7 +14,6 @@ using TestSuite.Fixtures; namespace TestSuite.ApiTests; -[UsesVerify] public class AnonymousTests : IClassFixture { private readonly string appName = Guid.NewGuid().ToString(); diff --git a/tools/TestSuite/TestSuite.ApiTests/AppClientsTests.cs b/tools/TestSuite/TestSuite.ApiTests/AppClientsTests.cs index f0fd0b015..17f7d4a38 100644 --- a/tools/TestSuite/TestSuite.ApiTests/AppClientsTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/AppClientsTests.cs @@ -13,7 +13,6 @@ using TestSuite.Fixtures; namespace TestSuite.ApiTests; -[UsesVerify] public sealed class AppClientsTests : IClassFixture { private readonly string id = Guid.NewGuid().ToString(); diff --git a/tools/TestSuite/TestSuite.ApiTests/AppContributorsTests.cs b/tools/TestSuite/TestSuite.ApiTests/AppContributorsTests.cs index a879434fe..9f14cb6b5 100644 --- a/tools/TestSuite/TestSuite.ApiTests/AppContributorsTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/AppContributorsTests.cs @@ -13,7 +13,6 @@ using TestSuite.Fixtures; namespace TestSuite.ApiTests; -[UsesVerify] public sealed class AppContributorsTests : IClassFixture { public ClientFixture _ { get; } diff --git a/tools/TestSuite/TestSuite.ApiTests/AppCreationTests.cs b/tools/TestSuite/TestSuite.ApiTests/AppCreationTests.cs index 588ae487f..7d0bfd85f 100644 --- a/tools/TestSuite/TestSuite.ApiTests/AppCreationTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/AppCreationTests.cs @@ -13,7 +13,6 @@ using TestSuite.Fixtures; namespace TestSuite.ApiTests; -[UsesVerify] public class AppCreationTests : IClassFixture { private readonly string appName = Guid.NewGuid().ToString(); diff --git a/tools/TestSuite/TestSuite.ApiTests/AppLanguagesTests.cs b/tools/TestSuite/TestSuite.ApiTests/AppLanguagesTests.cs index e6b2c34b1..dcf31cac7 100644 --- a/tools/TestSuite/TestSuite.ApiTests/AppLanguagesTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/AppLanguagesTests.cs @@ -13,7 +13,6 @@ using TestSuite.Fixtures; namespace TestSuite.ApiTests; -[UsesVerify] public sealed class AppLanguagesTests : IClassFixture { public ClientFixture _ { get; } diff --git a/tools/TestSuite/TestSuite.ApiTests/AppRolesTests.cs b/tools/TestSuite/TestSuite.ApiTests/AppRolesTests.cs index 111927b85..dc9f9b21a 100644 --- a/tools/TestSuite/TestSuite.ApiTests/AppRolesTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/AppRolesTests.cs @@ -13,7 +13,6 @@ using TestSuite.Fixtures; namespace TestSuite.ApiTests; -[UsesVerify] public sealed class AppRolesTests : IClassFixture { private readonly string roleName = Guid.NewGuid().ToString(); diff --git a/tools/TestSuite/TestSuite.ApiTests/AppTests.cs b/tools/TestSuite/TestSuite.ApiTests/AppTests.cs index 096c54424..3cafb5254 100644 --- a/tools/TestSuite/TestSuite.ApiTests/AppTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/AppTests.cs @@ -13,7 +13,6 @@ using TestSuite.Fixtures; namespace TestSuite.ApiTests; -[UsesVerify] public sealed class AppTests : IClassFixture { public CreatedAppFixture _ { get; } diff --git a/tools/TestSuite/TestSuite.ApiTests/AppWorkflowsTests.cs b/tools/TestSuite/TestSuite.ApiTests/AppWorkflowsTests.cs index a52df447c..6d2825480 100644 --- a/tools/TestSuite/TestSuite.ApiTests/AppWorkflowsTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/AppWorkflowsTests.cs @@ -13,7 +13,6 @@ using TestSuite.Fixtures; namespace TestSuite.ApiTests; -[UsesVerify] public sealed class AppWorkflowsTests : IClassFixture { private readonly string workflowName = Guid.NewGuid().ToString(); diff --git a/tools/TestSuite/TestSuite.ApiTests/AssetFoldersTests.cs b/tools/TestSuite/TestSuite.ApiTests/AssetFoldersTests.cs index 5ee8b0cc6..b52bca1f9 100644 --- a/tools/TestSuite/TestSuite.ApiTests/AssetFoldersTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/AssetFoldersTests.cs @@ -13,7 +13,6 @@ using TestSuite.Fixtures; namespace TestSuite.ApiTests; -[UsesVerify] public class AssetFoldersTests : IClassFixture { public CreatedAppFixture _ { get; } diff --git a/tools/TestSuite/TestSuite.ApiTests/AssetFormatTests.cs b/tools/TestSuite/TestSuite.ApiTests/AssetFormatTests.cs index 3923257fa..fe6fc13ce 100644 --- a/tools/TestSuite/TestSuite.ApiTests/AssetFormatTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/AssetFormatTests.cs @@ -13,7 +13,6 @@ using TestSuite.Fixtures; namespace TestSuite.ApiTests; -[UsesVerify] public class AssetFormatTests : IClassFixture { public CreatedAppFixture _ { get; } diff --git a/tools/TestSuite/TestSuite.ApiTests/AssetTests.cs b/tools/TestSuite/TestSuite.ApiTests/AssetTests.cs index e49ad2369..4a6004155 100644 --- a/tools/TestSuite/TestSuite.ApiTests/AssetTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/AssetTests.cs @@ -15,7 +15,6 @@ using TestSuite.Utils; namespace TestSuite.ApiTests; -[UsesVerify] public class AssetTests : IClassFixture { private ProgressHandler progress = new ProgressHandler(); diff --git a/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs b/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs index 3c7f05985..e5eb641a4 100644 --- a/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs @@ -16,7 +16,6 @@ using TestSuite.Model; namespace TestSuite.ApiTests; -[UsesVerify] public class ContentUpdateTests : IClassFixture { public ContentFixture _ { get; } diff --git a/tools/TestSuite/TestSuite.ApiTests/RuleTests.cs b/tools/TestSuite/TestSuite.ApiTests/RuleTests.cs index e4eb2c3d8..e1321ef02 100644 --- a/tools/TestSuite/TestSuite.ApiTests/RuleTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/RuleTests.cs @@ -13,7 +13,6 @@ using TestSuite.Fixtures; namespace TestSuite.ApiTests; -[UsesVerify] public class RuleTests : IClassFixture { private readonly string ruleName = Guid.NewGuid().ToString(); diff --git a/tools/TestSuite/TestSuite.ApiTests/SchemaTests.cs b/tools/TestSuite/TestSuite.ApiTests/SchemaTests.cs index 2f3c27efb..b18477797 100644 --- a/tools/TestSuite/TestSuite.ApiTests/SchemaTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/SchemaTests.cs @@ -14,7 +14,6 @@ using TestSuite.Fixtures; namespace TestSuite.ApiTests; -[UsesVerify] public class SchemaTests : IClassFixture { private readonly string schemaName = $"schema-{Guid.NewGuid()}"; diff --git a/tools/TestSuite/TestSuite.ApiTests/TeamContributorTests.cs b/tools/TestSuite/TestSuite.ApiTests/TeamContributorTests.cs index e1321f78e..a1c1c0392 100644 --- a/tools/TestSuite/TestSuite.ApiTests/TeamContributorTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/TeamContributorTests.cs @@ -13,7 +13,6 @@ using TestSuite.Fixtures; namespace TestSuite.ApiTests; -[UsesVerify] public class TeamContributorTests : IClassFixture { public ClientFixture _ { get; } diff --git a/tools/TestSuite/TestSuite.ApiTests/TeamTests.cs b/tools/TestSuite/TestSuite.ApiTests/TeamTests.cs index 5fc3e20af..1a0ed06ec 100644 --- a/tools/TestSuite/TestSuite.ApiTests/TeamTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/TeamTests.cs @@ -13,7 +13,6 @@ using TestSuite.Fixtures; namespace TestSuite.ApiTests; -[UsesVerify] public class TeamTests : IClassFixture { public CreatedTeamFixture _ { get; } diff --git a/tools/TestSuite/TestSuite.ApiTests/TestSuite.ApiTests.csproj b/tools/TestSuite/TestSuite.ApiTests/TestSuite.ApiTests.csproj index 84c63b3c7..c50c3cebd 100644 --- a/tools/TestSuite/TestSuite.ApiTests/TestSuite.ApiTests.csproj +++ b/tools/TestSuite/TestSuite.ApiTests/TestSuite.ApiTests.csproj @@ -7,21 +7,21 @@ enable - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + - - + + all runtime; build; native; contentfiles; analyzers diff --git a/tools/TestSuite/TestSuite.LoadTests/TestSuite.LoadTests.csproj b/tools/TestSuite/TestSuite.LoadTests/TestSuite.LoadTests.csproj index 412659eff..b4a0486ea 100644 --- a/tools/TestSuite/TestSuite.LoadTests/TestSuite.LoadTests.csproj +++ b/tools/TestSuite/TestSuite.LoadTests/TestSuite.LoadTests.csproj @@ -7,13 +7,13 @@ enable - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers diff --git a/tools/TestSuite/TestSuite.Shared/TestSuite.Shared.csproj b/tools/TestSuite/TestSuite.Shared/TestSuite.Shared.csproj index 98df56bdb..86e2cb337 100644 --- a/tools/TestSuite/TestSuite.Shared/TestSuite.Shared.csproj +++ b/tools/TestSuite/TestSuite.Shared/TestSuite.Shared.csproj @@ -7,7 +7,7 @@ enable - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -17,12 +17,12 @@ - - - + + + - - + +