Browse Source

Asset versioning fixed. Closes #92

pull/95/head
Sebastian Stehle 8 years ago
parent
commit
36edf07a5f
  1. 2
      src/Squidex.Domain.Apps.Write/Assets/AssetCommandHandler.cs
  2. 23
      src/Squidex.Domain.Apps.Write/Assets/AssetSavedResult.cs
  3. 3
      src/Squidex/Controllers/Api/Assets/AssetsController.cs
  4. 6
      src/Squidex/Controllers/Api/Assets/Models/AssetReplacedDto.cs
  5. 6
      src/Squidex/app/shared/components/pipes.ts

2
src/Squidex.Domain.Apps.Write/Assets/AssetCommandHandler.cs

@ -69,6 +69,8 @@ namespace Squidex.Domain.Apps.Write.Assets
a.Update(command);
await assetStore.UploadTemporaryAsync(context.ContextId.ToString(), command.File.OpenRead());
context.Complete(new AssetSavedResult(a.Version, a.FileVersion));
});
await assetStore.CopyTemporaryAsync(context.ContextId.ToString(), asset.Id.ToString(), asset.FileVersion, null);

23
src/Squidex.Domain.Apps.Write/Assets/AssetSavedResult.cs

@ -0,0 +1,23 @@
// ==========================================================================
// AssetSavedResult.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using Squidex.Infrastructure.CQRS.Commands;
namespace Squidex.Domain.Apps.Write.Assets
{
public class AssetSavedResult : EntitySavedResult
{
public long FileVersion { get; }
public AssetSavedResult(long version, long fileVersion)
: base(version)
{
FileVersion = fileVersion;
}
}
}

3
src/Squidex/Controllers/Api/Assets/AssetsController.cs

@ -18,6 +18,7 @@ using NSwag.Annotations;
using Squidex.Controllers.Api.Assets.Models;
using Squidex.Domain.Apps.Read.Apps.Services;
using Squidex.Domain.Apps.Read.Assets.Repositories;
using Squidex.Domain.Apps.Write.Assets;
using Squidex.Domain.Apps.Write.Assets.Commands;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Assets;
@ -201,7 +202,7 @@ namespace Squidex.Controllers.Api.Assets
var command = new UpdateAsset { File = assetFile, AssetId = id };
var context = await CommandBus.PublishAsync(command);
var result = context.Result<EntitySavedResult>();
var result = context.Result<AssetSavedResult>();
var response = AssetReplacedDto.Create(command, result);
return StatusCode(201, response);

6
src/Squidex/Controllers/Api/Assets/Models/AssetReplacedDto.cs

@ -7,8 +7,8 @@
// ==========================================================================
using System.ComponentModel.DataAnnotations;
using Squidex.Domain.Apps.Write.Assets;
using Squidex.Domain.Apps.Write.Assets.Commands;
using Squidex.Infrastructure.CQRS.Commands;
namespace Squidex.Controllers.Api.Assets.Models
{
@ -50,12 +50,12 @@ namespace Squidex.Controllers.Api.Assets.Models
/// </summary>
public long Version { get; set; }
public static AssetReplacedDto Create(UpdateAsset command, EntitySavedResult result)
public static AssetReplacedDto Create(UpdateAsset command, AssetSavedResult result)
{
var response = new AssetReplacedDto
{
FileSize = command.File.FileSize,
FileVersion = result.Version,
FileVersion = result.FileVersion,
MimeType = command.File.MimeType,
IsImage = command.ImageInfo != null,
PixelWidth = command.ImageInfo?.PixelWidth,

6
src/Squidex/app/shared/components/pipes.ts

@ -8,7 +8,7 @@
import { ChangeDetectorRef, OnDestroy, Pipe, PipeTransform } from '@angular/core';
import { Observable, Subscription } from 'rxjs';
import { ApiUrlConfig, MathHelper, Version } from 'framework';
import { ApiUrlConfig, MathHelper } from 'framework';
import { UserDto, UsersProviderService } from './../declarations-base';
@ -219,8 +219,8 @@ export class AssetPreviewUrlPipe implements PipeTransform {
) {
}
public transform(asset: { id: any, version: Version }): string {
return this.apiUrl.buildUrl(`api/assets/${asset.id}?version=${asset.version.value}`);
public transform(asset: { id: any, fileVersion: number }): string {
return this.apiUrl.buildUrl(`api/assets/${asset.id}?version=${asset.fileVersion}`);
}
}

Loading…
Cancel
Save