Merge branch 'develop' into 'release'
Develop See merge request yescent/yes.blog!7
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
|
||||
namespace Yes.Application.Admins.Installs
|
||||
namespace Yes.Application.Installs
|
||||
{
|
||||
public class FileService:IFileService
|
||||
public class FileService : IFileService
|
||||
{
|
||||
public void CopyFolder(string sources, string dest)
|
||||
{
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Yes.Application.Admins.Installs
|
||||
namespace Yes.Application.Installs
|
||||
{
|
||||
public record InstallCommand(
|
||||
string DatabaseType,
|
||||
@@ -10,13 +10,13 @@
|
||||
bool UseDefaultAdmin
|
||||
) : IRequest<InstallCommandResponse>;
|
||||
|
||||
public record InstallCommandResponse(bool Success,string ErrorMessage="");
|
||||
public record InstallCommandResponse(bool Success, string ErrorMessage = "");
|
||||
|
||||
public class InstallCommandHandler(
|
||||
IConnectionStringProvider connectionStringProvider,
|
||||
IMigratorProvider migratorProvider,
|
||||
IConnectionStringProvider connectionStringProvider,
|
||||
IMigratorProvider migratorProvider,
|
||||
IWebHostEnvironment env,
|
||||
IConfigurationService configurationService,
|
||||
IConfigurationService configurationService,
|
||||
IFileService fileService,
|
||||
IOptionsMonitor<BlogSettings> options) : IRequestHandler<InstallCommand, InstallCommandResponse>
|
||||
{
|
||||
@@ -48,10 +48,11 @@
|
||||
Enum.TryParse(request.DatabaseType, out DatabaseTypeEnum databaseType);
|
||||
var databaseServer = request.DatabaseServer;
|
||||
var databaseName = request.DatabaseName;
|
||||
|
||||
var databaseVersion = request.DatabaseVersion;
|
||||
|
||||
var settings = new BlogSettings();
|
||||
|
||||
settings.DatabaseVersion = databaseVersion;
|
||||
settings.DatabaseName = databaseName;
|
||||
settings.DatabaseType = databaseType.ToString();
|
||||
settings.ConnectionString = _connectionStringProvider.GetConnectionString(databaseType, databaseServer, databaseName, request.DatabaseUser, request.DatabasePassword);
|
||||
@@ -12,8 +12,9 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Mapster.DependencyInjection" Version="1.0.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Qiniu" Version="8.7.0" />
|
||||
<PackageReference Include="MediatR" Version="12.4.1" />
|
||||
<PackageReference Include="MediatR" Version="12.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -93,21 +93,21 @@
|
||||
</div>
|
||||
<div class="form-group" x-show="data.databaseType && data.databaseType=='MySql'">
|
||||
<label>数据库版本:</label>
|
||||
<input type="text" class="form-control" x-model="data.databaseVersion" placeholder="请填写数据库版本">
|
||||
<input type="text" class="form-control" x-model="data.databaseVersion" placeholder="请填写数据库版本,如 8.4.5">
|
||||
</div>
|
||||
<div class="form-group" >
|
||||
<div class="form-group">
|
||||
<label>数据库地址:</label>
|
||||
<input type="text" class="form-control" x-model="data.databaseServer" placeholder="请输入您的数据库地址">
|
||||
</div>
|
||||
<div class="form-group" >
|
||||
<div class="form-group">
|
||||
<label>数据库用户名:</label>
|
||||
<input type="text" class="form-control" x-model="data.databaseUser" placeholder="请输入您的数据库用户名">
|
||||
</div>
|
||||
<div class="form-group" >
|
||||
<div class="form-group">
|
||||
<label>数据库密码:</label>
|
||||
<input type="password" class="form-control" x-model="data.databasePassword" placeholder="请输入您的数据库密码">
|
||||
<input type="text" class="form-control" x-model="data.databasePassword" placeholder="请输入您的数据库密码">
|
||||
</div>
|
||||
<div class="form-group" >
|
||||
<div class="form-group">
|
||||
<label>数据库名称:</label>
|
||||
<input type="text" class="form-control" x-model="data.databaseName" placeholder="请输入您的数据库名称">
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace Yes.Blog
|
||||
namespace Yes.Blog
|
||||
{
|
||||
public static class DependencyInjection
|
||||
{
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
|
||||
|
||||
namespace Yes.Blog.Endpoints.Blogs
|
||||
{
|
||||
public class InstallEndpoint : BlogEndpointScheme, IEndpoint
|
||||
|
||||
@@ -18,7 +18,6 @@ global using Yes.Application.Admins.Auths;
|
||||
global using Yes.Application.Admins.Categories;
|
||||
global using Yes.Application.Admins.Comments;
|
||||
global using Yes.Application.Admins.Configurations;
|
||||
global using Yes.Application.Admins.Installs;
|
||||
global using Yes.Application.Admins.Pages;
|
||||
global using Yes.Application.Admins.Statistics;
|
||||
global using Yes.Application.Admins.Storages;
|
||||
@@ -43,3 +42,6 @@ global using Yes.Infrastructure.Authorizations;
|
||||
global using Yes.Infrastructure.Middlewares;
|
||||
global using Yes.Infrastructure.ViewEngine;
|
||||
global using IResult = Yes.Domain.Core.Models.IResult;
|
||||
|
||||
global using Yes.Application.Installs;
|
||||
global using Scalar.AspNetCore;
|
||||
@@ -1,7 +1,3 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.OpenApi.Any;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Scalar.AspNetCore;
|
||||
|
||||
namespace Yes.Blog
|
||||
{
|
||||
|
||||
@@ -40,11 +40,12 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentValidation" Version="11.11.0" />
|
||||
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.11.0" />
|
||||
<PackageReference Include="FluentValidation" Version="12.0.0" />
|
||||
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="12.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.4" />
|
||||
<PackageReference Include="MinimalApis.LiquidViews" Version="2.16.0" />
|
||||
<PackageReference Include="Scalar.AspNetCore" Version="2.2.2" />
|
||||
<PackageReference Include="MinimalApis.LiquidViews" Version="2.24.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Scalar.AspNetCore" Version="2.2.7" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -2,19 +2,18 @@
|
||||
{
|
||||
public class BlogSettings
|
||||
{
|
||||
public string ConnectionString { get; set; }
|
||||
public string ConnectionString { get; set; } = "";
|
||||
|
||||
public string DatabaseName { get; set; }
|
||||
public string DatabaseName { get; set; } = "";
|
||||
|
||||
public string DatabaseType { get; set; }
|
||||
|
||||
public string DatabaseVersion { get; set; }
|
||||
public string DatabaseType { get; set; } = "";
|
||||
|
||||
public string DatabaseVersion { get; set; } = "";
|
||||
public string Name { get; set; } = "我的博客";
|
||||
|
||||
public string Logo { get; set; } = "https://img.yescent.com/FosQ9ua_nPhlNQwYgJwUXi9MFsB5.jpg";
|
||||
public string Logo { get; set; } = "";
|
||||
|
||||
public string Url { get; set; } = "https://yescent.com";
|
||||
public string Url { get; set; } = "https://blog.yescent.com";
|
||||
|
||||
public int PageSizeOfHomepage { get; set; } = 5;
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ namespace Yes.Domain.Core.Data
|
||||
|
||||
string GetDatabaseVersion();
|
||||
|
||||
|
||||
string GetConnectionStringWithoutDatabase(DatabaseTypeEnum databaseType, string connectionString);
|
||||
|
||||
string GetDatabase(DatabaseTypeEnum databaseType, string connectionString);
|
||||
|
||||
@@ -17,5 +17,13 @@ namespace Yes.Domain.Core.Extensions
|
||||
}
|
||||
return ipAddress ?? "";
|
||||
}
|
||||
|
||||
public static string GetCurrentDomain(this HttpContext httpContext)
|
||||
{
|
||||
var request = httpContext.Request;
|
||||
var host = request.Headers["X-Forwarded-Host"].FirstOrDefault() ?? request.Host.Host;
|
||||
var protocol = request.Headers["X-Forwarded-Proto"].FirstOrDefault() ?? request.Scheme;
|
||||
return $"{protocol}://{host}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Markdig" Version="0.39.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
|
||||
<PackageReference Include="Markdig" Version="0.41.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Microsoft.AspNetCore.Http.Extensions;
|
||||
|
||||
|
||||
namespace Yes.Infrastructure.Authorizations
|
||||
{
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
private readonly DatabaseTypeEnum _databaseType;
|
||||
private readonly string _databaseVersion;
|
||||
|
||||
|
||||
public BlogDbContext(IConnectionStringProvider connectionStringProvider)
|
||||
{
|
||||
_connectionString = connectionStringProvider.GetConnectionString();
|
||||
@@ -22,7 +21,7 @@
|
||||
_ = _databaseType switch
|
||||
{
|
||||
DatabaseTypeEnum.SqlServer => builder.UseSqlServer(_connectionString),
|
||||
DatabaseTypeEnum.MySql => builder.UseMySql(_connectionString, string.IsNullOrEmpty(_databaseVersion) ? MySqlServerVersion.AutoDetect(_connectionString) : new MySqlServerVersion(_databaseVersion)),
|
||||
DatabaseTypeEnum.MySql => builder.UseMySql(_connectionString, string.IsNullOrEmpty(_databaseVersion) ? MySqlServerVersion.AutoDetect(_connectionString) : new MySqlServerVersion(_databaseVersion), builder => builder.TranslateParameterizedCollectionsToConstants()),
|
||||
DatabaseTypeEnum.PostgreSQL => builder.UseNpgsql(_connectionString),
|
||||
|
||||
_ => throw new DatabaseNotSupportedException()
|
||||
|
||||
@@ -43,4 +43,7 @@ global using Yes.Infrastructure.Authorizations.Identity;
|
||||
global using Yes.Infrastructure.Authorizations.Identity.Authroizations;
|
||||
global using Yes.Infrastructure.Authorizations.Identity.Context;
|
||||
global using Yes.Infrastructure.Data.DbContexts;
|
||||
global using Yes.Infrastructure.Migrator.Migrations;
|
||||
global using Yes.Infrastructure.Migrator.Migrations;
|
||||
global using MySql.Data.MySqlClient;
|
||||
global using Npgsql;
|
||||
global using Microsoft.AspNetCore.Http.Extensions;
|
||||
@@ -27,7 +27,7 @@
|
||||
return databaseType switch
|
||||
{
|
||||
DatabaseTypeEnum.SqlServer => builder.AddSqlServer(),
|
||||
DatabaseTypeEnum.MySql => builder.AddMySql8().AddMySql5().AddMySql4(),
|
||||
DatabaseTypeEnum.MySql => builder.AddMySql(),
|
||||
DatabaseTypeEnum.PostgreSQL => builder.AddPostgres(),
|
||||
|
||||
_ => throw new DatabaseNotSupportedException()
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace Yes.Infrastructure.Migrator.Providers
|
||||
|
||||
|
||||
namespace Yes.Infrastructure.Migrator.Providers
|
||||
{
|
||||
public class MigratorProvider : IMigratorProvider
|
||||
{
|
||||
@@ -70,14 +72,50 @@
|
||||
{
|
||||
case DatabaseTypeEnum.SqlServer:
|
||||
|
||||
var connection = new SqlConnection(connectionStringWithoutDatabase);
|
||||
var records = connection.Query($"SELECT name FROM sys.databases WHERE name = '{dbName}';");
|
||||
if (!records.Any())
|
||||
using (var connection = new SqlConnection(connectionStringWithoutDatabase))
|
||||
{
|
||||
connection.Execute($"CREATE DATABASE {dbName}");
|
||||
var records = connection.Query($"SELECT name FROM sys.databases WHERE name = '{dbName}';");
|
||||
if (!records.Any())
|
||||
{
|
||||
connection.Execute($"CREATE DATABASE {dbName}");
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case DatabaseTypeEnum.PostgreSQL:
|
||||
|
||||
using (var connection = new NpgsqlConnection(connectionStringWithoutDatabase))
|
||||
{
|
||||
var exists = connection.ExecuteScalar<bool>(
|
||||
"SELECT EXISTS(SELECT 1 FROM pg_database WHERE datname = @dbName)",
|
||||
new { dbName }
|
||||
);
|
||||
if (!exists)
|
||||
{
|
||||
connection.Execute($"CREATE DATABASE \"{dbName}\" ENCODING = 'UTF8'");
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case DatabaseTypeEnum.MySql:
|
||||
using (var connection = new MySqlConnection(connectionStringWithoutDatabase)) // 需要 MySql.Data NuGet 包
|
||||
{
|
||||
// 参数化查询
|
||||
var records = connection.Query<string>(
|
||||
"SELECT SCHEMA_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = @dbName",
|
||||
new { dbName }
|
||||
);
|
||||
|
||||
if (!records.Any())
|
||||
{
|
||||
// 指定字符集和排序规则(推荐)
|
||||
connection.Execute($@"
|
||||
CREATE DATABASE `{dbName}`
|
||||
CHARACTER SET utf8mb4
|
||||
COLLATE utf8mb4_general_ci");
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -7,15 +7,15 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Dapper" Version="2.1.35" />
|
||||
<PackageReference Include="FluentMigrator" Version="6.2.0" />
|
||||
<PackageReference Include="FluentMigrator.Runner" Version="6.2.0" />
|
||||
<PackageReference Include="Fluid.ViewEngine" Version="2.16.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.OpenApi" Version="1.6.17" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.2" />
|
||||
<PackageReference Include="Dapper" Version="2.1.66" />
|
||||
<PackageReference Include="FluentMigrator" Version="7.1.0" />
|
||||
<PackageReference Include="FluentMigrator.Runner" Version="7.1.0" />
|
||||
<PackageReference Include="Fluid.ViewEngine" Version="2.24.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.4" />
|
||||
<PackageReference Include="Microsoft.OpenApi" Version="1.6.24" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="9.0.0-preview.2.efcore.9.0.0" />
|
||||
<PackageReference Include="MySql.Data" Version="9.1.0" />
|
||||
<PackageReference Include="MySql.Data" Version="9.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user