public async Task <ProjectFileDto> GetFileForProject(string projectName, string version, string filePath) { var projectId = await _context.DocumentationProjects .Where(p => p.Name == projectName) .Select(p => new { p.Id }) .FirstOrDefaultAsync(); if (projectId == null) { return(null); } var versionId = await _context.DocumentationProjectVersions .Where(v => v.ProjectName == projectName && v.Version == version) .Select(v => new { v.FileId }) .FirstOrDefaultAsync(); if (versionId == null) { return(null); } var blobFilePath = GetFilePath(projectId.Id, versionId.FileId, filePath); var fileResult = await _fileManager.GetFileAsync(AppConstants.PROJECTS_CONTAINER, blobFilePath); if (!fileResult.IsSuccess) { return(null); } return(new ProjectFileDto { MimeType = GetMimeTypeForFilePath(filePath), FileStream = fileResult.Value }); }
private async Task <ProjectFileDto> GetFileFromZipArchive(string archivePath, string filePath) { var mimeType = GetMimeTypeForFilePath(filePath); var memoryStream = new MemoryStream(); var repoResult = await _fileManager.GetFileAsync(AppConstants.PROJECTS_CONTAINER, archivePath); if (!repoResult.IsSuccess) { return(null); } using (var fileStream = repoResult.Value) { using (var zipArchive = new ZipArchive(fileStream)) { var fileEntry = zipArchive.Entries.FirstOrDefault(e => e.FullName.Replace('/', '\\') == filePath.Replace('/', '\\')); if (fileEntry == null) { return(null); } var zipEntryStream = fileEntry.Open(); await zipEntryStream.CopyToAsync(memoryStream); } } memoryStream.Position = 0; return(new ProjectFileDto { MimeType = mimeType, FileStream = memoryStream }); }