|
@@ -0,0 +1,64 @@
|
|
|
+using Google.Protobuf.WellKnownTypes;
|
|
|
+using Grpc.Core;
|
|
|
+using Grpc.Extension.Abstract;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using TEAMModelGrpc.Models;
|
|
|
+using TEAMModelOS.SDK.Module.AzureBlob.Interfaces;
|
|
|
+
|
|
|
+namespace TEAMModelGrpc.Services
|
|
|
+{
|
|
|
+ public class BlobSASService : IGrpcService
|
|
|
+ {
|
|
|
+
|
|
|
+ private readonly IAzureBlobDBRepository _azureBlobDBRepository;
|
|
|
+
|
|
|
+ public BlobSASService(IAzureBlobDBRepository azureBlobDBRepository)
|
|
|
+ {
|
|
|
+ _azureBlobDBRepository = azureBlobDBRepository;
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task<BlobSASDto> GetContainerSasUri(Empty empty, ServerCallContext context) {
|
|
|
+ (string, string) aaa = _azureBlobDBRepository.GetContainerSasUri();
|
|
|
+ BlobSASDto blobSASDto = new BlobSASDto();
|
|
|
+ blobSASDto.Url = aaa.Item1;
|
|
|
+ blobSASDto.SAS = aaa.Item2;
|
|
|
+ return blobSASDto;
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task<BlobSASDto> GetContainerSASRead(BlobSASDto blob, ServerCallContext context)
|
|
|
+ {
|
|
|
+ (string, string) a = BlobUrlString(blob.Url);
|
|
|
+ string ContainerName = a.Item1;
|
|
|
+ string BlobName = a.Item2;
|
|
|
+ bool flg = IsBlobName(BlobName);
|
|
|
+ if (flg)
|
|
|
+ {
|
|
|
+ string SAS = _azureBlobDBRepository.GetBlobSasUriRead(ContainerName, BlobName);
|
|
|
+ return new BlobSASDto { Url = SAS };
|
|
|
+ }
|
|
|
+ else throw new Exception();
|
|
|
+ //return responseBuilder.Error(false, ResponseCode.PARAMS_ERROR, "文件名错误").build();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private static (string, string) BlobUrlString(string sasUrl)
|
|
|
+ {
|
|
|
+ sasUrl = sasUrl.Substring(8);
|
|
|
+ string[] sasUrls = sasUrl.Split("/");
|
|
|
+ string ContainerName;
|
|
|
+ ContainerName = sasUrls[1].Clone().ToString();
|
|
|
+ string item = sasUrls[0] + "/" + sasUrls[1] + "/";
|
|
|
+ string blob = sasUrl.Replace(item, "");
|
|
|
+ return (ContainerName, blob);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static bool IsBlobName(string BlobName)
|
|
|
+ {
|
|
|
+ return System.Text.RegularExpressions.Regex.IsMatch(BlobName,
|
|
|
+ @"(?!((^(con)$)|^(con)\\..*|(^(prn)$)|^(prn)\\..*|(^(aux)$)|^(aux)\\..*|(^(nul)$)|^(nul)\\..*|(^(com)[1-9]$)|^(com)[1-9]\\..*|(^(lpt)[1-9]$)|^(lpt)[1-9]\\..*)|^\\s+|.*\\s$)(^[^\\\\\\:\\<\\>\\*\\?\\\\\\""\\\\|]{1,255}$)");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|