fix: standardize upload request path and handle null storage path in URL generation

This commit is contained in:
ShiYu
2025-05-20 00:04:14 +08:00
parent 1ebe7b9e6c
commit 09a05706c7
3 changed files with 6 additions and 4 deletions
+1 -1
View File
@@ -16,7 +16,7 @@ public static class ApplicationBuilderExtensions
app.UseStaticFiles(new StaticFileOptions app.UseStaticFiles(new StaticFileOptions
{ {
FileProvider = new PhysicalFileProvider(uploadsPath), FileProvider = new PhysicalFileProvider(uploadsPath),
RequestPath = "/uploads" RequestPath = "/Uploads"
}); });
} }
+2 -2
View File
@@ -122,7 +122,7 @@ public sealed class BackgroundTaskQueue : IBackgroundTaskQueue, IDisposable
foreach (var picture in unfinishedPictures) foreach (var picture in unfinishedPictures)
{ {
// 构建原始文件路径 // 构建原始文件路径
string relativePath = picture.Path.TrimStart('/').Replace("uploads", "Uploads"); string relativePath = picture.Path.TrimStart('/');
string originalFilePath = Path.Combine(Directory.GetCurrentDirectory(), relativePath); string originalFilePath = Path.Combine(Directory.GetCurrentDirectory(), relativePath);
if (File.Exists(originalFilePath)) if (File.Exists(originalFilePath))
{ {
@@ -255,7 +255,7 @@ public sealed class BackgroundTaskQueue : IBackgroundTaskQueue, IDisposable
{ {
// 本地存储缩略图 // 本地存储缩略图
relativeThumbnailPath = relativeThumbnailPath =
$"/uploads/{Path.GetRelativePath("Uploads", Path.GetDirectoryName(thumbnailPath)!)}/{Path.GetFileName(thumbnailPath)}"; $"/Uploads/{Path.GetRelativePath("Uploads", Path.GetDirectoryName(thumbnailPath)!)}/{Path.GetFileName(thumbnailPath)}";
picture.ThumbnailPath = relativeThumbnailPath.Replace('\\', '/'); picture.ThumbnailPath = relativeThumbnailPath.Replace('\\', '/');
} }
else if (picture.StorageType == StorageType.Telegram) else if (picture.StorageType == StorageType.Telegram)
@@ -30,8 +30,10 @@ public class LocalStorageProvider(IConfigService config) : IStorageProvider
return Task.CompletedTask; return Task.CompletedTask;
} }
public string GetUrl(string storagePath) public string GetUrl(string? storagePath)
{ {
if (string.IsNullOrEmpty(storagePath))
return $"/images/unavailable.gif";
return $"{_serverUrl}{storagePath}"; return $"{_serverUrl}{storagePath}";
} }