|
|
@ -142,11 +142,39 @@ namespace Squidex.Areas.Api.Controllers.Assets |
|
|
{ |
|
|
{ |
|
|
var resizedAsset = $"{asset.Id}_{asset.FileVersion}_{resizeOptions}"; |
|
|
var resizedAsset = $"{asset.Id}_{asset.FileVersion}_{resizeOptions}"; |
|
|
|
|
|
|
|
|
|
|
|
if (query.ForceResize) |
|
|
|
|
|
{ |
|
|
|
|
|
await ResizeAsync(asset, bodyStream, resizedAsset, fileVersion, resizeOptions, true); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
await assetStore.DownloadAsync(resizedAsset, bodyStream); |
|
|
await assetStore.DownloadAsync(resizedAsset, bodyStream); |
|
|
} |
|
|
} |
|
|
catch (AssetNotFoundException) |
|
|
catch (AssetNotFoundException) |
|
|
|
|
|
{ |
|
|
|
|
|
await ResizeAsync(asset, bodyStream, resizedAsset, fileVersion, resizeOptions, false); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
await assetFileStore.DownloadAsync(asset.Id, fileVersion, bodyStream); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if (query.Download == 1 || asset.Type != AssetType.Image) |
|
|
|
|
|
{ |
|
|
|
|
|
return new FileCallbackResult(asset.MimeType, asset.FileName, true, handler); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
return new FileCallbackResult(asset.MimeType, null, true, handler); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private async Task ResizeAsync(IAssetEntity asset, Stream bodyStream, string fileName, long fileVersion, ResizeOptions resizeOptions, bool overwrite) |
|
|
{ |
|
|
{ |
|
|
using (Profiler.Trace("Resize")) |
|
|
using (Profiler.Trace("Resize")) |
|
|
{ |
|
|
{ |
|
|
@ -168,7 +196,7 @@ namespace Squidex.Areas.Api.Controllers.Assets |
|
|
|
|
|
|
|
|
using (Profiler.Trace("ResizeUpload")) |
|
|
using (Profiler.Trace("ResizeUpload")) |
|
|
{ |
|
|
{ |
|
|
await assetStore.UploadAsync(resizedAsset, destinationStream); |
|
|
await assetStore.UploadAsync(fileName, destinationStream, overwrite); |
|
|
destinationStream.Position = 0; |
|
|
destinationStream.Position = 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -177,22 +205,6 @@ namespace Squidex.Areas.Api.Controllers.Assets |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
await assetFileStore.DownloadAsync(asset.Id, fileVersion, bodyStream); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if (query.Download == 1 || asset.Type != AssetType.Image) |
|
|
|
|
|
{ |
|
|
|
|
|
return new FileCallbackResult(asset.MimeType, asset.FileName, true, handler); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
return new FileCallbackResult(asset.MimeType, null, true, handler); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static FileStream GetTempStream() |
|
|
private static FileStream GetTempStream() |
|
|
{ |
|
|
{ |
|
|
|