/// <summary>
        /// 获取指定前缀的文件列表
        /// </summary>
        /// <param name="filter">筛选</param>
        /// <returns></returns>
        public ListFileItemResultDto ListFiles(ListFileFilter filter)
        {
            new ListFileFilterValidator().Validate(filter).Check(HttpStatus.Err.Name);
            var listRet = base.GetBucketManager(filter.PersistentOps).ListFiles(
                Core.Tools.GetBucket(QiNiuConfig, filter.PersistentOps.Bucket), filter.Prefix, filter.Marker,
                filter.PageSize,
                filter.Delimiter);

            if (listRet.Code == (int)HttpCode.OK)
            {
                return(new ListFileItemResultDto(true, "success")
                {
                    CommonPrefixes = listRet.Result.CommonPrefixes,
                    Marker = listRet.Result.Marker,
                    Items = listRet.Result.Items.Select(x => new FileInfoDto(true, "success")
                    {
                        Key = x.Key,
                        Hash = filter.IsShowHash ? x.Hash : "",
                        Size = x.Fsize,
                        PutTime = x.PutTime,
                        MimeType = x.MimeType,
                        FileType = Configuration.Ioc.Plugs.Storage.Enumerations.StorageClass
                                   .FromValue <EInfrastructure.Core.Configuration.Ioc.Plugs.Storage.Enumerations.StorageClass>(
                            x.FileType),
                    }).ToList()
                });
            }

            return(new ListFileItemResultDto(false, "lose"));
        }
 /// <summary>
 /// 获取指定前缀的文件列表
 /// </summary>
 /// <param name="filter">筛选</param>
 /// <returns></returns>
 public ListFileItemResultDto ListFiles(ListFileFilter filter)
 {
     throw new NotImplementedException();
 }
예제 #3
0
        /// <summary>
        /// 获取指定前缀的文件列表
        /// </summary>
        /// <param name="filter">筛选</param>
        /// <returns></returns>
        public ListFileItemResultDto ListFiles(ListFileFilter filter)
        {
            return(ToolCommon.GetResponse(() =>
            {
                new ListFileFilterValidator().Validate(filter).Check(HttpStatus.Err.Name);
                var zone = Core.Tools.GetZone(_aLiYunConfig, filter.PersistentOps.Zone, () => ZoneEnum.HangZhou);
                var client = _aLiYunConfig.GetClient(zone);
                var bucket = Core.Tools.GetBucket(_aLiYunConfig, filter.PersistentOps.Bucket);
                var listObjectsRequest = new ListObjectsRequest(bucket)
                {
                    MaxKeys = filter.PageSize
                };
                if (!string.IsNullOrEmpty(filter.Delimiter))
                {
                    listObjectsRequest.Delimiter = filter.Delimiter;
                }

                if (!string.IsNullOrEmpty(filter.Marker))
                {
                    listObjectsRequest.Marker = filter.Marker;
                }

                if (!string.IsNullOrEmpty(filter.Prefix))
                {
                    listObjectsRequest.Prefix = filter.Prefix;
                }

                var ret = client.ListObjects(listObjectsRequest);
                if (ret.HttpStatusCode == HttpStatusCode.OK)
                {
                    var list = new ListFileItemResultDto(true, "success")
                    {
                        CommonPrefixes = ret.CommonPrefixes?.ToList() ?? new List <string>(),
                        Marker = ret.NextMarker,
                        Items = ret.ObjectSummaries.Select(x => new FileInfoDto(true, "success")
                        {
                            Key = x.Key,
                            Hash = "",
                            Size = x.Size,
                            PutTime = x.LastModified.ToUnixTimestamp(TimestampType.Millisecond),
                            MimeType = "",
                            FileType = Core.Tools.GetStorageClass(x.StorageClass),
                        }).ToList()
                    };

                    if (filter.IsShowHash)
                    {
                        var fileList = GetList(new GetFileRangeParam(list.Items.Select(x => x.Key).ToList(),
                                                                     filter.PersistentOps));
                        list.Items.ForEach(item =>
                        {
                            var fileInfo = fileList.FirstOrDefault(x => x.Key == item.Key);
                            if (fileInfo != null)
                            {
                                item.Hash = fileInfo.Hash;
                            }
                        });
                    }

                    return list;
                }

                return new ListFileItemResultDto(false,
                                                 $"RequestId:{ret.RequestId},HttpStatusCode:{ret.HttpStatusCode}");
            }, message => new ListFileItemResultDto(false,
                                                    message)));
        }