diff --git a/IRC.Core.SCP/Program.cs b/IRC.Core.SCP/Program.cs index b3d4a885c..544d38a4d 100644 --- a/IRC.Core.SCP/Program.cs +++ b/IRC.Core.SCP/Program.cs @@ -167,6 +167,9 @@ var app = builder.Build(); //app.UseSwaggerUI(); //} +//不需要 token 访问的静态文件 wwwroot css, JavaScript, and images don't require authentication. +app.UseStaticFiles(); + SwaggerSetup.Configure(app, app.Environment); app.UseAuthorization(); diff --git a/IRC.Core.SCP/Service/PatientStudyService.cs b/IRC.Core.SCP/Service/PatientStudyService.cs index 8b817ae22..f55b93ebc 100644 --- a/IRC.Core.SCP/Service/PatientStudyService.cs +++ b/IRC.Core.SCP/Service/PatientStudyService.cs @@ -1,19 +1,22 @@ -using IRaCIS.Core.Domain.Share; -using System.Text; -using Microsoft.AspNetCore.Hosting; -using IRaCIS.Core.Infrastructure; -using Medallion.Threading; -using FellowOakDicom; +using FellowOakDicom; +using FellowOakDicom.Imaging; using FellowOakDicom.Imaging.Codec; -using System.Data; -using IRaCIS.Core.Domain.Models; using FellowOakDicom.Network; -using IRaCIS.Core.SCP.Service; +using IRaCIS.Core.Domain.Models; +using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Infra.EFCore; -using MassTransit; -using Microsoft.AspNetCore.Mvc; +using IRaCIS.Core.Infrastructure; using IRaCIS.Core.Infrastructure.Extention; +using IRaCIS.Core.SCP.Service; +using MassTransit; +using Medallion.Threading; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using SixLabors.ImageSharp.Formats.Jpeg; +using System.Data; +using System.Text; namespace IRaCIS.Core.SCP.Service { @@ -46,7 +49,53 @@ namespace IRaCIS.Core.SCP.Service _distributedLockProvider = distributedLockProvider; } + [AllowAnonymous] + public async Task TestImage(string folderPath) + { + if (!Directory.Exists(folderPath)) + return ResponseOutput.Ok("目录不存在"); + + // 获取所有 .dcm 文件 + var dicomFiles = Directory.GetFiles(folderPath); + + foreach (var fileFullPath in dicomFiles) + { + try + { + var file = await DicomFile.OpenAsync(fileFullPath); + + + // 生成缩略图 + using (var memoryStream = new MemoryStream()) + { + DicomImage image = new DicomImage(file.Dataset); + + var sharpimage = image.RenderImage().AsSharpImage(); + sharpimage.Save(memoryStream, new JpegEncoder()); + + + // 关键点:一定要回到开头 + memoryStream.Position = 0; + + using (var fileStream = File.Create($"{fileFullPath}.jpg")) + { + await memoryStream.CopyToAsync(fileStream); + } + + } + } + catch (Exception) + { + + continue; + } + } + + + + return ResponseOutput.Ok(); + } public class AuToBindingStudyInfo {