示例#1
0
 public PathService(
     APIConnection connection,
     MetadataAuditLogStore auditLogStore,
     ViewSetService viewSetService,
     ModuleConfigurator moduleConfigurator,
     ManagerConfiguration managerConfiguration,
     FileService fileService
     ) : base(connection)
 {
     this.auditLogStore        = auditLogStore;
     this.viewSetService       = viewSetService;
     this.moduleConfigurator   = moduleConfigurator;
     this.ManagerConfiguration = managerConfiguration;
     this.fileService          = fileService;
 }
示例#2
0
        public ManagerFileModel ModelConvert(OrganizationModel organization, FileModel fileModel, string userTimeZone, List <IModule> activeModules = null, PathIdentifier virtualPathIdentifier = null, List <AttributeLocator> attributeLocators = null)
        {
            var shareStateIcon = EDiscoveryUtility.GetShareStateIcon(fileModel);
            var earrStateIcon  = EArraignment.GetEArrainmentStateIcon(fileModel);

            var pathIdentifier = fileModel.MetaPathIdentifierRead();

            if (virtualPathIdentifier != null)
            {
                pathIdentifier = virtualPathIdentifier;
            }

            var managerFileModel = new ManagerFileModel
            {
                Identifier        = fileModel.Identifier,
                Name              = fileModel.Name,
                Length            = fileModel.Length,
                LengthForHumans   = fileModel.LengthForHumans,
                Created           = fileModel.Created.ConvertToLocal(userTimeZone),
                Modified          = fileModel.Modified.ConvertToLocal(userTimeZone),
                Views             = ViewSetService.DetectFileViews(organization, fileModel),
                AllowedOperations = GetOperations(fileModel, pathIdentifier, activeModules, virtualPathIdentifier),
                PathIdentifier    = pathIdentifier
            };

            var alternativeViews = fileModel.Read <List <AlternativeView> >(MetadataKeyConstants.ALTERNATIVE_VIEWS);
            // this should probably be using the mediaservices somehow
            var thumbnail = alternativeViews
                            ?.FirstOrDefault(v =>
                                             v.SizeType == "Thumbnail" ||
                                             (v.SizeType == null &&
                                              v.ImageFormat == ImageFormatEnum.PNG &&
                                              v.Height == 100) // there was a period where SizeType was missing
                                             );

            managerFileModel.PreviewImageIdentifier = thumbnail?.FileIdentifier;

            // Now we need to build up the attributes on the file.
            // First we need to get the index from the folder.
            managerFileModel.Attributes = new Dictionary <string, object>();
            if (attributeLocators != null)
            {
                foreach (var attributeLocator in attributeLocators)
                {
                    if (attributeLocator.IsOnDetailView)
                    {
                        // This attribute locator points to a potential attribute that should exist on the file.
                        // figure out if this attribute is actually defined on the file.
                        var storageType    = Type.GetType(attributeLocator.GetTypeNameFromStorageType());
                        var attributeValue = fileModel.Read(storageType, attributeLocator.Key);
                        if (attributeValue != null)
                        {
                            managerFileModel.Attributes.Add(attributeLocator.Label, attributeValue);
                        }
                    }
                }
            }

            // Now we need to add the hashes to our attributes as well.
            managerFileModel.Attributes.Add("MD5 Hash", ConvertFromBase64ToHex(fileModel.HashMD5));
            managerFileModel.Attributes.Add("SHA1 Hash", ConvertFromBase64ToHex(fileModel.HashSHA1));
            managerFileModel.Attributes.Add("SHA256 Hash", ConvertFromBase64ToHex(fileModel.HashSHA256));

            var defaultView = managerFileModel.Views.FirstOrDefault();

            managerFileModel.ViewerType = defaultView?.ViewerType ?? ManagerFileView.ViewerTypeEnum.Unknown;

            var icons = defaultView?.Icons.ToList() ?? new List <string>();

            icons.Add(shareStateIcon);
            icons.Add(earrStateIcon);

            managerFileModel.Icons = icons.Where(i => i != null).ToList();

            return(managerFileModel);
        }
示例#3
0
        public async Task <SearchResponse> SearchAsync(OrganizationModel organization, Manager.Models.Requests.SearchRequest request)
        {
            var searchConfiguration = organization.Read <SearchConfiguration>("searchConfiguration");

            if (request.Filters?.Any() ?? false)
            {
                request.Filters = request.Filters.Select(f =>
                {
                    if (f.Name == "pathKey")
                    {
                        f.Name = "_path";
                    }

                    return(f);
                }).ToList();
            }

            var results = await Connection.Search.SearchAsync(
                searchRequest : new SearchRequest
            {
                OrganizationIdentifier = organization.Identifier,
                FolderIdentifier       = request.FolderIdentifier,
                KeywordQuery           = request.Keyword,
                Filters = request.Filters?.Select(ff => new API.Common.Models.Search.Filter
                {
                    Name  = ff.Name,
                    Value = ff.Value
                }),
                Paging = request.Paging ?? new PagingArguments
                {
                    PageIndex = 0,
                    PageSize  = 500
                }
            }
                );


            var response = new SearchResponse
            {
                Rows = results.Rows.Select(f => {
                    var alternativeViews = f.Metadata?.Read <List <AlternativeView> >(MetadataKeyConstants.ALTERNATIVE_VIEWS);
                    var pathIdentifier   = f.Metadata?.MetaPathIdentifierRead(f.FileIdentifier as FolderIdentifier, dontThrow: true);

                    var result = new ManagerFileSearchResult
                    {
                        Identifier     = f.FileIdentifier,
                        PathIdentifier = pathIdentifier,

                        FullPath = pathIdentifier?.FullName,

                        Name  = f.Name,
                        Views = ViewSetService.DetectFileViews(
                            organization,
                            f.FileIdentifier,
                            f.Metadata.Read <List <AlternativeView> >(MetadataKeyConstants.ALTERNATIVE_VIEWS),
                            f.Extension,
                            f.MimeType
                            ),
                        Created  = f.Created,
                        Modified = f.Modified,

                        PreviewImageIdentifier = alternativeViews?.FirstOrDefault(v => v.SizeType == "Thumbnail")?.FileIdentifier,

                        Attributes = BuildAttributes(searchConfiguration, f),

                        Highlights = f.Highlights
                    };

                    result.ViewerType = result.Views.FirstOrDefault()?.ViewerType ?? Manager.Models.ManagerFileView.ViewerTypeEnum.Unknown;
                    result.Icons      = result.Views.FirstOrDefault()?.Icons;

                    return(result);
                }).ToList(), // if we don't ToList(), then deferred execution happens during the streaming, and you don't
                             // want to debug that again, trust me.

                TotalMatches = results.TotalMatches,

                Facets = DecorateFacets(searchConfiguration, results.Facets)
            };

            return(response);
        }
示例#4
0
        public async Task DownloadZip(
            string fileName,
            IEnumerable <FileIdentifier> fileIdentifiers,
            HttpResponse response,
            Func <FileModel, PathIdentifier> pathGenerator = null,
            CancellationToken cancellationToken            = default(CancellationToken)
            )
        {
            if (pathGenerator == null)
            {
                pathGenerator = APIModelExtensions.MetaPathIdentifierRead;
            }

            response.StatusCode  = 200;
            response.ContentType = "application/zip";
            var contentDisposition = new ContentDispositionHeaderValue("attachment");

            contentDisposition.SetHttpFileName(fileName);
            response.Headers[HeaderNames.ContentDisposition] = contentDisposition.ToString();

            var isEDiscoveryUser           = EDiscoveryUtility.IsUserEDiscovery(Connection.UserAccessIdentifiers);
            OrganizationModel organization = null;

            using (var archive = new ZipArchive(response.Body, ZipArchiveMode.Create))
            {
                foreach (var fileIdentifier in fileIdentifiers)
                {
                    if (organization == null || organization.Identifier.OrganizationKey != fileIdentifier.OrganizationKey)
                    {
                        organization = await Connection.Organization.GetAsync(fileIdentifier as OrganizationIdentifier);
                    }

                    var fileModel = await Connection.File.GetAsync(fileIdentifier);

                    var views = ViewSetService.DetectFileViews(organization, fileModel);

                    var newFileExtension       = null as string;
                    var contentsFileIdentifier = fileIdentifier;

                    if (views.Any())
                    {
                        var first = views.First();
                        switch (first.ViewerType)
                        {
                        case ManagerFileView.ViewerTypeEnum.Video:
                            var mediaSet = await viewSetService.LoadSet <MediaSet>(fileIdentifier);

                            var mp4 = mediaSet.Sources.FirstOrDefault(s => s.Type == "video/mp4");
                            if (mp4 != null)
                            {
                                newFileExtension       = "mp4";
                                contentsFileIdentifier = mp4.FileIdentifier;
                            }

                            break;

                        case ManagerFileView.ViewerTypeEnum.Document:

                            if (fileModel.Extension == "docx")
                            {
                                var documentSet = await viewSetService.LoadSet <DocumentSet>(fileIdentifier);

                                var pdf = documentSet.FileIdentifier;
                                if (pdf != null)
                                {
                                    newFileExtension       = "pdf";
                                    contentsFileIdentifier = pdf;
                                }
                            }
                            break;
                        }
                    }


                    var path = pathGenerator(fileModel);

                    string name = fileModel.Name;
                    if (newFileExtension != null)
                    {
                        name = $"{Path.GetFileNameWithoutExtension(name)}.{newFileExtension}";
                    }
                    else
                    {
                        newFileExtension = fileModel.Extension;
                    }

                    name = MakeFilenameSafe(name);

                    var filename = path != null
                        ? Path.Combine(path.PathKey, name)
                        : name;

                    var entry = archive.CreateEntry(filename);

                    using (var fileStream = entry.Open())
                    {
                        await Connection.File.DownloadAsync(
                            contentsFileIdentifier,
                            onStreamAvailable : async(stream, cancel) =>
                        {
                            if (isEDiscoveryUser && WatermarkFilter.IsSupportedFileType(newFileExtension))
                            {
                                var packageName = fileModel.Read <string>(
                                    MetadataKeyConstants.E_DISCOVERY_SHARE_PACKGAGE);

                                var watermarkUser = await Connection.User.GetAsync(Connection.UserIdentifier);

                                // this code is redundant with FileService.ExecuteDownload
                                await WatermarkFilter.Execute(stream,
                                                              fileStream,
                                                              newFileExtension,
                                                              $"Defense {packageName} {watermarkUser.EmailAddress}"
                                                              );
                            }
                            else
                            {
                                await stream.CopyToAsync(fileStream);
                            }
                        },

                            cancellationToken : cancellationToken
                            );
                    }
                }
            }
        }
示例#5
0
 public ClipService(APIConnection connection, ViewSetService viewSetService) : base(connection)
 {
     this.ViewSetService = viewSetService;
 }
示例#6
0
 public TranscriptService(APIConnection connection, ViewSetService viewSetService) : base(connection)
 {
     this.ViewSetService = viewSetService;
 }