|
@@ -27,7 +27,7 @@ public class DefaultFileStorage : IFileStorage, IScopeDependency
|
|
|
/// <param name="fileData"></param>
|
|
|
/// <param name="client"></param>
|
|
|
/// <returns></returns>
|
|
|
- public FileMetadata Upload(string fileName, long length, string extraInfo, Stream fileData, string client)
|
|
|
+ public async Task<FileMetadata> UploadAsync(string fileName, long length, string extraInfo, Stream fileData, string client)
|
|
|
{
|
|
|
if (fileName == null)
|
|
|
{
|
|
@@ -53,7 +53,7 @@ public class DefaultFileStorage : IFileStorage, IScopeDependency
|
|
|
fileModel.SaveMode = _fileUploadOptions.Value.Impt;
|
|
|
fileModel.ExtraInfo = extraInfo;
|
|
|
fileModel.UploadTime = DateTime.Now;
|
|
|
- _fileMetadataRepository.AddAsync(fileModel);
|
|
|
+ await _fileMetadataRepository.AddAsync(fileModel);
|
|
|
return fileModel;
|
|
|
}
|
|
|
return null;
|
|
@@ -73,7 +73,20 @@ public class DefaultFileStorage : IFileStorage, IScopeDependency
|
|
|
throw new UserFriendlyException("无权限访问");
|
|
|
}
|
|
|
|
|
|
- public (Stream stream, string contentType,string fileName) DownLoadFile(string id,string clientId)
|
|
|
+ public async Task<Uri> GetFileUrlIndefinitely(string id, string clientId)
|
|
|
+ {
|
|
|
+ var fileMetadata = await _fileMetadataRepository.GetAsync(x => x.Id == id && x.Client == clientId);
|
|
|
+ if (fileMetadata != null)
|
|
|
+ {
|
|
|
+ long sTime = (long)(DateTime.Now.AddHours(1).ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds;
|
|
|
+ string encryptText = clientId + "|" + sTime + "|" + id;
|
|
|
+ var signatureText = DESExtensions.Encrypt(encryptText);
|
|
|
+ return new Uri(_fileUploadOptions.Value.Local.VisDomain + "file/files_indefinitely?id=" + id + "&expires=" + sTime + "&clientid=" + clientId + "&signature=" + signatureText);
|
|
|
+ }
|
|
|
+ throw new UserFriendlyException("无权限访问");
|
|
|
+ }
|
|
|
+
|
|
|
+ public (Stream stream, string contentType,string fileName) DownLoadFile(string id,string clientId)
|
|
|
{
|
|
|
var fileMetadata = _fileMetadataRepository.Get(x=>x.Id == id && x.Client == clientId);
|
|
|
if (fileMetadata!=null)
|
|
@@ -128,8 +141,27 @@ public class DefaultFileStorage : IFileStorage, IScopeDependency
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public async Task<string> GetFilePathIndefinitely(string id, string expires, string clientId, string signature)
|
|
|
+ {
|
|
|
+ string decryptText = DESExtensions.Decrypt(signature);
|
|
|
+ if (!string.IsNullOrEmpty(decryptText))
|
|
|
+ {
|
|
|
+ string[] paramData = decryptText.Split('|');
|
|
|
+
|
|
|
+ if (id != paramData[2] || clientId != paramData[0] || expires != paramData[1])
|
|
|
+ throw UserFriendlyException.SameMessage("参数不合法");
|
|
|
+
|
|
|
+ var fileMetadata = await _fileMetadataRepository.GetAsync(x => x.Id == id && x.Client == clientId);
|
|
|
+ if (fileMetadata == null)
|
|
|
+ throw UserFriendlyException.SameMessage("无权限访问");
|
|
|
+
|
|
|
+ return GetFullPath(fileMetadata.Path);
|
|
|
+ }
|
|
|
+ throw UserFriendlyException.SameMessage("无权限访问");
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
- private string TaskGetFileContentTypeAsync(string fileName)
|
|
|
+ private string TaskGetFileContentTypeAsync(string fileName)
|
|
|
{
|
|
|
string suffix = Path.GetExtension(fileName);
|
|
|
var provider = new FileExtensionContentTypeProvider();
|