Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7d4d113e60 |
25
.gitignore
vendored
25
.gitignore
vendored
@ -259,31 +259,16 @@ paket-files/
|
|||||||
# Python Tools for Visual Studio (PTVS)
|
# Python Tools for Visual Studio (PTVS)
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.pyc
|
*.pyc
|
||||||
|
/ZR.Admin.WebApi/appsettings.Development.json
|
||||||
/CodeGenerate
|
/CodeGenerate
|
||||||
|
/ZR.Admin.WebApi/appsettings.Production.json
|
||||||
|
/ZR.Admin.WebApi/wwwroot/uploads
|
||||||
/ZR.Admin.WebApi/wwwroot/Generatecode
|
/ZR.Admin.WebApi/wwwroot/Generatecode
|
||||||
/ZR.Admin.WebApi/wwwroot/export
|
/ZR.Admin.WebApi/wwwroot/export
|
||||||
/ZR.Vue/src/views/business/Gendemo.vue
|
/ZR.Vue/src/views/business/Gendemo.vue
|
||||||
|
/ZR.Admin.WebApi/Properties/launchSettings.json
|
||||||
/ZR.Admin.WebApi/ZRAdmin.xml
|
/ZR.Admin.WebApi/ZRAdmin.xml
|
||||||
/ZR.Admin.WebApi/DataProtection
|
/ZR.Admin.WebApi/DataProtection
|
||||||
/Quartz.NET.WindowsService
|
/Quartz.NET.WindowsService
|
||||||
/ZRAdmin-vue/node_modules/
|
/ZRAdmin-vue
|
||||||
/ZRAdmin-vue/.DS_Store
|
|
||||||
/ZRAdmin-vue/dist/
|
|
||||||
/ZRAdmin-vue/npm-debug.log*
|
|
||||||
/ZRAdmin-vue/yarn-debug.log*
|
|
||||||
/ZRAdmin-vue/yarn-error.log*
|
|
||||||
/ZRAdmin-vue/**/*.log
|
|
||||||
/ZRAdmin-vue/tests/**/coverage/
|
|
||||||
/ZRAdmin-vue/tests/e2e/reports
|
|
||||||
/ZRAdmin-vue/selenium-debug.log
|
|
||||||
/ZRAdmin-vue/.idea
|
|
||||||
/ZRAdmin-vue/*.suo
|
|
||||||
/ZRAdmin-vue/*.ntvs*
|
|
||||||
/ZRAdmin-vue/*.njsproj
|
|
||||||
/ZRAdmin-vue/*.sln
|
|
||||||
/ZRAdmin-vue/*.local
|
|
||||||
/ZRAdmin-vue/package-lock.json
|
|
||||||
/ZRAdmin-vue/deploy.js
|
|
||||||
/ZR.Admin.WebApi/ZRModel.xml
|
/ZR.Admin.WebApi/ZRModel.xml
|
||||||
ZRAdmin-vue/dist.zip
|
|
||||||
**/.vshistory/
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
<NoWarn>8632</NoWarn>
|
<NoWarn>8632</NoWarn>
|
||||||
|
|||||||
@ -1,54 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
|
|
||||||
option csharp_namespace = "ZR.Admin.Grpc";
|
|
||||||
|
|
||||||
package filetransfer;
|
|
||||||
|
|
||||||
service FileTransfer {
|
|
||||||
rpc InitUpload (InitUploadRequest) returns (InitUploadResponse);
|
|
||||||
rpc UploadChunk (stream UploadChunkRequest) returns (UploadChunkResponse);
|
|
||||||
rpc CompleteUpload (CompleteUploadRequest) returns (CompleteUploadResponse);
|
|
||||||
rpc CheckUploadStatus (CheckUploadStatusRequest) returns (CheckUploadStatusResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
message InitUploadRequest {
|
|
||||||
string file_name = 1;
|
|
||||||
int64 file_size = 2;
|
|
||||||
string file_hash = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
message InitUploadResponse {
|
|
||||||
string session_id = 1;
|
|
||||||
int64 uploaded_bytes = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message UploadChunkRequest {
|
|
||||||
string session_id = 1;
|
|
||||||
bytes chunk_data = 2;
|
|
||||||
int64 offset = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
message UploadChunkResponse {
|
|
||||||
int64 uploaded_bytes = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message CompleteUploadRequest {
|
|
||||||
string session_id = 1;
|
|
||||||
string file_hash = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message CompleteUploadResponse {
|
|
||||||
bool success = 1;
|
|
||||||
string message = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message CheckUploadStatusRequest {
|
|
||||||
string file_name = 1;
|
|
||||||
string file_hash = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message CheckUploadStatusResponse {
|
|
||||||
string session_id = 1;
|
|
||||||
int64 uploaded_bytes = 2;
|
|
||||||
bool exists = 3;
|
|
||||||
}
|
|
||||||
@ -1,35 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
|
|
||||||
option csharp_namespace = "ZR.Admin.Grpc";
|
|
||||||
|
|
||||||
package my.diary;
|
|
||||||
|
|
||||||
import "google/protobuf/timestamp.proto";
|
|
||||||
|
|
||||||
// The greeting service definition.
|
|
||||||
service MyDiary {
|
|
||||||
// Sends a greeting
|
|
||||||
rpc Edit (EditRequest) returns (EditReply);
|
|
||||||
rpc Query (QueryRequest) returns (QueryReply);
|
|
||||||
}
|
|
||||||
|
|
||||||
// The request message containing the user's name.
|
|
||||||
message EditRequest {
|
|
||||||
string content = 1;
|
|
||||||
int64 user_id = 2;
|
|
||||||
google.protobuf.Timestamp create_time = 3; // 字段名仍然建议使用 snake_case
|
|
||||||
}
|
|
||||||
|
|
||||||
// The response message containing the greetings.
|
|
||||||
message EditReply {
|
|
||||||
string result_message = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message QueryRequest {
|
|
||||||
int64 user_id = 1;
|
|
||||||
google.protobuf.Timestamp create_time = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message QueryReply {
|
|
||||||
string content = 1;
|
|
||||||
}
|
|
||||||
@ -1,109 +0,0 @@
|
|||||||
using Grpc.Core;
|
|
||||||
using ZR.Admin.Grpc;
|
|
||||||
|
|
||||||
namespace GrpcService.Services
|
|
||||||
{
|
|
||||||
public class FileTransferService : FileTransfer.FileTransferBase
|
|
||||||
{
|
|
||||||
private readonly string _storagePath = "Îļþ";
|
|
||||||
private readonly IUploadSessionManager _sessionManager;
|
|
||||||
|
|
||||||
public FileTransferService(IUploadSessionManager sessionManager)
|
|
||||||
{
|
|
||||||
Directory.CreateDirectory(_storagePath);
|
|
||||||
_sessionManager = sessionManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Task<InitUploadResponse> InitUpload(InitUploadRequest request, ServerCallContext context)
|
|
||||||
{
|
|
||||||
var sessionId = _sessionManager.CreateSession(request.FileName, request.FileSize, request.FileHash);
|
|
||||||
var uploadedBytes = _sessionManager.GetUploadedBytes(sessionId);
|
|
||||||
|
|
||||||
return Task.FromResult(new InitUploadResponse
|
|
||||||
{
|
|
||||||
SessionId = sessionId,
|
|
||||||
UploadedBytes = uploadedBytes
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task<UploadChunkResponse> UploadChunk(IAsyncStreamReader<UploadChunkRequest> requestStream, ServerCallContext context)
|
|
||||||
{
|
|
||||||
UploadChunkRequest currentRequest = null;
|
|
||||||
var response = new UploadChunkResponse();
|
|
||||||
|
|
||||||
while (await requestStream.MoveNext())
|
|
||||||
{
|
|
||||||
currentRequest = requestStream.Current;
|
|
||||||
var session = _sessionManager.GetSession(currentRequest.SessionId);
|
|
||||||
|
|
||||||
if (session == null)
|
|
||||||
{
|
|
||||||
throw new RpcException(new Status(StatusCode.NotFound, "Session not found"));
|
|
||||||
}
|
|
||||||
|
|
||||||
using (var fileStream = new FileStream(session.TempFilePath, FileMode.OpenOrCreate, FileAccess.Write))
|
|
||||||
{
|
|
||||||
fileStream.Seek(currentRequest.Offset, SeekOrigin.Begin);
|
|
||||||
await fileStream.WriteAsync(currentRequest.ChunkData.ToByteArray(), 0, currentRequest.ChunkData.Length);
|
|
||||||
}
|
|
||||||
|
|
||||||
_sessionManager.UpdateSessionProgress(currentRequest.SessionId, currentRequest.Offset + currentRequest.ChunkData.Length);
|
|
||||||
response.UploadedBytes = currentRequest.Offset + currentRequest.ChunkData.Length;
|
|
||||||
}
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task<CompleteUploadResponse> CompleteUpload(CompleteUploadRequest request, ServerCallContext context)
|
|
||||||
{
|
|
||||||
var session = _sessionManager.GetSession(request.SessionId);
|
|
||||||
if (session == null)
|
|
||||||
{
|
|
||||||
return await Task.FromResult(new CompleteUploadResponse
|
|
||||||
{
|
|
||||||
Success = false,
|
|
||||||
Message = "Session not found"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify file hash if needed
|
|
||||||
if (!string.IsNullOrEmpty(request.FileHash))
|
|
||||||
{
|
|
||||||
var actualHash = await FileHelper.GetQuickFileIdentity(session.TempFilePath);
|
|
||||||
if (actualHash != request.FileHash)
|
|
||||||
{
|
|
||||||
return await Task.FromResult(new CompleteUploadResponse
|
|
||||||
{
|
|
||||||
Success = false,
|
|
||||||
Message = "File hash mismatch"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move temp file to final location
|
|
||||||
var finalPath = Path.Combine(_storagePath, session.FileName);
|
|
||||||
//var finalPath = FileHelper.GetUniqueFilePath(_storagePath, session.FileName);
|
|
||||||
File.Move(session.TempFilePath, finalPath, true);
|
|
||||||
|
|
||||||
_sessionManager.CompleteSession(request.SessionId);
|
|
||||||
|
|
||||||
return await Task.FromResult(new CompleteUploadResponse
|
|
||||||
{
|
|
||||||
Success = true,
|
|
||||||
Message = "File uploaded successfully"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Task<CheckUploadStatusResponse> CheckUploadStatus(CheckUploadStatusRequest request, ServerCallContext context)
|
|
||||||
{
|
|
||||||
var session = _sessionManager.FindSession(request.FileName, request.FileHash);
|
|
||||||
|
|
||||||
return Task.FromResult(new CheckUploadStatusResponse
|
|
||||||
{
|
|
||||||
SessionId = session?.SessionId ?? "",
|
|
||||||
UploadedBytes = session?.UploadedBytes ?? 0,
|
|
||||||
Exists = session != null
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,37 +0,0 @@
|
|||||||
using Grpc.Core;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ZR.Admin.Grpc.Services
|
|
||||||
{
|
|
||||||
public class GreeterService : Greeter.GreeterBase
|
|
||||||
{
|
|
||||||
private readonly ILogger<GreeterService> _logger;
|
|
||||||
|
|
||||||
public GreeterService(ILogger<GreeterService> logger)
|
|
||||||
{
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 实现 SayHello 方法
|
|
||||||
// 第一个参数是请求消息 (HelloRequest)
|
|
||||||
// 第二个参数是服务器上下文 (ServerCallContext),提供关于当前调用的信息
|
|
||||||
public override Task<HelloReply> SayHello(HelloRequest request, ServerCallContext context)
|
|
||||||
{
|
|
||||||
_logger.LogInformation($"接收到来自 {request.Name} 的请求");
|
|
||||||
|
|
||||||
// 构建并返回回复消息
|
|
||||||
var reply = new HelloReply
|
|
||||||
{
|
|
||||||
Message = $"你好,{request.Name} 来自 gRPC 服务器!"
|
|
||||||
};
|
|
||||||
|
|
||||||
// 返回一个 Task<HelloReply>
|
|
||||||
return Task.FromResult(reply);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,76 +0,0 @@
|
|||||||
using Grpc.Core;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using ZR.Service.IService;
|
|
||||||
|
|
||||||
namespace ZR.Admin.Grpc.Services
|
|
||||||
{
|
|
||||||
public class MyDiaryService(ILogger<MyDiaryService> logger, IMyDiaryService myDiaryService) : MyDiary.MyDiaryBase
|
|
||||||
{
|
|
||||||
public override async Task<EditReply> Edit(EditRequest request, ServerCallContext context)
|
|
||||||
{
|
|
||||||
logger.LogInformation($"接收到来自 {request.UserId} 的请求");
|
|
||||||
|
|
||||||
var myDiary = new Model.MyDiary()
|
|
||||||
{
|
|
||||||
Content = request.Content,
|
|
||||||
CreateTime = request.CreateTime.ToDateTime().ToLocalTime(),
|
|
||||||
UserId = request.UserId
|
|
||||||
};
|
|
||||||
|
|
||||||
var myDiaryToday = await myDiaryService.Queryable()
|
|
||||||
.Where(it => it.CreateTime.Date == myDiary.CreateTime.Date && it.UserId == myDiary.UserId)
|
|
||||||
.FirstAsync();
|
|
||||||
if (myDiaryToday != null)
|
|
||||||
{
|
|
||||||
myDiaryToday.Content = myDiary.Content;
|
|
||||||
await myDiaryService.Updateable(myDiaryToday)
|
|
||||||
.ExecuteCommandAsync();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
await myDiaryService.Insertable(myDiary).ExecuteReturnSnowflakeIdAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 构建并返回回复消息
|
|
||||||
var reply = new EditReply()
|
|
||||||
{
|
|
||||||
ResultMessage = $"日记已记录 来自 gRPC 服务器!"
|
|
||||||
};
|
|
||||||
|
|
||||||
logger.LogInformation($"日记已记录");
|
|
||||||
|
|
||||||
// 返回一个 Task<HelloReply>
|
|
||||||
return reply;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task<QueryReply> Query(QueryRequest request, ServerCallContext context)
|
|
||||||
{
|
|
||||||
logger.LogInformation($"接收到来自 {request.UserId} 的请求");
|
|
||||||
|
|
||||||
var myDiary = new Model.MyDiary()
|
|
||||||
{
|
|
||||||
CreateTime = request.CreateTime.ToDateTime().ToLocalTime(),
|
|
||||||
UserId = request.UserId
|
|
||||||
};
|
|
||||||
|
|
||||||
var myDiaryToday = await myDiaryService.Queryable()
|
|
||||||
.Where(it => it.CreateTime.Date == myDiary.CreateTime.Date && it.UserId == myDiary.UserId)
|
|
||||||
.FirstAsync();
|
|
||||||
|
|
||||||
if (myDiaryToday != null)
|
|
||||||
{
|
|
||||||
myDiary.Content = myDiaryToday.Content;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 构建并返回回复消息
|
|
||||||
var reply = new QueryReply()
|
|
||||||
{
|
|
||||||
Content = myDiary.Content ?? ""
|
|
||||||
};
|
|
||||||
|
|
||||||
return reply;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,28 +1,22 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Remove="Services\FileTransferService.cs" />
|
<Protobuf Include="Protos\greet.proto" GrpcServices="Both"/>
|
||||||
|
<Protobuf Include="Protos\block.proto" GrpcServices="Client"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Protobuf Include="Protos\greet.proto" GrpcServices="Both" />
|
<PackageReference Include="Grpc.AspNetCore" Version="2.49.0"/>
|
||||||
<Protobuf Include="Protos\block.proto" GrpcServices="Client" />
|
|
||||||
<Protobuf Include="Protos\my_diary.proto" GrpcServices="Server" />
|
|
||||||
<Protobuf Include="Protos\FileTransfer.proto" GrpcServices="Server" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Grpc.AspNetCore" Version="2.49.0" />
|
<Folder Include="Services\" />
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\ZR.Service\ZR.Service.csproj" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
using NLog;
|
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using ZR.Admin.WebApi.Filters;
|
using ZR.Admin.WebApi.Filters;
|
||||||
using ZR.ServiceCore.Model;
|
using ZR.ServiceCore.Model;
|
||||||
@ -25,8 +24,6 @@ namespace ZR.Admin.WebApi.Controllers
|
|||||||
_sysFileService = sysFileService;
|
_sysFileService = sysFileService;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查询文件存储列表
|
/// 查询文件存储列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -132,44 +129,5 @@ namespace ZR.Admin.WebApi.Controllers
|
|||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 通过文件ID下载文件
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="fileId"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet("download/{fileId}")]
|
|
||||||
public IActionResult Download([FromRoute] long fileId)
|
|
||||||
{
|
|
||||||
var sysFile = _sysFileService.Queryable().Where(it => it.Id == fileId).First();
|
|
||||||
if (sysFile == null)
|
|
||||||
{
|
|
||||||
throw new CustomException("服务器上不存在此文件");
|
|
||||||
}
|
|
||||||
|
|
||||||
Stream? stream;
|
|
||||||
switch ((StoreType)Enum.Parse(typeof(StoreType), sysFile.StoreType.ToString() ?? string.Empty))
|
|
||||||
{
|
|
||||||
case StoreType.LOCAL:
|
|
||||||
Logger.Info("本地存储");
|
|
||||||
stream = sysFile.IsEncrypted == "1" ? _sysFileService.DecryptSysFileStream(sysFile.FileUrl)
|
|
||||||
: new FileStream(sysFile.FileUrl, FileMode.Open);
|
|
||||||
break;
|
|
||||||
case StoreType.ALIYUN:
|
|
||||||
stream = AliyunOssHelper.DownloadFile(sysFile.FileUrl, "", sysFile.IsEncrypted == "1");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new CustomException("不支持的存储类型");
|
|
||||||
}
|
|
||||||
if (stream != null)
|
|
||||||
{
|
|
||||||
return new FileStreamResult(stream, "application/octet-stream")
|
|
||||||
{
|
|
||||||
FileDownloadName = sysFile.RealName
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return NoContent();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,15 +1,13 @@
|
|||||||
using AspNetCoreRateLimit;
|
using AspNetCoreRateLimit;
|
||||||
using Infrastructure.Converter;
|
using Infrastructure.Converter;
|
||||||
using Microsoft.AspNetCore.DataProtection;
|
using Microsoft.AspNetCore.DataProtection;
|
||||||
using Microsoft.AspNetCore.RateLimiting;
|
using NLog.Web;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
using System.Text.Json;
|
||||||
using Microsoft.Extensions.Caching.Distributed;
|
using Microsoft.Extensions.Caching.Distributed;
|
||||||
using Microsoft.Extensions.Caching.Redis;
|
using Microsoft.Extensions.Caching.Redis;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using NLog.Web;
|
|
||||||
using System.Text.Json;
|
|
||||||
using ZR.Admin.Grpc;
|
using ZR.Admin.Grpc;
|
||||||
using ZR.Admin.Grpc.Services;
|
using ZR.Admin.Grpc.Extensions;
|
||||||
using ZR.Admin.WebApi.Extensions;
|
using ZR.Admin.WebApi.Extensions;
|
||||||
using ZR.Infrastructure.Cache;
|
using ZR.Infrastructure.Cache;
|
||||||
using ZR.Infrastructure.WebExtensions;
|
using ZR.Infrastructure.WebExtensions;
|
||||||
@ -72,11 +70,7 @@ if (openRedis == "1")
|
|||||||
builder.Services.AddSingleton<IDistributedCache>(new CSRedisCache(RedisHelper.Instance));
|
builder.Services.AddSingleton<IDistributedCache>(new CSRedisCache(RedisHelper.Instance));
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.Services.AddRateLimiter(o => o
|
|
||||||
.AddFixedWindowLimiter(policyName: "fixed", options =>
|
|
||||||
{
|
|
||||||
// configuration
|
|
||||||
}));
|
|
||||||
|
|
||||||
builder.Services.AddMvc(options =>
|
builder.Services.AddMvc(options =>
|
||||||
{
|
{
|
||||||
@ -100,27 +94,15 @@ builder.Services.AddSignalR()
|
|||||||
options.PayloadSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
|
options.PayloadSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
|
||||||
});
|
});
|
||||||
builder.Services.AddSwaggerConfig();
|
builder.Services.AddSwaggerConfig();
|
||||||
//using var channel = GrpcChannel.ForAddress("https://localhost:7025");
|
// using var channel = GrpcChannel.ForAddress("https://localhost:7025");
|
||||||
//var client = new Greeter.GreeterClient(channel);
|
// var client = new Greeter.GreeterClient(channel);
|
||||||
//var reply = await client.SayHelloAsync(new HelloRequest { Name = "GreeterClient" });
|
// var reply = await client.SayHelloAsync(new HelloRequest { Name = "GreeterClient" });
|
||||||
//Console.WriteLine("Greeting: " + reply.Message);
|
// Console.WriteLine("Greeting: " + reply.Message);
|
||||||
//
|
//
|
||||||
// var blockClient = new Block.BlockClient(channel);
|
// var blockClient = new Block.BlockClient(channel);
|
||||||
// var blockReply = await blockClient.GetBlockAsync(new BlockRequest { In = "asads" });
|
// var blockReply = await blockClient.GetBlockAsync(new BlockRequest { In = "asads" });
|
||||||
// Console.WriteLine("BlockReply: " + blockReply.Out);
|
// Console.WriteLine("BlockReply: " + blockReply.Out);
|
||||||
//builder.Services.AddGrpcServiceConfiguration(builder.Configuration);
|
builder.Services.AddGrpcServiceConfiguration(builder.Configuration);
|
||||||
|
|
||||||
// 配置 Kestrel 监听 HTTP/2 的非加密流量
|
|
||||||
//builder.WebHost.ConfigureKestrel(options =>
|
|
||||||
//{
|
|
||||||
// // 如果你只想监听一个端口,只保留其中一个 Listen
|
|
||||||
// options.ListenLocalhost(8888, o =>
|
|
||||||
// {
|
|
||||||
// o.Protocols = HttpProtocols.Http2; // 明确设置为 Http2
|
|
||||||
// });
|
|
||||||
|
|
||||||
//});
|
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
InternalApp.ServiceProvider = app.Services;
|
InternalApp.ServiceProvider = app.Services;
|
||||||
InternalApp.Configuration = builder.Configuration;
|
InternalApp.Configuration = builder.Configuration;
|
||||||
@ -153,7 +135,7 @@ app.UseStaticFiles();
|
|||||||
//开启路由访问
|
//开启路由访问
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
app.UseCors("Policy");//要放在app.UseEndpoints前。
|
app.UseCors("Policy");//要放在app.UseEndpoints前。
|
||||||
app.UseHttpsRedirection();
|
//app.UseHttpsRedirection();
|
||||||
|
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
@ -200,15 +182,12 @@ using (var serviceScope = app.Services.CreateScope())
|
|||||||
pol.IpRules.AddRange(ipRateLimitPolicies.Adapt<List<IpRateLimitPolicy>>());
|
pol.IpRules.AddRange(ipRateLimitPolicies.Adapt<List<IpRateLimitPolicy>>());
|
||||||
await ipPolicyStore.SetAsync(optionsAccessor.Value.IpPolicyPrefix, pol);
|
await ipPolicyStore.SetAsync(optionsAccessor.Value.IpPolicyPrefix, pol);
|
||||||
|
|
||||||
//var greeterClient = services.GetRequiredService<Greeter.GreeterClient>();
|
// var greeterClient = services.GetRequiredService<Greeter.GreeterClient>();
|
||||||
//var helloReply = await greeterClient.SayHelloAsync(new HelloRequest
|
// var helloReply = await greeterClient.SayHelloAsync(new HelloRequest
|
||||||
//{
|
// {
|
||||||
// Name = "gree"
|
// Name = "gree"
|
||||||
//});
|
// });
|
||||||
//Console.WriteLine(helloReply);
|
// Console.WriteLine(helloReply);
|
||||||
}
|
}
|
||||||
|
|
||||||
app.MapGrpcService<GreeterService>();
|
|
||||||
app.MapGrpcService<MyDiaryService>();
|
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
@ -13,7 +13,7 @@
|
|||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"dotnetRunMessages": true,
|
"dotnetRunMessages": true,
|
||||||
"launchUrl": "",
|
"launchUrl": "",
|
||||||
"applicationUrl": "https://localhost:8888",
|
"applicationUrl": "http://localhost:8888",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
|
|||||||
@ -1,20 +0,0 @@
|
|||||||
{
|
|
||||||
"urls": "http://[*]:8888", //项目启动url,如果改动端口前端对应devServer也需要进行修改
|
|
||||||
"dbConfigs": [
|
|
||||||
{
|
|
||||||
"Conn": "server=8.140.174.251;user=admin;pwd=admin123;database=ZrAdmin",
|
|
||||||
"DbType": 0, //数据库类型 MySql = 0, SqlServer = 1, Oracle = 3,PgSql = 4
|
|
||||||
"ConfigId": "0", //多租户唯一标识
|
|
||||||
"IsAutoCloseConnection": true
|
|
||||||
}
|
|
||||||
//...下面添加更多的数据库源
|
|
||||||
],
|
|
||||||
//redis服务配置
|
|
||||||
"RedisServer": {
|
|
||||||
"open": 1, //是否启用redis
|
|
||||||
"Cache": "8.140.174.251:6379,password=Wyd210213,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=cache:",
|
|
||||||
// "Cache": "127.0.0.1:6379,password=Wyd210213,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=cache:",
|
|
||||||
"Session": "8.140.174.251:6379,password=Wyd210213,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=session:"
|
|
||||||
// "Session": "127.0.0.1:6379,password=Wyd210213,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=session:"
|
|
||||||
},
|
|
||||||
}
|
|
||||||
@ -8,7 +8,7 @@
|
|||||||
},
|
},
|
||||||
"dbConfigs": [
|
"dbConfigs": [
|
||||||
{
|
{
|
||||||
"Conn": "server=127.0.0.1;user=admin;pwd=admin123;database=ZrAdmin;port=3306",
|
"Conn": "server=8.140.174.251;user=admin;pwd=admin123;database=ZrAdmin;port=33060",
|
||||||
"DbType": 0, //数据库类型 MySql = 0, SqlServer = 1, Oracle = 3,PgSql = 4
|
"DbType": 0, //数据库类型 MySql = 0, SqlServer = 1, Oracle = 3,PgSql = 4
|
||||||
"ConfigId": "0", //多租户唯一标识
|
"ConfigId": "0", //多租户唯一标识
|
||||||
"IsAutoCloseConnection": true
|
"IsAutoCloseConnection": true
|
||||||
@ -18,26 +18,26 @@
|
|||||||
//代码生成数据库配置
|
//代码生成数据库配置
|
||||||
"CodeGenDbConfig": {
|
"CodeGenDbConfig": {
|
||||||
//代码生成连接字符串,注意{dbName}为固定格式,不要填写数据库名
|
//代码生成连接字符串,注意{dbName}为固定格式,不要填写数据库名
|
||||||
"Conn": "Data Source=127.0.0.1;user=admin;pwd=admin123;database=ZrAdmin;port=3306",
|
"Conn": "Data Source=LAPTOP-STKF2M8H\\SQLEXPRESS;User ID=admin;Password=admin123;Initial Catalog={dbName};",
|
||||||
"DbType": 0,
|
"DbType": 1,
|
||||||
"IsAutoCloseConnection": true,
|
"IsAutoCloseConnection": true,
|
||||||
"DbName": "ZrAdmin" //代码生成默认连接数据库,Oracle库是实例的名称
|
"DbName": "ZrAdmin" //代码生成默认连接数据库,Oracle库是实例的名称
|
||||||
},
|
},
|
||||||
"urls": "https://localhost:8888", //项目启动url,如果改动端口前端对应devServer也需要进行修改
|
"urls": "http://localhost:8888", //项目启动url,如果改动端口前端对应devServer也需要进行修改
|
||||||
"corsUrls": [ "http://localhost:8887", "http://localhost:8886" ], //跨域地址(前端启动项目,前后端分离单独部署需要设置),多个用","隔开
|
"corsUrls": [ "http://localhost:8887", "http://localhost:8886" ], //跨域地址(前端启动项目,前后端分离单独部署需要设置),多个用","隔开
|
||||||
"JwtSettings": {
|
"JwtSettings": {
|
||||||
"Issuer": "ZRAdmin.NET", //即token的签发者。
|
"Issuer": "ZRAdmin.NET", //即token的签发者。
|
||||||
"Audience": "ZRAdmin.NET", //指该token是服务于哪个群体的(群体范围)
|
"Audience": "ZRAdmin.NET", //指该token是服务于哪个群体的(群体范围)
|
||||||
"SecretKey": "SecretKey-ZRADMIN.NET-20210101",
|
"SecretKey": "SecretKey-ZRADMIN.NET-20210101",
|
||||||
"Expire": 1440, //jwt登录过期时间(分)
|
"Expire": 1440, //jwt登录过期时间(分)
|
||||||
"RefreshTokenTime": 5, //分钟
|
"RefreshTokenTime": 5,//分钟
|
||||||
"TokenType": "Bearer"
|
"TokenType": "Bearer"
|
||||||
},
|
},
|
||||||
"InjectClass": [ "ZR.Repository", "ZR.Service", "ZR.Tasks", "ZR.ServiceCore" ], //自动注入类
|
"InjectClass": [ "ZR.Repository", "ZR.Service", "ZR.Tasks", "ZR.ServiceCore" ], //自动注入类
|
||||||
"ShowDbLog": true, //是否打印db日志
|
"ShowDbLog": true, //是否打印db日志
|
||||||
"InitDb": false, //是否初始化db
|
"InitDb": false, //是否初始化db
|
||||||
"DemoMode": false, //是否演示模式
|
"DemoMode": false, //是否演示模式
|
||||||
"SingleLogin": false, //是否单点登录
|
"SingleLogin": false,//是否单点登录
|
||||||
"Upload": {
|
"Upload": {
|
||||||
"uploadUrl": "http://localhost:8888", //本地存储资源访问路径
|
"uploadUrl": "http://localhost:8888", //本地存储资源访问路径
|
||||||
"localSavePath": "", //本地上传默认文件存储目录 wwwroot
|
"localSavePath": "", //本地上传默认文件存储目录 wwwroot
|
||||||
@ -102,8 +102,10 @@
|
|||||||
//redis服务配置
|
//redis服务配置
|
||||||
"RedisServer": {
|
"RedisServer": {
|
||||||
"open": 1, //是否启用redis
|
"open": 1, //是否启用redis
|
||||||
"Cache": "127.0.0.1:6379,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=cache:",
|
"Cache": "8.140.174.251:6379,password=Wyd210213,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=cache:",
|
||||||
"Session": "127.0.0.1:6379,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=session:"
|
// "Cache": "127.0.0.1:6379,password=Wyd210213,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=cache:",
|
||||||
|
"Session": "8.140.174.251:6379,password=Wyd210213,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=session:"
|
||||||
|
// "Session": "127.0.0.1:6379,password=Wyd210213,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=session:"
|
||||||
},
|
},
|
||||||
//验证码配置
|
//验证码配置
|
||||||
"CaptchaOptions": {
|
"CaptchaOptions": {
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -1,23 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ZR.Model
|
|
||||||
{
|
|
||||||
[SugarTable("my_diary")]
|
|
||||||
public class MyDiary
|
|
||||||
{
|
|
||||||
[SugarColumn(IsPrimaryKey = true)]
|
|
||||||
[JsonConverter(typeof(ValueToStringConverter))]
|
|
||||||
public long Id { get; set; }
|
|
||||||
|
|
||||||
public string Content { get; set; }
|
|
||||||
|
|
||||||
[JsonConverter(typeof(ValueToStringConverter))]
|
|
||||||
public long UserId { get; set; }
|
|
||||||
|
|
||||||
public DateTime CreateTime { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
<NoWarn>1701;1702;1591;1570</NoWarn>
|
<NoWarn>1701;1702;1591;1570</NoWarn>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -1,14 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using ZR.Model;
|
|
||||||
|
|
||||||
namespace ZR.Service.IService
|
|
||||||
{
|
|
||||||
public interface IMyDiaryService : IBaseService<MyDiary>
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using ZR.Model;
|
|
||||||
using ZR.Service.IService;
|
|
||||||
|
|
||||||
namespace ZR.Service
|
|
||||||
{
|
|
||||||
[AppService(ServiceType = typeof(IMyDiaryService), ServiceLifetime = LifeTime.Transient)]
|
|
||||||
public class MyDiaryService : BaseService<MyDiary>, IMyDiaryService
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|||||||
@ -76,7 +76,7 @@ namespace ZR.Service
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public SysUser SelectUserById(long userId)
|
public SysUser SelectUserById(long userId)
|
||||||
{
|
{
|
||||||
var user = Queryable().Filter(null, true)
|
var user = Queryable().Filter(null, true).WithCache(60 * 5)
|
||||||
.Where(f => f.UserId == userId).First();
|
.Where(f => f.UserId == userId).First();
|
||||||
if (user != null && user.UserId > 0)
|
if (user != null && user.UserId > 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
<NoWarn>1701;1702;1591;1570</NoWarn>
|
<NoWarn>1701;1702;1591;1570</NoWarn>
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user