BlobManager Düzenlemesi
This commit is contained in:
parent
fcd938985d
commit
b06edfd1ff
12 changed files with 78 additions and 65 deletions
|
|
@ -10,11 +10,9 @@ using Kurs.Platform.Entities;
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.Application.Dtos;
|
||||
using Volo.Abp.Application.Services;
|
||||
using Volo.Abp.BlobStoring;
|
||||
using Volo.Abp.Domain.Repositories;
|
||||
using Volo.Abp.Identity;
|
||||
|
||||
|
|
@ -27,17 +25,17 @@ public class ActivityAppService : CrudAppService<
|
|||
Guid,
|
||||
ActivityListRequestDto>
|
||||
{
|
||||
private readonly IBlobContainer<ActivityBlobContainer> _activityBlobContainer;
|
||||
private readonly IRepository<IdentityUser, Guid> _repositoryUser;
|
||||
private readonly BlobManager _blobContainer;
|
||||
|
||||
public ActivityAppService(
|
||||
IRepository<Activity, Guid> repo,
|
||||
IBlobContainer<ActivityBlobContainer> activityBlobContainer,
|
||||
IRepository<IdentityUser, Guid> repositoryUser
|
||||
IRepository<IdentityUser, Guid> repositoryUser,
|
||||
BlobManager blobContainer
|
||||
) : base(repo)
|
||||
{
|
||||
_activityBlobContainer = activityBlobContainer;
|
||||
_repositoryUser = repositoryUser;
|
||||
_blobContainer = blobContainer;
|
||||
|
||||
// CreatePolicyName = $"{AppCodes.Listforms.Listform}.Create";
|
||||
// UpdatePolicyName = $"{AppCodes.Listforms.Listform}.Update";
|
||||
|
|
@ -55,7 +53,7 @@ public class ActivityAppService : CrudAppService<
|
|||
if (string.IsNullOrWhiteSpace(savedFileName))
|
||||
throw new UserFriendlyException("Dosya adı geçersiz");
|
||||
|
||||
var stream = await _activityBlobContainer.GetAsync(savedFileName);
|
||||
var stream = await _blobContainer.GetAsync(BlobContainerNames.Activity, savedFileName);
|
||||
if (stream == null)
|
||||
throw new UserFriendlyException("Dosya bulunamadı");
|
||||
|
||||
|
|
@ -132,7 +130,8 @@ public class ActivityAppService : CrudAppService<
|
|||
await using var stream = file.GetStream();
|
||||
var savedFileName = $"{Guid.NewGuid()}_{file.FileName}";
|
||||
|
||||
await _activityBlobContainer.SaveAsync(
|
||||
await _blobContainer.SaveAsync(
|
||||
BlobContainerNames.Activity,
|
||||
savedFileName,
|
||||
stream,
|
||||
true
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ using Microsoft.AspNetCore.Mvc;
|
|||
using Microsoft.Extensions.Options;
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.Account;
|
||||
using Volo.Abp.BlobStoring;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
using Volo.Abp.Identity;
|
||||
using Volo.Abp.Users;
|
||||
|
|
@ -21,15 +20,15 @@ namespace Kurs.Platform.Identity;
|
|||
[Route("/api/account/my-profile")]
|
||||
public class PlatformProfileAppService : ProfileAppService, IProfileAppService
|
||||
{
|
||||
private readonly IBlobContainer<AvatarBlobContainer> avatarBlobContainer;
|
||||
public BlobManager _blobCdnManager { get; }
|
||||
|
||||
public PlatformProfileAppService(
|
||||
IdentityUserManager userManager,
|
||||
IOptions<IdentityOptions> identityOptions,
|
||||
IBlobContainer<AvatarBlobContainer> avatarBlobContainer
|
||||
BlobManager blobCdnManager
|
||||
) : base(userManager, identityOptions)
|
||||
{
|
||||
this.avatarBlobContainer = avatarBlobContainer;
|
||||
_blobCdnManager = blobCdnManager;
|
||||
}
|
||||
|
||||
[RemoteService(false)]
|
||||
|
|
@ -63,11 +62,11 @@ public class PlatformProfileAppService : ProfileAppService, IProfileAppService
|
|||
var fileName = $"{user.Id}.jpg";
|
||||
if (input.Avatar is null || input.Avatar.ContentLength == 0)
|
||||
{
|
||||
await avatarBlobContainer.DeleteAsync(fileName);
|
||||
await _blobCdnManager.DeleteAsync(BlobContainerNames.Avatar, fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
await avatarBlobContainer.SaveAsync(fileName, input.Avatar.GetStream(), true);
|
||||
await _blobCdnManager.SaveAsync(BlobContainerNames.Avatar, fileName, input.Avatar.GetStream());
|
||||
}
|
||||
|
||||
user.Name = input.Name;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ using Microsoft.AspNetCore.Authorization;
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.BlobStoring;
|
||||
using Volo.Abp.Content;
|
||||
using Volo.Abp.Domain.Entities;
|
||||
using Volo.Abp.Domain.Repositories;
|
||||
|
|
@ -25,21 +24,21 @@ public class ListFormImportAppService : PlatformAppService, IImportAppService
|
|||
{
|
||||
private readonly IRepository<ListFormImport, Guid> _importSessionRepository;
|
||||
private readonly IRepository<ListFormImportExecute, Guid> _importSessionExecuteRepository;
|
||||
private readonly IBlobContainer<ImportBlobContainer> _importBlobContainer;
|
||||
private readonly IListFormAuthorizationManager _authManager;
|
||||
private readonly IQueryManager _qManager;
|
||||
private readonly BlobManager _blobContainer;
|
||||
|
||||
public ListFormImportAppService(
|
||||
IRepository<ListFormImport, Guid> importSessionRepository,
|
||||
IRepository<ListFormImportExecute, Guid> importSessionExecuteRepository,
|
||||
IBlobContainer<ImportBlobContainer> importBlobContainer,
|
||||
IListFormAuthorizationManager authManager,
|
||||
IQueryManager qManager
|
||||
IQueryManager qManager,
|
||||
BlobManager blobContainer
|
||||
)
|
||||
{
|
||||
_importSessionRepository = importSessionRepository;
|
||||
_importSessionExecuteRepository = importSessionExecuteRepository;
|
||||
_importBlobContainer = importBlobContainer;
|
||||
_blobContainer = blobContainer;
|
||||
_authManager = authManager;
|
||||
_qManager = qManager;
|
||||
}
|
||||
|
|
@ -74,7 +73,7 @@ public class ListFormImportAppService : PlatformAppService, IImportAppService
|
|||
|
||||
try
|
||||
{
|
||||
await _importBlobContainer.SaveAsync(blobName, file.GetStream(), overrideExisting: true);
|
||||
await _blobContainer.SaveAsync(BlobContainerNames.Import, blobName, file.GetStream(), true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1365,13 +1365,6 @@ public static class PlatformConsts
|
|||
public const string dxTextBox = "dxTextBox";
|
||||
}
|
||||
|
||||
public static class BlobContainers
|
||||
{
|
||||
public const string AvatarContainer = "Avatar";
|
||||
public const string ImportContainer = "Import";
|
||||
public const string ActivityContainer = "Activity";
|
||||
}
|
||||
|
||||
public static readonly ReadOnlyCollection<LanguageInfo> Languages = new(
|
||||
[
|
||||
new LanguageInfo(LanguageCodes.Ar, LanguageCodes.Ar, LanguageNames.Ar),
|
||||
|
|
@ -1413,7 +1406,7 @@ public static class PlatformConsts
|
|||
new SelectListItem { Value = LanguageCodes.Tr, Text = LanguageNames.Tr },
|
||||
new SelectListItem { Value = LanguageCodes.Zh, Text = LanguageNames.Zh },
|
||||
];
|
||||
|
||||
|
||||
public static class CustomEndpointConsts
|
||||
{
|
||||
public static class ParameterTypes
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
using Volo.Abp.BlobStoring;
|
||||
|
||||
namespace Kurs.Platform.BlobStoring;
|
||||
|
||||
[BlobContainerName(PlatformConsts.BlobContainers.ActivityContainer)]
|
||||
public class ActivityBlobContainer
|
||||
{
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
using Volo.Abp.BlobStoring;
|
||||
|
||||
namespace Kurs.Platform.BlobStoring;
|
||||
|
||||
[BlobContainerName(PlatformConsts.BlobContainers.AvatarContainer)]
|
||||
public class AvatarBlobContainer
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
namespace Kurs.Platform.BlobStoring;
|
||||
|
||||
public static class BlobContainerNames
|
||||
{
|
||||
public const string Avatar = "avatar";
|
||||
public const string Import = "import";
|
||||
public const string Activity = "activity";
|
||||
}
|
||||
42
api/src/Kurs.Platform.Domain/BlobStoring/BlobManager.cs
Normal file
42
api/src/Kurs.Platform.Domain/BlobStoring/BlobManager.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Volo.Abp.BlobStoring;
|
||||
using Volo.Abp.Domain.Services;
|
||||
|
||||
namespace Kurs.Platform.BlobStoring;
|
||||
|
||||
[Authorize]
|
||||
public class BlobManager : DomainService
|
||||
{
|
||||
private readonly IBlobContainerFactory _blobContainerFactory;
|
||||
|
||||
public BlobManager(IBlobContainerFactory blobContainerFactory)
|
||||
{
|
||||
_blobContainerFactory = blobContainerFactory;
|
||||
}
|
||||
|
||||
private IBlobContainer GetContainer(string containerName)
|
||||
{
|
||||
// containerName bir sınıfa bağlı değil, sadece string
|
||||
return _blobContainerFactory.Create(containerName);
|
||||
}
|
||||
|
||||
public async Task SaveAsync(string containerName, string blobName, Stream bytes, bool overrideExisting = true)
|
||||
{
|
||||
var container = GetContainer(containerName);
|
||||
await container.SaveAsync(blobName, bytes, overrideExisting);
|
||||
}
|
||||
|
||||
public async Task<Stream> GetAsync(string containerName, string blobName)
|
||||
{
|
||||
var container = GetContainer(containerName);
|
||||
return await container.GetAsync(blobName);
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(string containerName, string blobName)
|
||||
{
|
||||
var container = GetContainer(containerName);
|
||||
await container.DeleteAsync(blobName);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
using Volo.Abp.BlobStoring;
|
||||
|
||||
namespace Kurs.Platform.BlobStoring;
|
||||
|
||||
[BlobContainerName(PlatformConsts.BlobContainers.ImportContainer)]
|
||||
public class ImportBlobContainer
|
||||
{
|
||||
}
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using Kurs.Languages;
|
||||
using Kurs.Languages;
|
||||
using Kurs.Sender;
|
||||
using Kurs.MailQueue;
|
||||
using Kurs.Notifications.Domain;
|
||||
|
|
@ -14,7 +13,6 @@ using Volo.Abp.OpenIddict;
|
|||
using Volo.Abp.PermissionManagement.Identity;
|
||||
using Volo.Abp.PermissionManagement.OpenIddict;
|
||||
using Volo.Abp.TenantManagement;
|
||||
using Volo.Abp.Timing;
|
||||
using Volo.Abp.BlobStoring;
|
||||
using Volo.Abp.BlobStoring.FileSystem;
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ using Hangfire.PostgreSql;
|
|||
using Kurs.Languages;
|
||||
using Kurs.MailQueue;
|
||||
using Kurs.Notifications.Application;
|
||||
using Kurs.Platform.BlobStoring;
|
||||
using Kurs.Platform.Classrooms;
|
||||
using Kurs.Platform.EntityFrameworkCore;
|
||||
using Kurs.Platform.Extensions;
|
||||
|
|
@ -37,7 +36,6 @@ using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
|
|||
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic;
|
||||
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Bundling;
|
||||
using Volo.Abp.AspNetCore.Serilog;
|
||||
using Volo.Abp.Auditing;
|
||||
using Volo.Abp.Autofac;
|
||||
using Volo.Abp.BackgroundWorkers.Hangfire;
|
||||
using Volo.Abp.BlobStoring;
|
||||
|
|
@ -48,7 +46,6 @@ using Volo.Abp.Identity;
|
|||
using Volo.Abp.Modularity;
|
||||
using Volo.Abp.Security.Claims;
|
||||
using Volo.Abp.Swashbuckle;
|
||||
using Volo.Abp.Timing;
|
||||
using Volo.Abp.UI.Navigation.Urls;
|
||||
using Volo.Abp.VirtualFileSystem;
|
||||
using static Kurs.Platform.PlatformConsts;
|
||||
|
|
@ -107,7 +104,7 @@ public class PlatformHttpApiHostModule : AbpModule
|
|||
//TenantLocalization Middleware kaydı
|
||||
context.Services.AddTransient<TenantLocalizationMiddleware>();
|
||||
context.Services.AddTransient<TenantLocalizationInitializer>();
|
||||
|
||||
|
||||
ConfigureAuthentication(context);
|
||||
ConfigureBundles();
|
||||
ConfigureUrls(configuration);
|
||||
|
|
@ -333,13 +330,15 @@ public class PlatformHttpApiHostModule : AbpModule
|
|||
|
||||
private void ConfigureBlobStoring(IConfiguration configuration)
|
||||
{
|
||||
var root = configuration["App:CdnPath"];
|
||||
|
||||
Configure<AbpBlobStoringOptions>(options =>
|
||||
{
|
||||
options.Containers.Configure<AvatarBlobContainer>(c => c.UseFileSystem(fs => fs.BasePath = root));
|
||||
options.Containers.Configure<ImportBlobContainer>(c => c.UseFileSystem(fs => fs.BasePath = root));
|
||||
options.Containers.Configure<ActivityBlobContainer>(c => c.UseFileSystem(fs => fs.BasePath = root));
|
||||
options.Containers.ConfigureDefault(container =>
|
||||
{
|
||||
container.UseFileSystem(fileSystem =>
|
||||
{
|
||||
fileSystem.BasePath = configuration["App:CdnPath"];
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
"CorsOrigins": "http://localhost,http://localhost:3000,http://localhost:4200",
|
||||
"RedirectAllowedUrls": "http://localhost:4200,http://localhost:4200/authentication/callback",
|
||||
"AttachmentsPath": "C:\\Private\\Projects\\sozsoft\\configs\\mail-queue\\attachments",
|
||||
"CdnPath": "C:\\Private\\Projects\\sozsoft\\configs\\docker\\data\\cdn",
|
||||
"CdnPath": "C:\\Private\\Projects\\sozsoft\\configs\\docker\\cdn",
|
||||
"Version": "1.0.1"
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
|
|
|
|||
Loading…
Reference in a new issue