Skip to content

Commit 41b545e

Browse files
committed
Move avatars to App_Data
1 parent a27c781 commit 41b545e

5 files changed

Lines changed: 22 additions & 7 deletions

File tree

MyApp.ServiceInterface/FileServices.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ public async Task<HttpResult> GetProfileImageResultAsync(string profilePath)
5454
return new HttpResult(Svg.GetImage(Svg.Icons.Users), MimeTypes.ImageSvg);
5555
}
5656

57+
public object Any(GetAvatarFile request)
58+
{
59+
var filePath = appData.Config.AppDataPath.CombineWith("avatars", request.Path);
60+
if (!File.Exists(filePath))
61+
throw HttpError.NotFound($"Avatar not found: {filePath}");
62+
63+
return new HttpResult(new FileInfo(filePath),
64+
asAttachment:request.Download == true);
65+
}
66+
5767
public object Any(GetArtifact request)
5868
{
5969
var filePath = appData.Config.ArtifactsPath.CombineWith(request.Path[..2], request.Path);

MyApp.ServiceModel/Artifacts.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ public class GetUserAvatar : IGet, IReturn<byte[]>
6363
public string UserName { get; set; }
6464
}
6565

66+
[Tag(Tags.Artifacts)]
67+
[Route("/avatars/{**Path}")]
68+
public class GetAvatarFile : IGet, IReturn<byte[]>
69+
{
70+
[ValidateNotEmpty]
71+
public string Path { get; set; } = null!;
72+
public bool? Download { get; set; }
73+
}
74+
6675
[Tag(Tags.Artifacts)]
6776
[Route("/artifacts/{**Path}")]
6877
public class GetArtifact : IGet, IReturn<byte[]>

MyApp/Components/Account/Pages/Manage/Index.razor

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
@inject IdentityRedirectManager RedirectManager
1313
@inject IWebHostEnvironment WebHostEnvironment
1414
@inject ServiceStack.Data.IDbConnectionFactory DbFactory
15+
@inject AppConfig AppConfig
1516

1617
<PageTitle>Profile</PageTitle>
1718

@@ -175,7 +176,7 @@
175176
private async Task<string> SaveAvatarAsync(IBrowserFile file, string currentUsername)
176177
{
177178
var relativePath = $"/avatars/{currentUsername[..2]}/{currentUsername}.webp";
178-
var avatarPath = WebHostEnvironment.WebRootPath.CombineWith(relativePath);
179+
var avatarPath = AppConfig.AppDataPath.CombineWith(relativePath);
179180

180181
avatarPath.LastLeftPart('/').AssertDir();
181182

MyApp/Configure.AppHost.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void Configure(IWebHostBuilder builder) => builder
4343
services.AddSingleton<AgentEventsManager>();
4444

4545
// Optional: Enable Managed File Uploads: https://docs.servicestack.net/locode/files-overview
46-
var fileFs = new FileSystemVirtualFiles(context.HostingEnvironment.ContentRootPath);
46+
var fileFs = new FileSystemVirtualFiles(appConfig.AppDataPath);
4747
services.AddPlugin(new FilesUploadFeature(
4848
// User writable, public readable
4949
new UploadLocation("avatars",

MyApp/MyApp.csproj

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@
6262
<Content Include="_videos\**" CopyToPublishDirectory="PreserveNewest"/>
6363
</ItemGroup>
6464

65-
<ItemGroup>
66-
<Folder Include="App_Data\artifacts\" />
67-
<Folder Include="App_Data\files\" />
68-
</ItemGroup>
69-
7065
<Target Name="tailwind" BeforeTargets="Publish">
7166
<Exec Command="bun run ui:build" WorkingDirectory="./" />
7267
</Target>

0 commit comments

Comments
 (0)