Skip to content

Commit 04f2300

Browse files
committed
Merge branch 'release/3.209.0'
2 parents 903859a + 6da55a4 commit 04f2300

File tree

3 files changed

+52
-14
lines changed

3 files changed

+52
-14
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?><Project>
22
<!-- These properties will be shared for all projects -->
33
<PropertyGroup>
4-
<VersionPrefix>3.208.0</VersionPrefix>
4+
<VersionPrefix>3.209.0</VersionPrefix>
55
<VersionSuffix>
66
</VersionSuffix>
77
<VersionSuffix Condition=" '$(VersionSuffix)' != '' AND '$(BuildNumber)' != '' ">$(VersionSuffix)-$(BuildNumber)</VersionSuffix>

src/VirtoCommerce.AzureBlobAssetsModule.Core/AzureBlobProvider.cs

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ public virtual Stream OpenWrite(string blobUrl)
112112

113113
public virtual async Task<Stream> OpenWriteAsync(string blobUrl)
114114
{
115+
if (string.IsNullOrEmpty(blobUrl))
116+
{
117+
throw new ArgumentNullException(nameof(blobUrl));
118+
}
119+
120+
// Normilize Url if blobUrl has wrong encoded, like contains space
121+
blobUrl = NormalizeUrl(blobUrl);
122+
115123
var filePath = GetFilePathFromUrl(blobUrl);
116124
var fileName = Path.GetFileName(filePath);
117125

@@ -149,12 +157,24 @@ public virtual async Task<Stream> OpenWriteAsync(string blobUrl)
149157
return new FlushLessStream(await blob.OpenWriteAsync(true, options));
150158
}
151159

160+
protected static string NormalizeUrl(string blobUrl)
161+
{
162+
try
163+
{
164+
return (new Uri(blobUrl)).AbsoluteUri;
165+
}
166+
catch (Exception)
167+
{
168+
return blobUrl;
169+
}
170+
}
171+
152172
public virtual async Task RemoveAsync(string[] urls)
153173
{
154174
foreach (var url in urls.Where(x => !string.IsNullOrWhiteSpace(x)))
155175
{
156176
var absoluteUri = url.IsAbsoluteUrl()
157-
? new Uri(url).ToString()
177+
? url
158178
: UrlHelperExtensions.Combine(_blobServiceClient.Uri.ToString(), url);
159179
var blobContainer = GetBlobContainer(GetContainerNameFromUrl(absoluteUri));
160180

@@ -217,11 +237,15 @@ public virtual async Task<BlobEntrySearchResult> SearchAsync(string folderUrl, s
217237
.Split(new[] { Delimiter }, StringSplitOptions.RemoveEmptyEntries)
218238
.Last();
219239

220-
folder.Url = UrlHelperExtensions.Combine(baseUriEscaped, EscapeUri(blobhierarchyItem.Prefix));
240+
var folderUrlBuilder = new UriBuilder(new Uri(baseUriEscaped));
241+
folderUrlBuilder.Path += Delimiter + blobhierarchyItem.Prefix;
242+
folder.Url = folderUrlBuilder.ToString();
221243
folder.ParentUrl = GetParentUrl(baseUriEscaped, blobhierarchyItem.Prefix);
222244
folder.RelativeUrl = folder.Url.Replace(EscapeUri(_blobServiceClient.Uri.ToString()), string.Empty);
245+
223246
folder.CreatedDate = containerProperties.Value.LastModified.UtcDateTime;
224247
folder.ModifiedDate = containerProperties.Value.LastModified.UtcDateTime;
248+
225249
result.Results.Add(folder);
226250
}
227251
else
@@ -248,7 +272,11 @@ public virtual async Task<BlobEntrySearchResult> SearchAsync(string folderUrl, s
248272
{
249273
var folder = AbstractTypeFactory<BlobFolder>.TryCreateInstance();
250274
folder.Name = item.Name.Split(Delimiter).Last();
251-
folder.Url = EscapeUri(UrlHelperExtensions.Combine(_blobServiceClient.Uri.ToString(), item.Name));
275+
276+
var folderUrlBuilder = new UriBuilder(_blobServiceClient.Uri);
277+
folderUrlBuilder.Path += item.Name + Delimiter;
278+
folder.Url = folderUrlBuilder.ToString();
279+
252280
result.Results.Add(folder);
253281
}
254282
}
@@ -260,15 +288,20 @@ public virtual async Task<BlobEntrySearchResult> SearchAsync(string folderUrl, s
260288

261289
public virtual async Task CreateFolderAsync(BlobFolder folder)
262290
{
263-
var path = folder.ParentUrl == null ?
264-
folder.Name :
265-
UrlHelperExtensions.Combine(folder.ParentUrl, folder.Name);
291+
var newFolderUrl = folder.Name;
266292

267-
var containerName = GetContainerNameFromUrl(path);
293+
if (folder.ParentUrl != null)
294+
{
295+
var newFolderUriBuilder = new UriBuilder(new Uri(folder.ParentUrl));
296+
newFolderUriBuilder.Path += Delimiter + folder.Name;
297+
newFolderUrl = newFolderUriBuilder.ToString();
298+
}
299+
300+
var containerName = GetContainerNameFromUrl(newFolderUrl);
268301
var container = _blobServiceClient.GetBlobContainerClient(containerName);
269302
await container.CreateIfNotExistsAsync(PublicAccessType.Blob);
270303

271-
var directoryPath = GetDirectoryPathFromUrl(path);
304+
var directoryPath = GetDirectoryPathFromUrl(newFolderUrl);
272305
if (!string.IsNullOrEmpty(directoryPath))
273306
{
274307
// Need to upload an empty '.keep' blob because Azure Blob Storage does not support direct directory creation
@@ -406,6 +439,7 @@ public virtual string GetAbsoluteUrl(string blobKey)
406439
private string[] GetOutlineFromUrl(string url)
407440
{
408441
var relativeUrl = url;
442+
409443
if (url.IsAbsoluteUrl())
410444
{
411445
relativeUrl = Uri.UnescapeDataString(new Uri(url).AbsolutePath);
@@ -423,13 +457,13 @@ private string GetContainerNameFromUrl(string url)
423457
private string GetDirectoryPathFromUrl(string url)
424458
{
425459
var result = string.Join(Delimiter, GetOutlineFromUrl(url).Skip(1).ToArray());
426-
return !string.IsNullOrEmpty(result) ? result + Delimiter : null;
460+
return !string.IsNullOrEmpty(result) ? Uri.UnescapeDataString(result) + Delimiter : null;
427461
}
428462

429463
private string GetFilePathFromUrl(string url)
430464
{
431465
var result = string.Join(Delimiter, GetOutlineFromUrl(url).Skip(1).ToArray());
432-
return !string.IsNullOrEmpty(result) ? result : null;
466+
return !string.IsNullOrEmpty(result) ? Uri.UnescapeDataString(result) : null;
433467
}
434468

435469
private string GetParentUrl(string baseUri, string blobPrefix)
@@ -483,9 +517,13 @@ private BlobInfo ConvertBlobToBlobInfo(BlobClient blob, BlobProperties props)
483517

484518
private BlobInfo ConvertBlobToBlobInfo(BlobItem blob, string baseUri)
485519
{
486-
var fileName = Path.GetFileName(blob.Name);
487-
var absoluteUrl = UrlHelperExtensions.Combine(baseUri, EscapeUri(blob.Name));
520+
var fileUrlBuilder = new UriBuilder(new Uri(baseUri));
521+
fileUrlBuilder.Path = fileUrlBuilder.Path + "/" + blob.Name;
522+
var absoluteUrl = fileUrlBuilder.ToString();
523+
488524
var relativeUrl = absoluteUrl.Replace(EscapeUri(_blobServiceClient.Uri.ToString()), string.Empty);
525+
526+
var fileName = Path.GetFileName(blob.Name);
489527
var contentType = MimeTypeResolver.ResolveContentType(fileName);
490528

491529
return new BlobInfo

src/VirtoCommerce.AzureBlobAssetsModule.Web/module.manifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<module xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
33
<id>VirtoCommerce.AzureBlobAssets</id>
4-
<version>3.208.0</version>
4+
<version>3.209.0</version>
55
<version-tag />
66
<platformVersion>3.200.0</platformVersion>
77
<title>Azure blob assets module</title>

0 commit comments

Comments
 (0)