Browse Source

Fix asset public url.

pull/342/head
Sebastian Stehle 8 years ago
parent
commit
d74bd78273
  1. 17
      src/Squidex.Infrastructure.Azure/Assets/AzureBlobAssetStore.cs
  2. 6
      src/Squidex.Infrastructure.GoogleCloud/Assets/GoogleCloudAssetStore.cs
  3. 4
      src/Squidex.Infrastructure.MongoDb/Assets/MongoGridFsAssetStore.cs
  4. 6
      src/Squidex.Infrastructure/Assets/FolderAssetStore.cs
  5. 2
      src/Squidex.Infrastructure/Assets/IAssetStore.cs
  6. 1
      src/Squidex/Areas/Api/Controllers/Backups/BackupContentController.cs
  7. 2
      src/Squidex/Pipeline/UrlGenerator.cs
  8. 4
      tests/Squidex.Infrastructure.Tests/Assets/AzureBlobAssetStoreTests.cs
  9. 4
      tests/Squidex.Infrastructure.Tests/Assets/FolderAssetStoreTests.cs
  10. 4
      tests/Squidex.Infrastructure.Tests/Assets/GoogleCloudAssetStoreTests.cs
  11. 4
      tests/Squidex.Infrastructure.Tests/Assets/MongoGridFsAssetStoreTests.cs

17
src/Squidex.Infrastructure.Azure/Assets/AzureBlobAssetStore.cs

@ -48,11 +48,17 @@ namespace Squidex.Infrastructure.Assets
} }
} }
public string GenerateSourceUrl(string id, long version, string suffix) public string GeneratePublicUrl(string id, long version, string suffix)
{ {
var blobName = GetObjectName(id, version, suffix); if (blobContainer.Properties.PublicAccess != BlobContainerPublicAccessType.Blob)
{
var sourceName = GetObjectName(id, version, suffix);
var sourceBlob = blobContainer.GetBlockBlobReference(sourceName);
return sourceBlob.Uri.ToString();
}
return new Uri(blobContainer.StorageUri.PrimaryUri, $"/{containerName}/{blobName}").ToString(); return null;
} }
public async Task CopyAsync(string sourceFileName, string id, long version, string suffix, CancellationToken ct = default(CancellationToken)) public async Task CopyAsync(string sourceFileName, string id, long version, string suffix, CancellationToken ct = default(CancellationToken))
@ -91,11 +97,12 @@ namespace Squidex.Infrastructure.Assets
public async Task DownloadAsync(string id, long version, string suffix, Stream stream, CancellationToken ct = default(CancellationToken)) public async Task DownloadAsync(string id, long version, string suffix, Stream stream, CancellationToken ct = default(CancellationToken))
{ {
var blob = blobContainer.GetBlockBlobReference(GetObjectName(id, version, suffix)); var sourceName = GetObjectName(id, version, suffix);
var sourceBlob = blobContainer.GetBlockBlobReference(sourceName);
try try
{ {
await blob.DownloadToStreamAsync(stream, null, null, null, ct); await sourceBlob.DownloadToStreamAsync(stream, null, null, null, ct);
} }
catch (StorageException ex) when (ex.RequestInformation.HttpStatusCode == 404) catch (StorageException ex) when (ex.RequestInformation.HttpStatusCode == 404)
{ {

6
src/Squidex.Infrastructure.GoogleCloud/Assets/GoogleCloudAssetStore.cs

@ -44,11 +44,9 @@ namespace Squidex.Infrastructure.Assets
} }
} }
public string GenerateSourceUrl(string id, long version, string suffix) public string GeneratePublicUrl(string id, long version, string suffix)
{ {
var objectName = GetObjectName(id, version, suffix); return null;
return $"https://storage.cloud.google.com/{bucketName}/{objectName}";
} }
public async Task CopyAsync(string sourceFileName, string id, long version, string suffix, CancellationToken ct = default(CancellationToken)) public async Task CopyAsync(string sourceFileName, string id, long version, string suffix, CancellationToken ct = default(CancellationToken))

4
src/Squidex.Infrastructure.MongoDb/Assets/MongoGridFsAssetStore.cs

@ -39,9 +39,9 @@ namespace Squidex.Infrastructure.Assets
} }
} }
public string GenerateSourceUrl(string id, long version, string suffix) public string GeneratePublicUrl(string id, long version, string suffix)
{ {
return "UNSUPPORTED"; return null;
} }
public async Task CopyAsync(string sourceFileName, string id, long version, string suffix, CancellationToken ct = default(CancellationToken)) public async Task CopyAsync(string sourceFileName, string id, long version, string suffix, CancellationToken ct = default(CancellationToken))

6
src/Squidex.Infrastructure/Assets/FolderAssetStore.cs

@ -52,11 +52,9 @@ namespace Squidex.Infrastructure.Assets
} }
} }
public string GenerateSourceUrl(string id, long version, string suffix) public string GeneratePublicUrl(string id, long version, string suffix)
{ {
var file = GetFile(id, version, suffix); return null;
return file.FullName;
} }
public async Task DownloadAsync(string id, long version, string suffix, Stream stream, CancellationToken ct = default(CancellationToken)) public async Task DownloadAsync(string id, long version, string suffix, Stream stream, CancellationToken ct = default(CancellationToken))

2
src/Squidex.Infrastructure/Assets/IAssetStore.cs

@ -13,7 +13,7 @@ namespace Squidex.Infrastructure.Assets
{ {
public interface IAssetStore public interface IAssetStore
{ {
string GenerateSourceUrl(string id, long version, string suffix); string GeneratePublicUrl(string id, long version, string suffix);
Task CopyAsync(string sourceFileName, string id, long version, string suffix, CancellationToken ct = default(CancellationToken)); Task CopyAsync(string sourceFileName, string id, long version, string suffix, CancellationToken ct = default(CancellationToken));

1
src/Squidex/Areas/Api/Controllers/Backups/BackupContentController.cs

@ -39,6 +39,7 @@ namespace Squidex.Areas.Api.Controllers.Backups
/// </returns> /// </returns>
[HttpGet] [HttpGet]
[Route("apps/{app}/backups/{id}")] [Route("apps/{app}/backups/{id}")]
[ResponseCache(Duration = 3600 * 24 * 30)]
[ProducesResponseType(200)] [ProducesResponseType(200)]
[ApiCosts(0)] [ApiCosts(0)]
[AllowAnonymous] [AllowAnonymous]

2
src/Squidex/Pipeline/UrlGenerator.cs

@ -67,7 +67,7 @@ namespace Squidex.Pipeline
public string GenerateAssetSourceUrl(IAppEntity app, IAssetEntity asset) public string GenerateAssetSourceUrl(IAppEntity app, IAssetEntity asset)
{ {
return assetStore.GenerateSourceUrl(asset.Id.ToString(), asset.FileVersion, null); return assetStore.GeneratePublicUrl(asset.Id.ToString(), asset.FileVersion, null);
} }
} }
} }

4
tests/Squidex.Infrastructure.Tests/Assets/AzureBlobAssetStoreTests.cs

@ -25,9 +25,9 @@ namespace Squidex.Infrastructure.Assets
[Fact] [Fact]
public void Should_calculate_source_url() public void Should_calculate_source_url()
{ {
var url = Sut.GenerateSourceUrl(AssetId, 1, null); var url = Sut.GeneratePublicUrl(AssetId, 1, null);
Assert.Equal($"http://127.0.0.1:10000/squidex-test-container/{AssetId}_1", url); Assert.Equal($"http://127.0.0.1:10000/devstoreaccount1/squidex-test-container/{AssetId}_1", url);
} }
} }
} }

4
tests/Squidex.Infrastructure.Tests/Assets/FolderAssetStoreTests.cs

@ -45,9 +45,9 @@ namespace Squidex.Infrastructure.Assets
[Fact] [Fact]
public void Should_calculate_source_url() public void Should_calculate_source_url()
{ {
var url = Sut.GenerateSourceUrl(AssetId, 1, null); var url = Sut.GeneratePublicUrl(AssetId, 1, null);
Assert.Equal(Path.Combine(testFolder, $"{AssetId}_1"), url); Assert.Null(url);
} }
private static string CreateInvalidPath() private static string CreateInvalidPath()

4
tests/Squidex.Infrastructure.Tests/Assets/GoogleCloudAssetStoreTests.cs

@ -25,9 +25,9 @@ namespace Squidex.Infrastructure.Assets
[Fact] [Fact]
public void Should_calculate_source_url() public void Should_calculate_source_url()
{ {
var url = Sut.GenerateSourceUrl(AssetId, 1, null); var url = Sut.GeneratePublicUrl(AssetId, 1, null);
Assert.Equal($"https://storage.cloud.google.com/squidex-test/{AssetId}_1", url); Assert.Null(url);
} }
} }
} }

4
tests/Squidex.Infrastructure.Tests/Assets/MongoGridFsAssetStoreTests.cs

@ -40,7 +40,9 @@ namespace Squidex.Infrastructure.Assets
[Fact] [Fact]
public void Should_not_calculate_source_url() public void Should_not_calculate_source_url()
{ {
Assert.Equal("UNSUPPORTED", Sut.GenerateSourceUrl(AssetId, 1, null)); var url = Sut.GeneratePublicUrl(AssetId, 1, null);
Assert.Null(url);
} }
} }
} }
Loading…
Cancel
Save