CHANGE PROJECT NAME TO "NETINA"
parent
5abfe72bdb
commit
83cd317203
|
@ -0,0 +1,78 @@
|
|||
{
|
||||
"ConnectionStrings": {
|
||||
"PostgresServer": "User ID=postgres;Password=root;Host=localhost;Port=5432;Database=iGarsonDB;",
|
||||
"Postgres": "Host=pg-0,pg-1;Username=igarsonAgent;Password=xHTpBf4wC+bBeNg2pL6Ga7VEWKFJx7VPEUpqxwPFfOc2YYTVwFQuHfsiqoVeT9+6;Database=NetinaShopDB02;Load Balance Hosts=true;Target Session Attributes=primary;Application Name=iGLS",
|
||||
"MartenDB": "Host=pg-0,pg-1;Username=igarsonAgent;Password=xHTpBf4wC+bBeNg2pL6Ga7VEWKFJx7VPEUpqxwPFfOc2YYTVwFQuHfsiqoVeT9+6;Database=NetinaShopMartenDB;"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "None",
|
||||
"Microsoft.Hosting.Lifetime": "Information",
|
||||
"Microsoft.AspNetCore.SignalR": "Debug",
|
||||
"Microsoft.AspNetCore.Http.Connections": "Debug"
|
||||
}
|
||||
},
|
||||
"ShopSettings": {
|
||||
"TaxesFee": 9
|
||||
},
|
||||
"SiteSettings": {
|
||||
"BaseUrl": "http://localhost:32770",
|
||||
"WebSiteUrl": "https://hamyanedalat.com",
|
||||
"AdminPanelBaseUrl": "https://admin.hamyanedalat.com",
|
||||
"StorageBaseUrl": "https://storage.hamyanedalat.com",
|
||||
"KaveNegarApiKey": "3735494B4143727A794346457461576A2B4B6668414973424E333561505A694B",
|
||||
"UserSetting": {
|
||||
"Username": "09214802813",
|
||||
"Email": "avvampier@gmail.com",
|
||||
"Password": "eF79o4P4BopCUbUK",
|
||||
"Phone": "09214802813",
|
||||
"RoleName": "RootAdmin",
|
||||
"FirstName": "همه کاره",
|
||||
"LastName": "سیستم"
|
||||
},
|
||||
"Manager": {
|
||||
"Username": "09122171024",
|
||||
"Email": "info@hamyanedalat.com",
|
||||
"Password": "eF79o4P4BopCUbUK",
|
||||
"Phone": "09122171024",
|
||||
"RoleName": "Manager",
|
||||
"FirstName": "کامران",
|
||||
"LastName": "میرزایی"
|
||||
},
|
||||
"StorageSetting": {
|
||||
"AccessKey": "de129835-b43a-4552-8ed4-865e2635ab3d",
|
||||
"SecretKey": "f00197a766336e818023f90408ba3b88b4fdc86d0e7180f74f199d9f03db7575",
|
||||
"BucketKey": "hamyan-content"
|
||||
},
|
||||
"JwtSettings": {
|
||||
"SecretKey": "YAEMAMZAMAN_KHODET_NEGAHDAR_IN_KEY_BASH_nw+8E0EABj0Wg8c4mHg/bDBf5qGMhmBPb6u16DVe9/MzYva1e+/J1zImyIoQX2Lmra2kvzsIjGiwP7r3Znd_YA_JADE_NASABE_v+Ro/CDixScDv6EkpZnkBv9MFdPnSmFXNGMH9gA1BzQUoC1iSX9Aq+pMIw/cMKXI9WA==_YA_HUSEIN_SEYED_SHOHADA_BE_OMID_KHODET",
|
||||
"Issuer": "HamaynEdalat",
|
||||
"Audience": "HamaynEdalat",
|
||||
"ExpireAddDay": "15"
|
||||
}
|
||||
},
|
||||
"IpRateLimiting": {
|
||||
"EnableEndpointRateLimiting": false,
|
||||
"StackBlockedRequests": false,
|
||||
"RealIpHeader": "X-Real-IP",
|
||||
"ClientIdHeader": "X-ClientId",
|
||||
"HttpStatusCode": 429,
|
||||
"IpWhitelist": [ "127.0.0.1", "::1/10", "192.168.0.0/24" ],
|
||||
"EndpointWhitelist": [ "get:/api/license", "*:/api/status" ],
|
||||
"ClientWhitelist": [ "dev-id-1", "dev-id-2" ],
|
||||
"GeneralRules": [
|
||||
{
|
||||
"Endpoint": "*",
|
||||
"Period": "1m",
|
||||
"Limit": 60
|
||||
},
|
||||
{
|
||||
"Endpoint": "*",
|
||||
"Period": "15m",
|
||||
"Limit": 250
|
||||
}
|
||||
]
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
|
@ -10,8 +10,7 @@ public class FileController : ICarterModule
|
|||
public void AddRoutes(IEndpointRouteBuilder app)
|
||||
{
|
||||
var group = app.NewVersionedApi("File")
|
||||
.MapGroup("api/file")
|
||||
.RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser());
|
||||
.MapGroup("api/file");
|
||||
|
||||
group.MapGet("", GetFilesAsync)
|
||||
.WithDisplayName("GetFilesAsync")
|
||||
|
@ -20,7 +19,6 @@ public class FileController : ICarterModule
|
|||
|
||||
group.MapPost("", UploadFileAsync)
|
||||
.WithDisplayName("UploadFileAsync")
|
||||
.RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser().RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageFiles))
|
||||
.HasApiVersion(1.0);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,13 +1,7 @@
|
|||
using Netina.Common.Models.Api;
|
||||
using Netina.Common.Models.Exception;
|
||||
using Netina.Domain.CommandQueries.Commands;
|
||||
using Netina.Domain.Dtos.RequestDtos.SeedDtos;
|
||||
using Netina.Domain.Dtos.SmallDtos;
|
||||
using Netina.Domain.Dtos.RequestDtos.SeedDtos;
|
||||
using Netina.Domain.Entities.Blogs;
|
||||
using Netina.Repository.Repositories.Base;
|
||||
|
||||
namespace Netina.Api.Controller;
|
||||
|
||||
public class SeedController : ICarterModule
|
||||
{
|
||||
private readonly IWebHostEnvironment _environment;
|
||||
|
@ -63,6 +57,7 @@ public class SeedController : ICarterModule
|
|||
|
||||
return TypedResults.Ok();
|
||||
}
|
||||
|
||||
public async Task<IResult> SeedCategoriesAsync([FromBody] List<SeedCategoryRequestDto> request, [FromQuery] string key, IMediator mediator,CancellationToken cancellationToken)
|
||||
{
|
||||
if (key != "kKAYskyG8xPxKnJrHkuYxub4Ao2bnz7AOmNtwDT0RaqzaG7ZvbvaP29tCrC8wJ823RczJFXOIQT2bDOec4F38A==")
|
||||
|
@ -112,6 +107,13 @@ public class SeedController : ICarterModule
|
|||
{
|
||||
var ent = Blog.Create(seedBlogRequestDto.Title, seedBlogRequestDto.Content, seedBlogRequestDto.Tags, seedBlogRequestDto.ReadingTime,
|
||||
seedBlogRequestDto.Summery, seedBlogRequestDto.IsSuggested, seedBlogRequestDto.CategoryId);
|
||||
|
||||
foreach (var storageFileSDto in seedBlogRequestDto.Files)
|
||||
{
|
||||
ent.AddFile(storageFileSDto.Name, storageFileSDto.FileLocation, storageFileSDto.FileName, true, true,
|
||||
storageFileSDto.FileType);
|
||||
}
|
||||
|
||||
repositoryWrapper.SetRepository<Blog>().Add(ent);
|
||||
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
|
|
|
@ -1,12 +1,3 @@
|
|||
using Netina.Api.WebFramework.Configurations;
|
||||
using Netina.Api.WebFramework.MiddleWares;
|
||||
using Netina.Api.WebFramework.Swagger;
|
||||
using Netina.Common.Models;
|
||||
using Netina.Core;
|
||||
using Netina.Domain;
|
||||
using Netina.Domain.Models.Settings;
|
||||
using Netina.Infrastructure;
|
||||
using Netina.Repository;
|
||||
using Netina.Repository.Behaviors;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
@ -15,10 +6,9 @@ builder.Host.UseSerilog();
|
|||
LoggerConfig.ConfigureSerilog();
|
||||
string env = builder.Environment.IsDevelopment() == true ? "Development" : "Production";
|
||||
builder.Host.UseContentRoot(Directory.GetCurrentDirectory());
|
||||
string projectName = "Hamyan";
|
||||
if (builder.Environment.IsDevelopment())
|
||||
builder.Configuration
|
||||
.AddJsonFile($"AppSettings/appsettings.json")
|
||||
.AddJsonFile($"AppSettings/appsettings.{env}.json");
|
||||
builder.Configuration.AddJsonFile($"AppSettings/appsettings.json").AddJsonFile($"AppSettings/appsettings.{env}{projectName}.json");
|
||||
|
||||
if (builder.Environment.IsProduction())
|
||||
builder.Configuration.AddJsonFile($"AppSettings/Production/appsettings.{env}.json");
|
||||
|
|
|
@ -9,10 +9,13 @@ public static class ImageConvertor
|
|||
public static async Task<Stream> ImageResize(this FileUploadRequest fileUpload, Stream input, Stream output, int newWidth)
|
||||
{
|
||||
using var image = await Image.LoadAsync(input);
|
||||
var height_width = image.Width /image.Height;
|
||||
var new_Height = newWidth * height_width;
|
||||
image.Mutate(x => x.Resize(newWidth, new_Height));
|
||||
image.Mutate(x => x.Resize(newWidth, new_Height));
|
||||
if (image.Width > newWidth)
|
||||
{
|
||||
double ratio = (double)newWidth / image.Width;
|
||||
int new_Height = (int)Math.Round(image.Height * ratio);
|
||||
image.Mutate(x => x.Resize(newWidth, new_Height));
|
||||
image.Mutate(x => x.Resize(newWidth, new_Height));
|
||||
}
|
||||
await image.SaveAsJpegAsync(output);
|
||||
return output;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ public class SeedBlogRequestDto
|
|||
public string Summery { get; set; } = string.Empty;
|
||||
public bool IsSuggested { get; set; }
|
||||
public Guid CategoryId { get; set; }
|
||||
public List<StorageFileSDto> Files { get; set; } = new();
|
||||
}
|
||||
|
||||
public class SeedBlogCategoryRequestDto
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
using Netina.Domain.Entities.StorageFiles;
|
||||
using Netina.Domain.Enums;
|
||||
|
||||
namespace Netina.Domain.Entities.Blogs;
|
||||
namespace Netina.Domain.Entities.Blogs;
|
||||
|
||||
public partial class BlogStorageFile : StorageFile
|
||||
{
|
||||
|
|
|
@ -1,10 +1,21 @@
|
|||
using Netina.Common.Extensions;
|
||||
using Netina.Domain.CommandQueries.Commands;
|
||||
using Netina.Domain.Dtos.RequestDtos.SeedDtos;
|
||||
using Netina.Domain.Dtos.SmallDtos;
|
||||
using Netina.Domain.Entities.Blogs;
|
||||
using Netina.WordPressDBConverter.Models;
|
||||
using Netina.WordPressDBConverter.Services.RestServices;
|
||||
using Newtonsoft.Json;
|
||||
using Netina.Common.Models.Api;
|
||||
using Netina.Domain.Dtos.SmallDtos;
|
||||
using Netina.Domain.Enums;
|
||||
using Netina.WordPressDBConverter.Services.RestServices;
|
||||
using Refit;
|
||||
|
||||
|
||||
var postMetaReader = new StreamReader("F:\\wp_postmeta.json");
|
||||
var postMetaJson = postMetaReader.ReadToEnd();
|
||||
Console.WriteLine("Terms File Read Success !");
|
||||
var postMetas = JsonConvert.DeserializeObject<List<WordPressPostMetaDto>>(postMetaJson);
|
||||
if (postMetas == null)
|
||||
throw new Exception("Terms is null");
|
||||
|
||||
|
||||
var termReader = new StreamReader("F:\\wp_terms.json");
|
||||
|
@ -37,8 +48,10 @@ if (posts == null)
|
|||
throw new Exception("Posts is null");
|
||||
|
||||
|
||||
|
||||
//CREATE CATEGORY PART
|
||||
List<SeedBlogCategoryRequestDto> categories = new List<SeedBlogCategoryRequestDto>();
|
||||
|
||||
List<WordPressPostTagDto> tags = new List<WordPressPostTagDto>();
|
||||
foreach (var taxonomy in termTaxonomies)
|
||||
{
|
||||
|
@ -48,8 +61,8 @@ foreach (var taxonomy in termTaxonomies)
|
|||
if (term != null)
|
||||
categories.Add(new SeedBlogCategoryRequestDto
|
||||
{
|
||||
BaseCategoryId = term.term_id.ToInt(),
|
||||
Description = taxonomy.description,
|
||||
BaseCategoryId = term.term_id.ToInt(),
|
||||
Description = taxonomy.description,
|
||||
Name = term.name
|
||||
});
|
||||
}
|
||||
|
@ -64,15 +77,17 @@ foreach (var taxonomy in termTaxonomies)
|
|||
Tag = term.name
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var categoriesRest = await RestWrapper.Instance.SeedRestApi.SeedBlogCategoriesAsync(categories, "kKAYskyG8xPxKnJrHkuYxub4Ao2bnz7AOmNtwDT0RaqzaG7ZvbvaP29tCrC8wJ823RczJFXOIQT2bDOec4F38A==");
|
||||
Console.WriteLine($"{categories.Count} ProductCategory Added Success !");
|
||||
}
|
||||
var categoriesRest = new Dictionary<int, Guid>();
|
||||
categoriesRest = await RestWrapper.Instance.SeedRestApi.SeedBlogCategoriesAsync(categories, "kKAYskyG8xPxKnJrHkuYxub4Ao2bnz7AOmNtwDT0RaqzaG7ZvbvaP29tCrC8wJ823RczJFXOIQT2bDOec4F38A==");
|
||||
Console.WriteLine($"{categories.Count} BlogCategory Added Success !");
|
||||
|
||||
|
||||
//CREATE BLOG PART
|
||||
List<SeedBlogRequestDto> blogs = new List<SeedBlogRequestDto>();
|
||||
var random = new Random(1532);
|
||||
int thumbCounter = 0;
|
||||
foreach (var wordPressPostDto in posts.Where(p => p.post_type == "post"))
|
||||
{
|
||||
SeedBlogRequestDto blog;
|
||||
|
@ -94,6 +109,35 @@ foreach (var wordPressPostDto in posts.Where(p => p.post_type == "post"))
|
|||
if (categoryId == default)
|
||||
categoryId = categoriesRest.FirstOrDefault(c => c.Key == 0).Value;
|
||||
|
||||
var files = new List<StorageFileSDto>();
|
||||
|
||||
var thumbnailMeta = postMetas.FirstOrDefault(pm => pm.post_id == wordPressPostDto.ID && pm.meta_key == "_thumbnail_id");
|
||||
if (thumbnailMeta != null)
|
||||
{
|
||||
var thumbnail = posts.FirstOrDefault(p => p.ID.ToInt() == thumbnailMeta.meta_value.ToInt());
|
||||
if (thumbnail != null)
|
||||
{
|
||||
using var httpClient = new HttpClient();
|
||||
var imageBytes = await httpClient.GetByteArrayAsync(thumbnail.guid);
|
||||
var uploadFile = new FileUploadRequest
|
||||
{
|
||||
ContentType = thumbnail.post_mime_type,
|
||||
FileName = $"{StringExtensions.GetId(10)}.jpeg",
|
||||
FileUploadType = FileUploadType.Image,
|
||||
StringBaseFile = Convert.ToBase64String(imageBytes),
|
||||
};
|
||||
var fileRest = await RestWrapper.Instance.UploadRestApi.UploadAsync(uploadFile);
|
||||
|
||||
files.Add(new StorageFileSDto
|
||||
{
|
||||
FileLocation = fileRest.FileLocation,
|
||||
FileName = fileRest.FileName,
|
||||
Name = fileRest.FileName,
|
||||
FileType = StorageFileType.Image
|
||||
});
|
||||
Console.WriteLine($"Thumbnail uploaded : {thumbCounter++}");
|
||||
}
|
||||
}
|
||||
|
||||
blog = new SeedBlogRequestDto
|
||||
{
|
||||
|
@ -102,17 +146,14 @@ foreach (var wordPressPostDto in posts.Where(p => p.post_type == "post"))
|
|||
IsSuggested = false,
|
||||
ReadingTime = random.Next(1, 15),
|
||||
Title = wordPressPostDto.post_title,
|
||||
Files = files
|
||||
};
|
||||
|
||||
blogs.Add(blog);
|
||||
}
|
||||
|
||||
for (int i = 0; i < blogs.Count / 50; i++)
|
||||
{
|
||||
await RestWrapper.Instance.SeedRestApi.SeedBlogsAsync(blogs.Skip(i * 50).Take(50).ToList(),
|
||||
"kKAYskyG8xPxKnJrHkuYxub4Ao2bnz7AOmNtwDT0RaqzaG7ZvbvaP29tCrC8wJ823RczJFXOIQT2bDOec4F38A==");
|
||||
await RestWrapper.Instance.SeedRestApi.SeedBlogsAsync(new List<SeedBlogRequestDto>{blog}, "kKAYskyG8xPxKnJrHkuYxub4Ao2bnz7AOmNtwDT0RaqzaG7ZvbvaP29tCrC8wJ823RczJFXOIQT2bDOec4F38A==");
|
||||
|
||||
Console.WriteLine($"{i * 50} / {blogs.Count} Product Added Success !");
|
||||
Console.WriteLine($"{thumbCounter++ } / {blogs.Count} Blog Added Success !");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Netina.Domain.CommandQueries.Commands;
|
||||
using Netina.Common.Models.Api;
|
||||
using Netina.Domain.CommandQueries.Commands;
|
||||
using Netina.Domain.Dtos.RequestDtos.SeedDtos;
|
||||
using Refit;
|
||||
|
||||
|
@ -21,4 +22,10 @@ public interface ISeedRestApi
|
|||
|
||||
[Post("/blogs")]
|
||||
Task SeedBlogsAsync([Body] List<SeedBlogRequestDto> request, [Query] string key);
|
||||
}
|
||||
|
||||
public interface IUploadRestApi
|
||||
{
|
||||
[Post("")]
|
||||
Task<FileUploadResponse> UploadAsync([Body] FileUploadRequest uploadRequest);
|
||||
}
|
|
@ -1,11 +1,19 @@
|
|||
using Refit;
|
||||
using Newtonsoft.Json;
|
||||
using Refit;
|
||||
|
||||
namespace Netina.WordPressDBConverter.Services.RestServices;
|
||||
|
||||
public class RestWrapper
|
||||
{
|
||||
private static RefitSettings setting = new RefitSettings(new NewtonsoftJsonContentSerializer(new JsonSerializerSettings
|
||||
{
|
||||
Formatting = Newtonsoft.Json.Formatting.Indented,
|
||||
ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore,
|
||||
|
||||
}));
|
||||
private static RestWrapper? _instance;
|
||||
public static RestWrapper Instance => _instance = _instance ?? new RestWrapper();
|
||||
|
||||
public ISeedRestApi SeedRestApi => RestService.For<ISeedRestApi>("http://localhost:32770/api/seed");
|
||||
public ISeedRestApi SeedRestApi => RestService.For<ISeedRestApi>("http://localhost:32770/api/seed", setting);
|
||||
public IUploadRestApi UploadRestApi => RestService.For<IUploadRestApi>("http://localhost:32770/api/file", setting);
|
||||
}
|
Loading…
Reference in New Issue