Skip to content

Commit 32fd060

Browse files
chore: update s3
1 parent 7445c27 commit 32fd060

3 files changed

Lines changed: 21 additions & 11 deletions

File tree

src/Application/Common/Behaviors/ProcessImagePathBehavior.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ private void UpdatePropertyIfNotPublicUrl(object target, PropertyInfo property,
106106
if (!imageKeyStr.StartsWith(storageService.PublicUrl))
107107
{
108108
string? fullPath = storageService.GetFullPath(imageKeyStr);
109-
logger.LogInformation("image path {value}", fullPath);
109+
string? publicPath = storageService.GetPublicPath(fullPath!);
110+
logger.LogInformation("image path {value}", publicPath);
110111
property.SetValue(target, fullPath);
111112
}
112113
}

src/Application/Common/Interfaces/Services/Storage/IStorageService.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ public interface IStorageService
1515

1616
Task<StorageResponse> DeleteAsync(string key);
1717

18-
string? GetFullPath(string? key);
18+
string? GetFullPath(string key);
19+
20+
string? GetPublicPath(string originalPath);
1921

2022
string UniqueFileName(string fileName);
2123
}

src/Infrastructure/Services/Aws/AmazonS3Service.cs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,21 @@ public string UniqueFileName(string fileName)
167167
return $"{name}.{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}{extension}";
168168
}
169169

170-
public string? GetFullPath(string? key) =>
171-
string.IsNullOrWhiteSpace(key) ? null : GeneratePreSignedURL(key);
170+
public string? GetFullPath(string key) => GeneratePreSignedURL(key);
171+
172+
public string? GetPublicPath(string originalPath)
173+
{
174+
if (string.IsNullOrWhiteSpace(originalPath))
175+
{
176+
return string.Empty;
177+
}
178+
179+
return originalPath.Replace(
180+
s3AwsSettings.ServiceUrl!,
181+
s3AwsSettings.PublicUrl,
182+
StringComparison.OrdinalIgnoreCase
183+
);
184+
}
172185

173186
private string GeneratePreSignedURL(string key)
174187
{
@@ -182,12 +195,6 @@ private string GeneratePreSignedURL(string key)
182195
Protocol = s3AwsSettings.Protocol,
183196
};
184197

185-
string url = amazonS3.GetPreSignedURL(request);
186-
187-
return url.Replace(
188-
s3AwsSettings.ServiceUrl!,
189-
s3AwsSettings.PublicUrl,
190-
StringComparison.OrdinalIgnoreCase
191-
);
198+
return amazonS3.GetPreSignedURL(request);
192199
}
193200
}

0 commit comments

Comments
 (0)