public async Task <IActionResult> FileDownloadAddress(FileDownloadAddressAddressModel model) { var record = await _dbContext .FileRecords .Include(t => t.Conversation) .SingleOrDefaultAsync(t => t.FileKey == model.FileKey); if (record?.Conversation == null) { return(this.Protocol(ErrorType.NotFound, "无法找到这个文件!")); } var user = await _userManager.GetUserAsync(User); if (!await _dbContext.VerifyJoined(user.Id, record.Conversation)) { return(this.Protocol(ErrorType.Unauthorized, $"您在这个会话中没有下载文件的权限: {record.Conversation.Id}!")); } var secret = await _secretService.GenerateAsync(record.FileKey, await _appsContainer.AccessToken(), 1); return(this.ChatJson(new FileDownloadAddressViewModel { Code = ErrorType.Success, Message = "成功的生成了文件下载链接!", FileName = record.SourceName, DownloadPath = $"{_serviceLocation.OSS}/Download/FromSecret?Sec={secret.Value}&sd=true&name={record.SourceName}" })); }
public async Task <IActionResult> FileDownloadAddress(FileDownloadAddressAddressModel model) { var record = await _dbContext .FileRecords .Include(t => t.Conversation) .SingleOrDefaultAsync(t => t.FileKey == model.FileKey); if (record?.Conversation == null) { return(this.Protocol(ErrorType.NotFound, "Could not find your file! It might be time out!")); } var user = await GetKahlaUser(); if (!await _dbContext.VerifyJoined(user.Id, record.Conversation)) { return(this.Protocol(ErrorType.Unauthorized, $"You are not authorized to download file from conversation: {record.Conversation.Id}!")); } var secret = await _secretService.GenerateAsync(record.FileKey, await _appsContainer.AccessToken(), 1); return(this.AiurJson(new FileDownloadAddressViewModel { Code = ErrorType.Success, Message = "Successfully generated your file download address!", FileName = record.SourceName, DownloadPath = $"{_serviceLocation.OSS}/Download/FromSecret?Sec={secret.Value}&sd=true&name={record.SourceName}" })); }