public async Task <IActionResult> GenerateLink(int id) { var cuser = await GetCurrentUserAsync(); var fileinfo = await ApiService.ViewOneFileAsync(id); if (fileinfo.File == null) { return(NotFound()); } var bucketInfo = await ApiService.ViewBucketDetailAsync(fileinfo.File.BucketId); var app = await _dbContext.Apps.FindAsync(bucketInfo.BelongingAppId); if (bucketInfo.BelongingAppId != app.AppId) { return(Unauthorized()); } var secret = await SecretService.GenerateAsync(id, await AppsContainer.AccessToken(app.AppId, app.AppSecret)()); var model = new GenerateLinkViewModel(cuser) { Address = secret.Value, BucketId = bucketInfo.BucketId }; return(View(model)); }
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}" })); }
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> ViewLink(GenerateViewModel input) // file Id { var cuser = await GetCurrentUserAsync(); var fileinfo = await _ossApiService.ViewOneFileAsync(input.FileId); if (fileinfo.File == null) { return(NotFound()); } var bucketInfo = await _ossApiService.ViewBucketDetailAsync(fileinfo.File.BucketId); var app = await _dbContext.Apps.FindAsync(bucketInfo.BelongingAppId); var secret = await _secretService.GenerateAsync(input.FileId, await _appsContainer.AccessToken(app.AppId, app.AppSecret), input.AccessTimes); var model = new ViewLinkViewModel(cuser) { Address = secret.Value, BucketId = bucketInfo.BucketId }; return(View(model)); }