diff --git a/AliyunOSSSDK.xcodeproj/project.pbxproj b/AliyunOSSSDK.xcodeproj/project.pbxproj index 6f50b1a..96c23e1 100644 --- a/AliyunOSSSDK.xcodeproj/project.pbxproj +++ b/AliyunOSSSDK.xcodeproj/project.pbxproj @@ -8,6 +8,14 @@ /* Begin PBXBuildFile section */ 4CEF14F81F5522A1007010B8 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 216256EF1CF1B1580086458F /* SystemConfiguration.framework */; }; + 5423CD292845F647005B4BCE /* OSSGetBucketV2Request.h in Headers */ = {isa = PBXBuildFile; fileRef = 5423CD272845F647005B4BCE /* OSSGetBucketV2Request.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 5423CD2A2845F647005B4BCE /* OSSGetBucketV2Request.h in Headers */ = {isa = PBXBuildFile; fileRef = 5423CD272845F647005B4BCE /* OSSGetBucketV2Request.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 5423CD2B2845F647005B4BCE /* OSSGetBucketV2Request.m in Sources */ = {isa = PBXBuildFile; fileRef = 5423CD282845F647005B4BCE /* OSSGetBucketV2Request.m */; }; + 5423CD2C2845F647005B4BCE /* OSSGetBucketV2Request.m in Sources */ = {isa = PBXBuildFile; fileRef = 5423CD282845F647005B4BCE /* OSSGetBucketV2Request.m */; }; + 5423CD2F2845F66E005B4BCE /* OSSGetBucketV2Result.h in Headers */ = {isa = PBXBuildFile; fileRef = 5423CD2D2845F66E005B4BCE /* OSSGetBucketV2Result.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 5423CD302845F66E005B4BCE /* OSSGetBucketV2Result.h in Headers */ = {isa = PBXBuildFile; fileRef = 5423CD2D2845F66E005B4BCE /* OSSGetBucketV2Result.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 5423CD312845F66E005B4BCE /* OSSGetBucketV2Result.m in Sources */ = {isa = PBXBuildFile; fileRef = 5423CD2E2845F66E005B4BCE /* OSSGetBucketV2Result.m */; }; + 5423CD322845F66E005B4BCE /* OSSGetBucketV2Result.m in Sources */ = {isa = PBXBuildFile; fileRef = 5423CD2E2845F66E005B4BCE /* OSSGetBucketV2Result.m */; }; D80C81F51FC824E2008E3900 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D80C81F41FC824D5008E3900 /* SystemConfiguration.framework */; }; D80C81F71FC824FF008E3900 /* CoreTelephony.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D80C81F61FC824FF008E3900 /* CoreTelephony.framework */; }; D80C81FB1FC82541008E3900 /* OSSModel.h in Headers */ = {isa = PBXBuildFile; fileRef = D87183091FC56358000DD9EC /* OSSModel.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -223,6 +231,10 @@ 216256EF1CF1B1580086458F /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; 4C7D8BB61F8CC70F005D3040 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; }; 4C7D8BB81F8CC741005D3040 /* CoreTelephony.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreTelephony.framework; path = System/Library/Frameworks/CoreTelephony.framework; sourceTree = SDKROOT; }; + 5423CD272845F647005B4BCE /* OSSGetBucketV2Request.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSSGetBucketV2Request.h; sourceTree = ""; }; + 5423CD282845F647005B4BCE /* OSSGetBucketV2Request.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSSGetBucketV2Request.m; sourceTree = ""; }; + 5423CD2D2845F66E005B4BCE /* OSSGetBucketV2Result.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSSGetBucketV2Result.h; sourceTree = ""; }; + 5423CD2E2845F66E005B4BCE /* OSSGetBucketV2Result.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSSGetBucketV2Result.m; sourceTree = ""; }; D80C81EC1FC824A8008E3900 /* AliyunOSSOSX.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = AliyunOSSOSX.framework; sourceTree = BUILT_PRODUCTS_DIR; }; D80C81F41FC824D5008E3900 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/SystemConfiguration.framework; sourceTree = DEVELOPER_DIR; }; D80C81F61FC824FF008E3900 /* CoreTelephony.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreTelephony.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/CoreTelephony.framework; sourceTree = DEVELOPER_DIR; }; @@ -464,6 +476,10 @@ D827B4162111A6E4003A24F6 /* OSSPutSymlinkRequest.m */, D827B42D2111ADE9003A24F6 /* OSSPutSymlinkResult.h */, D827B42E2111ADE9003A24F6 /* OSSPutSymlinkResult.m */, + 5423CD272845F647005B4BCE /* OSSGetBucketV2Request.h */, + 5423CD282845F647005B4BCE /* OSSGetBucketV2Request.m */, + 5423CD2D2845F66E005B4BCE /* OSSGetBucketV2Result.h */, + 5423CD2E2845F66E005B4BCE /* OSSGetBucketV2Result.m */, D85277E92015BBAD00D7B1DE /* OSSRequest.h */, D85277EA2015BBAD00D7B1DE /* OSSRequest.m */, D827B4212111A71B003A24F6 /* OSSRestoreObjectRequest.h */, @@ -547,6 +563,7 @@ D8C41B211FCC2FD20091699B /* OSSClient.h in Headers */, D8C41B231FCC2FD20091699B /* OSSHttpdns.h in Headers */, D8C41B241FCC2FD20091699B /* OSSNetworking.h in Headers */, + 5423CD292845F647005B4BCE /* OSSGetBucketV2Request.h in Headers */, D8C41B251FCC2FD20091699B /* OSSIPv6Adapter.h in Headers */, D8C41B2A1FCC2FD20091699B /* OSSIPv6PrefixResolver.h in Headers */, D8C41B2B1FCC2FD20091699B /* OSSDefine.h in Headers */, @@ -581,6 +598,7 @@ D827B41D2111A6FA003A24F6 /* OSSGetSymlinkRequest.h in Headers */, D827B4352111ADF7003A24F6 /* OSSGetSymlinkResult.h in Headers */, D8C2951220F46A79008A08AA /* OSSGetBucketInfoRequest.h in Headers */, + 5423CD2F2845F66E005B4BCE /* OSSGetBucketV2Result.h in Headers */, D8C2951820F46A95008A08AA /* OSSGetBucketInfoResult.h in Headers */, D827B40B21107169003A24F6 /* NSDate+OSS.h in Headers */, D8C41B411FCC2FD20091699B /* OSSFileLogger.h in Headers */, @@ -604,6 +622,7 @@ D80C82131FC82596008E3900 /* OSSIPv6Adapter.h in Headers */, D80C82051FC82567008E3900 /* OSSService.h in Headers */, D80C82041FC82562008E3900 /* OSSLog.h in Headers */, + 5423CD2A2845F647005B4BCE /* OSSGetBucketV2Request.h in Headers */, D80C82151FC8259C008E3900 /* OSSIPv6PrefixResolver.h in Headers */, D80C82061FC8256D008E3900 /* OSSLogMacros.h in Headers */, D80C82081FC82571008E3900 /* OSSReachability.h in Headers */, @@ -638,6 +657,7 @@ D827B4362111ADF7003A24F6 /* OSSGetSymlinkResult.h in Headers */, D8C2951320F46A79008A08AA /* OSSGetBucketInfoRequest.h in Headers */, D8C2951920F46A95008A08AA /* OSSGetBucketInfoResult.h in Headers */, + 5423CD302845F66E005B4BCE /* OSSGetBucketV2Result.h in Headers */, D80C88E8201B06CF00F379D8 /* OSSDeleteMultipleObjectsRequest.h in Headers */, D80C82011FC82559008E3900 /* OSSHttpdns.h in Headers */, D827B40C21107169003A24F6 /* NSDate+OSS.h in Headers */, @@ -809,6 +829,7 @@ D8C41AF71FCC2F920091699B /* OSSIPv6Adapter.m in Sources */, D827B4192111A6E4003A24F6 /* OSSPutSymlinkRequest.m in Sources */, D8C41AFA1FCC2F920091699B /* OSSCompat.m in Sources */, + 5423CD2B2845F647005B4BCE /* OSSGetBucketV2Request.m in Sources */, D8C41AFC1FCC2F920091699B /* OSSCancellationTokenRegistration.m in Sources */, D8C41AFD1FCC2F920091699B /* OSSBolts.m in Sources */, D8C41AFF1FCC2F920091699B /* OSSTaskCompletionSource.m in Sources */, @@ -823,6 +844,7 @@ D8C41B0A1FCC2F920091699B /* OSSXMLDictionary.m in Sources */, D827B41F2111A6FA003A24F6 /* OSSGetSymlinkRequest.m in Sources */, D852780C2015D59000D7B1DE /* OSSURLRequestRetryHandler.m in Sources */, + 5423CD312845F66E005B4BCE /* OSSGetBucketV2Result.m in Sources */, D85277ED2015BBAD00D7B1DE /* OSSRequest.m in Sources */, D827B4312111ADE9003A24F6 /* OSSPutSymlinkResult.m in Sources */, D827B41321114E4B003A24F6 /* NSMutableDictionary+OSS.m in Sources */, @@ -861,6 +883,7 @@ D8C41AB81FCC284F0091699B /* OSSIPv6Adapter.m in Sources */, D827B41A2111A6E4003A24F6 /* OSSPutSymlinkRequest.m in Sources */, D8C41ABB1FCC284F0091699B /* OSSCompat.m in Sources */, + 5423CD2C2845F647005B4BCE /* OSSGetBucketV2Request.m in Sources */, D8C41ABD1FCC284F0091699B /* OSSCancellationTokenRegistration.m in Sources */, D8C41ABE1FCC284F0091699B /* OSSBolts.m in Sources */, D8C41AC01FCC284F0091699B /* OSSTaskCompletionSource.m in Sources */, @@ -875,6 +898,7 @@ D8C41ACB1FCC28500091699B /* OSSXMLDictionary.m in Sources */, D827B4202111A6FA003A24F6 /* OSSGetSymlinkRequest.m in Sources */, D852780D2015D59000D7B1DE /* OSSURLRequestRetryHandler.m in Sources */, + 5423CD322845F66E005B4BCE /* OSSGetBucketV2Result.m in Sources */, D85277EE2015BBAD00D7B1DE /* OSSRequest.m in Sources */, D827B4322111ADE9003A24F6 /* OSSPutSymlinkResult.m in Sources */, D827B41421114E4B003A24F6 /* NSMutableDictionary+OSS.m in Sources */, diff --git a/AliyunOSSSDK/OSSAllRequestNeededMessage.m b/AliyunOSSSDK/OSSAllRequestNeededMessage.m index b114e26..cd7975c 100644 --- a/AliyunOSSSDK/OSSAllRequestNeededMessage.m +++ b/AliyunOSSSDK/OSSAllRequestNeededMessage.m @@ -46,7 +46,8 @@ - (OSSTask *)validateRequestParamsInOperationType:(OSSOperationType)operType { } if (!self.objectKey && - (operType != OSSOperationTypeGetBucket && operType != OSSOperationTypeCreateBucket + (operType != OSSOperationTypeGetBucket && operType != OSSOperationTypeGetBucketV2 + && operType != OSSOperationTypeCreateBucket && operType != OSSOperationTypeDeleteBucket && operType != OSSOperationTypeGetService && operType != OSSOperationTypeGetBucketACL&& operType != OSSOperationTypeDeleteMultipleObjects && operType != OSSOperationTypeListMultipartUploads diff --git a/AliyunOSSSDK/OSSClient.h b/AliyunOSSSDK/OSSClient.h index ac9a853..f005049 100644 --- a/AliyunOSSSDK/OSSClient.h +++ b/AliyunOSSSDK/OSSClient.h @@ -35,6 +35,7 @@ @class OSSPutSymlinkRequest; @class OSSGetSymlinkRequest; @class OSSRestoreObjectRequest; +@class OSSGetBucketV2Request; @class OSSTask; @class OSSExecutor; @@ -133,6 +134,12 @@ NS_ASSUME_NONNULL_BEGIN */ - (OSSTask *)getBucket:(OSSGetBucketRequest *)request; +/** + The corresponding RESTFul API: GetBucketV2 + Lists all objects in a bucket. It could be specified with filters such as prefix, marker, delimeter and max-keys. + */ +- (OSSTask *)getBucketV2:(OSSGetBucketV2Request *)request; + /** The corresponding RESTFul API: GetBucketInfo Gets the {@link Bucket}'s basic information as well as its ACL. diff --git a/AliyunOSSSDK/OSSClient.m b/AliyunOSSSDK/OSSClient.m index b30e221..79c3fb2 100644 --- a/AliyunOSSSDK/OSSClient.m +++ b/AliyunOSSSDK/OSSClient.m @@ -26,6 +26,7 @@ #import "OSSPutSymlinkRequest.h" #import "OSSGetSymlinkRequest.h" #import "OSSRestoreObjectRequest.h" +#import "OSSGetBucketV2Request.h"" static NSString * const kClientRecordNameWithCommonPrefix = @"oss_partInfos_storage_name"; static NSString * const kClientRecordNameWithCRC64Suffix = @"-crc64"; @@ -495,6 +496,23 @@ - (OSSTask *)getBucket:(OSSGetBucketRequest *)request { return [self invokeRequest:requestDelegate requireAuthentication:request.isAuthenticationRequired]; } +- (OSSTask *)getBucketV2:(OSSGetBucketV2Request *)request { + OSSNetworkingRequestDelegate * requestDelegate = request.requestDelegate; + + requestDelegate.responseParser = [[OSSHttpResponseParser alloc] initForOperationType:OSSOperationTypeGetBucketV2]; + + OSSAllRequestNeededMessage *neededMsg = [[OSSAllRequestNeededMessage alloc] init]; + neededMsg.endpoint = self.endpoint; + neededMsg.httpMethod = OSSHTTPMethodGET; + neededMsg.bucketName = request.bucketName; + neededMsg.params = request.requestParams; + requestDelegate.allNeededMessage = neededMsg; + + requestDelegate.operType = OSSOperationTypeGetBucketV2; + + return [self invokeRequest:requestDelegate requireAuthentication:request.isAuthenticationRequired]; +} + - (OSSTask *)getBucketInfo:(OSSGetBucketInfoRequest *)request { OSSNetworkingRequestDelegate * requestDelegate = request.requestDelegate; diff --git a/AliyunOSSSDK/OSSConstants.h b/AliyunOSSSDK/OSSConstants.h index aa044c7..4f17823 100644 --- a/AliyunOSSSDK/OSSConstants.h +++ b/AliyunOSSSDK/OSSConstants.h @@ -47,6 +47,7 @@ typedef NS_ENUM(NSInteger, OSSOperationType) { OSSOperationTypeCreateBucket, OSSOperationTypeDeleteBucket, OSSOperationTypeGetBucket, + OSSOperationTypeGetBucketV2, OSSOperationTypeGetBucketInfo, OSSOperationTypeGetBucketACL, OSSOperationTypeHeadObject, diff --git a/AliyunOSSSDK/OSSDefine.h b/AliyunOSSSDK/OSSDefine.h index d388f23..e351f9d 100644 --- a/AliyunOSSSDK/OSSDefine.h +++ b/AliyunOSSSDK/OSSDefine.h @@ -28,9 +28,11 @@ #define OSSUploadIdMarkerXMLTOKEN @"UploadIdMarker" #define OSSNextUploadIdMarkerXMLTOKEN @"NextUploadIdMarker" #define OSSMaxKeysXMLTOKEN @"MaxKeys" +#define OSSKeyCountXMLTOKEN @"KeyCount" #define OSSMaxUploadsXMLTOKEN @"MaxUploads" #define OSSIsTruncatedXMLTOKEN @"IsTruncated" #define OSSContentsXMLTOKEN @"Contents" +#define OSSNextContinuationTokenXMLTOKEN @"NextContinuationToken" #define OSSUploadXMLTOKEN @"Upload" #define OSSKeyXMLTOKEN @"Key" #define OSSLastModifiedXMLTOKEN @"LastModified" @@ -55,6 +57,15 @@ #define OSSPartXMLTOKEN @"Part" #define OSSPartNumberXMLTOKEN @"PartNumber" +#define OSSSubResourceListType @"list-type" +#define OSSSubResourceDelimiter @"delimiter" +#define OSSSubResourceStartAfter @"start-after" +#define OSSSubResourceContinuationToken @"continuation-token" +#define OSSSubResourceMaxKeys @"max-keys" +#define OSSSubResourcePrefix @"prefix" +#define OSSSubResourceEncodingType @"encoding-type" +#define OSSSubResourceFetchOwner @"fetch-owner" + #define OSSClientErrorDomain @"com.aliyun.oss.clientError" #define OSSServerErrorDomain @"com.aliyun.oss.serverError" diff --git a/AliyunOSSSDK/OSSGetBucketV2Request.h b/AliyunOSSSDK/OSSGetBucketV2Request.h new file mode 100644 index 0000000..d193883 --- /dev/null +++ b/AliyunOSSSDK/OSSGetBucketV2Request.h @@ -0,0 +1,48 @@ +// +// OSSListObjectsV2Request.h +// AliyunOSSSDK +// +// Created by ws on 2022/5/26. +// Copyright © 2022 aliyun. All rights reserved. +// + +#import "OSSRequest.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface OSSGetBucketV2Request : OSSRequest + +/** + Bucket name + */ +@property (nonatomic, copy) NSString *bucketName; + +/// Optional parameter indicating the encoding method to be applied on the +/// response. An object key can contain any Unicode character; however, XML +/// 1.0 parser cannot parse some characters, such as characters with an ASCII +/// value from 0 to 10. you can add this parameter to request that OSS encode the keys in the +/// response. +@property (nonatomic, copy) NSString *delimiter; + +/// Optional parameter indicating the maximum number of keys to include in the response. +@property (nonatomic, copy) NSString *encodingType; + +/// Optional parameter restricting the response to keys which begin with the specified prefix. +@property (nonatomic) NSInteger maxKeys; + +/// Optional parameter restricting the response to keys which begin with the specified prefix. +@property (nonatomic, copy) NSString *prefix; + +/// Optional parameter which allows list to be continued from a specific point. +/// ContinuationToken is provided in truncated list results. +@property (nonatomic, copy) NSString *continuationToken; + +/// The owner field is not present in ListObjectsV2 results by default. If this flag is set to true the owner field will be returned. +@property (nonatomic) BOOL fetchOwner; + +/// Optional parameter indicating where you want OSS to start the object listing from. +@property (nonatomic, copy) NSString *startAfter; + +@end + +NS_ASSUME_NONNULL_END diff --git a/AliyunOSSSDK/OSSGetBucketV2Request.m b/AliyunOSSSDK/OSSGetBucketV2Request.m new file mode 100644 index 0000000..ff47c52 --- /dev/null +++ b/AliyunOSSSDK/OSSGetBucketV2Request.m @@ -0,0 +1,38 @@ +// +// OSSListObjectsV2Request.m +// AliyunOSSSDK +// +// Created by ws on 2022/5/26. +// Copyright © 2022 aliyun. All rights reserved. +// + +#import "OSSGetBucketV2Request.h" +#import "NSMutableDictionary+OSS.h" +#import "OSSDefine.h" + +@implementation OSSGetBucketV2Request + +- (instancetype)init { + self = [super init]; + if (self) { + self.maxKeys = 100; + self.fetchOwner = NO; + } + return self; +} + +- (NSDictionary *)requestParams { + NSMutableDictionary *params = [NSMutableDictionary dictionary]; + [params oss_setObject:@"2" forKey:OSSSubResourceListType]; + [params oss_setObject:self.delimiter forKey:OSSSubResourceDelimiter]; + [params oss_setObject:self.startAfter forKey:OSSSubResourceStartAfter]; + [params oss_setObject:self.continuationToken forKey:OSSSubResourceContinuationToken]; + [params oss_setObject:[@(self.maxKeys) stringValue] forKey:OSSSubResourceMaxKeys]; + [params oss_setObject:self.prefix forKey:OSSSubResourcePrefix]; + [params oss_setObject:self.encodingType forKey:OSSSubResourceEncodingType]; + NSString *fetchOwner = self.fetchOwner ? @"true": @"false"; + [params oss_setObject:fetchOwner forKey:OSSSubResourceFetchOwner]; + return [params copy]; +} + +@end diff --git a/AliyunOSSSDK/OSSGetBucketV2Result.h b/AliyunOSSSDK/OSSGetBucketV2Result.h new file mode 100644 index 0000000..55dcf64 --- /dev/null +++ b/AliyunOSSSDK/OSSGetBucketV2Result.h @@ -0,0 +1,53 @@ +// +// OSSListObjectsV2Result.h +// AliyunOSSSDK +// +// Created by ws on 2022/5/26. +// Copyright © 2022 aliyun. All rights reserved. +// + +#import "OSSResult.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface OSSGetBucketV2Result : OSSResult + +/// A list of summary information describing the objects stored in the bucket +@property (nonatomic, copy, nullable) NSArray *contents; + +/// A list of the common prefixes included in this object listing - common prefixes will only be populated for requests that specified a delimiter +@property (nonatomic, copy) NSArray *commonPrefixes; + +/// The name of the bucket +@property (nonatomic, copy) NSString *bucketName; + +/// KeyCount is the number of keys returned with this response +@property (nonatomic) NSInteger keyCount; + +/// Optional parameter which allows list to be continued from a specific point. ContinuationToken is provided in truncated list results. +@property (nonatomic, copy) NSString *continuationToken; + +/// NextContinuationToken is sent when isTruncated is true meaning there are more keys in the bucket that can be listed. +@property (nonatomic, copy) NSString *nextContinuationToken; + +/// Optional parameter indicating where you want OSS to start the object listing from. This can be any key in the bucket. +@property (nonatomic, copy) NSString *startAfter; + +/// Indicates if this is a complete listing, or if the caller needs to make additional requests to OSS to see the full object listing. +@property (nonatomic) BOOL isTruncated; + +/// The prefix parameter originally specified by the caller when this object listing was returned +@property (nonatomic, copy) NSString *prefix; + +/// The maxKeys parameter originally specified by the caller when this object listing was returned +@property (nonatomic) NSInteger maxKeys; + +/// The delimiter parameter originally specified by the caller when this object listing was returned +@property (nonatomic, copy) NSString *delimiter; + +/// The encodingType parameter originally specified by the caller when this object listing was returned. +@property (nonatomic, copy) NSString *encodingType; + +@end + +NS_ASSUME_NONNULL_END diff --git a/AliyunOSSSDK/OSSGetBucketV2Result.m b/AliyunOSSSDK/OSSGetBucketV2Result.m new file mode 100644 index 0000000..662c96d --- /dev/null +++ b/AliyunOSSSDK/OSSGetBucketV2Result.m @@ -0,0 +1,13 @@ +// +// OSSListObjectsV2Result.m +// AliyunOSSSDK +// +// Created by ws on 2022/5/26. +// Copyright © 2022 aliyun. All rights reserved. +// + +#import "OSSGetBucketV2Result.h" + +@implementation OSSGetBucketV2Result + +@end diff --git a/AliyunOSSSDK/OSSHttpResponseParser.m b/AliyunOSSSDK/OSSHttpResponseParser.m index bf03e17..75f5c44 100644 --- a/AliyunOSSSDK/OSSHttpResponseParser.m +++ b/AliyunOSSSDK/OSSHttpResponseParser.m @@ -20,6 +20,7 @@ #import "OSSRestoreObjectResult.h" #import "OSSPutSymlinkResult.h" #import "OSSGetSymlinkResult.h" +#import "OSSGetBucketV2Result.h" @implementation OSSHttpResponseParser { @@ -301,6 +302,53 @@ - (nullable id)constructResultObject return getBucketResult; } + case OSSOperationTypeGetBucketV2: + { + OSSGetBucketV2Result * getBucketResult = [OSSGetBucketV2Result new]; + if (_response) { + [self parseResponseHeader:_response toResultObject:getBucketResult]; + } + if (_collectingData) { + NSDictionary * parsedDict = [NSDictionary oss_dictionaryWithXMLData:_collectingData]; + OSSLogVerbose(@"Get bucket dict: %@", parsedDict); + + if (parsedDict) { + getBucketResult.bucketName = [parsedDict objectForKey:OSSNameXMLTOKEN]; + getBucketResult.prefix = [parsedDict objectForKey:OSSPrefixXMLTOKEN]; + getBucketResult.maxKeys = (int32_t)[[parsedDict objectForKey:OSSMaxKeysXMLTOKEN] integerValue]; + getBucketResult.keyCount = (int32_t)[[parsedDict objectForKey:OSSKeyCountXMLTOKEN] integerValue]; + getBucketResult.delimiter = [parsedDict objectForKey:OSSDelimiterXMLTOKEN]; + getBucketResult.isTruncated = [[parsedDict objectForKey:OSSIsTruncatedXMLTOKEN] boolValue]; + getBucketResult.nextContinuationToken = [parsedDict objectForKey:OSSNextContinuationTokenXMLTOKEN]; + + id contentObject = [parsedDict objectForKey:OSSContentsXMLTOKEN]; + if ([contentObject isKindOfClass:[NSArray class]]) { + getBucketResult.contents = contentObject; + } else if ([contentObject isKindOfClass:[NSDictionary class]]) { + NSArray * arr = [NSArray arrayWithObject:contentObject]; + getBucketResult.contents = arr; + } else { + getBucketResult.contents = nil; + } + + NSMutableArray * commonPrefixesArr = [NSMutableArray new]; + id commonPrefixes = [parsedDict objectForKey:OSSCommonPrefixesXMLTOKEN]; + if ([commonPrefixes isKindOfClass:[NSArray class]]) { + for (NSDictionary * prefix in commonPrefixes) { + [commonPrefixesArr addObject:[prefix objectForKey:@"Prefix"]]; + } + } else if ([commonPrefixes isKindOfClass:[NSDictionary class]]) { + [commonPrefixesArr addObject:[(NSDictionary *)commonPrefixes objectForKey:@"Prefix"]]; + } else { + commonPrefixesArr = nil; + } + + getBucketResult.commonPrefixes = commonPrefixesArr; + } + } + return getBucketResult; + } + case OSSOperationTypeListMultipartUploads: { OSSListMultipartUploadsResult * listMultipartUploadsResult = [OSSListMultipartUploadsResult new]; diff --git a/AliyunOSSSDK/OSSModel.m b/AliyunOSSSDK/OSSModel.m index 52399b3..e2b64f9 100644 --- a/AliyunOSSSDK/OSSModel.m +++ b/AliyunOSSSDK/OSSModel.m @@ -341,7 +341,7 @@ - (OSSTask *)interceptRequestMessage:(OSSAllRequestNeededMessage *)requestMessag static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ OSSSubResourceARRAY = @[@"acl", @"uploadId", @"partNumber", @"uploads", @"logging", @"website", @"location", - @"lifecycle", @"referer", @"cors", @"delete", @"append", @"position", @"security-token", @"x-oss-process", @"sequential",@"bucketInfo",@"symlink", @"restore"]; + @"lifecycle", @"referer", @"cors", @"delete", @"append", @"position", @"security-token", @"x-oss-process", @"sequential",@"bucketInfo",@"symlink", @"restore", @"continuation-token"]; }); /****************************************************************/ diff --git a/AliyunOSSSDK/OSSService.h b/AliyunOSSSDK/OSSService.h index b275e73..25b2b2b 100644 --- a/AliyunOSSSDK/OSSService.h +++ b/AliyunOSSSDK/OSSService.h @@ -31,6 +31,8 @@ #import "OSSGetSymlinkResult.h" #import "OSSRestoreObjectRequest.h" #import "OSSRestoreObjectResult.h" +#import "OSSGetBucketV2Request.h" +#import "OSSGetBucketV2Result.h" #import "OSSClient.h" #import "OSSModel.h" diff --git a/AliyunOSSSDK/OSSUtil.m b/AliyunOSSSDK/OSSUtil.m index 8496448..5a6c5b2 100644 --- a/AliyunOSSSDK/OSSUtil.m +++ b/AliyunOSSSDK/OSSUtil.m @@ -310,7 +310,7 @@ + (BOOL)isSubresource:(NSString *)param { @"tagging", @"objectMeta", @"uploadId", @"partNumber", @"security-token", @"position", @"img", @"style", @"styleName", @"replication", @"replicationProgress", @"replicationLocation", @"cname", @"bucketInfo", @"comp", @"qos", @"live", @"status", @"vod", @"startTime", @"endTime", @"symlink", @"x-oss-process", @"response-content-type", - @"response-content-language", @"response-expires", @"response-cache-control", @"response-content-disposition", @"response-content-encoding",@"restore" + @"response-content-language", @"response-expires", @"response-cache-control", @"response-content-disposition", @"response-content-encoding",@"restore", @"continuation-token" ]; }); /****************************************************************/ diff --git a/AliyunOSSiOSTests/OSSBucketTests.m b/AliyunOSSiOSTests/OSSBucketTests.m index 093e017..193d0f9 100644 --- a/AliyunOSSiOSTests/OSSBucketTests.m +++ b/AliyunOSSiOSTests/OSSBucketTests.m @@ -14,6 +14,8 @@ @interface OSSBucketTests : XCTestCase { OSSClient *_client; + NSString *bucketName; + int fileCount; } @end @@ -158,4 +160,131 @@ - (void)testListMultipartUploads [OSSTestUtils cleanBucket:@"oss-ios-bucket-list-multipart-uploads-test" with:_client]; } +- (void)testGetBucketV2 { + int fileCount = 50; + int delimiterFileCount = 10; + NSString *bucketName = @"oss-ios-bucket-get-bucket-test"; + NSString *delimiterPrefix = @"delimiterFile"; + NSString *prefix = @"file"; + OSSCreateBucketRequest *createRq = [OSSCreateBucketRequest new]; + createRq.bucketName = bucketName; + [[_client createBucket:createRq] waitUntilFinished]; + + for (int i = 0; i < fileCount; i++) { + OSSPutObjectRequest *putRq = [OSSPutObjectRequest new]; + putRq.bucketName = bucketName; + putRq.objectKey = [NSString stringWithFormat:@"%@%d", prefix, i]; + if (fileCount - i <= delimiterFileCount) { + putRq.objectKey = [NSString stringWithFormat:@"%@%d", delimiterPrefix, i]; + } + putRq.uploadingData = [self createRandomData:1024]; + [[_client putObject:putRq] waitUntilFinished]; + } + + OSSGetBucketV2Request *request = [OSSGetBucketV2Request new]; + request.bucketName = bucketName; + [[[_client getBucketV2:request] continueWithBlock:^id _Nullable(OSSTask * _Nonnull task) { + XCTAssertNil(task.error); + OSSGetBucketV2Result *result = task.result; + XCTAssertTrue(result.contents.count == fileCount); + return nil; + }] waitUntilFinished]; + + + __block int count = 0; + __block BOOL is; + __block NSString *nextContinuationToken; + do { + request = [OSSGetBucketV2Request new]; + request.bucketName = bucketName; + request.maxKeys = 20; + request.continuationToken = nextContinuationToken; + [[[_client getBucketV2:request] continueWithBlock:^id _Nullable(OSSTask * _Nonnull task) { + XCTAssertNil(task.error); + OSSGetBucketV2Result *result = task.result; + XCTAssertTrue(result.contents.count <= request.maxKeys); + XCTAssertTrue(result.keyCount <= request.maxKeys); + is = result.isTruncated; + count += result.keyCount; + nextContinuationToken = result.nextContinuationToken; + return nil; + }] waitUntilFinished]; + } while(is); + XCTAssertTrue(count == fileCount); + + + request = [OSSGetBucketV2Request new]; + request.bucketName = bucketName; + request.prefix = prefix; + [[[_client getBucketV2:request] continueWithBlock:^id _Nullable(OSSTask * _Nonnull task) { + XCTAssertNil(task.error); + OSSGetBucketV2Result *result = task.result; + XCTAssertTrue(result.keyCount == fileCount - delimiterFileCount); + return nil; + }] waitUntilFinished]; + + request = [OSSGetBucketV2Request new]; + request.bucketName = bucketName; + request.delimiter = @"f"; + [[[_client getBucketV2:request] continueWithBlock:^id _Nullable(OSSTask * _Nonnull task) { + XCTAssertNil(task.error); + OSSGetBucketV2Result *result = task.result; + XCTAssertTrue(result.contents.count == delimiterFileCount); + XCTAssertTrue(result.commonPrefixes.count == 1); + return nil; + }] waitUntilFinished]; + + request = [OSSGetBucketV2Request new]; + request.bucketName = bucketName; + request.delimiter = @"i"; + [[[_client getBucketV2:request] continueWithBlock:^id _Nullable(OSSTask * _Nonnull task) { + XCTAssertNil(task.error); + OSSGetBucketV2Result *result = task.result; + XCTAssertTrue(result.commonPrefixes.count == 2); + return nil; + }] waitUntilFinished]; + + request = [OSSGetBucketV2Request new]; + request.bucketName = bucketName; + request.startAfter = @"file10"; + [[[_client getBucketV2:request] continueWithBlock:^id _Nullable(OSSTask * _Nonnull task) { + XCTAssertNil(task.error); + OSSGetBucketV2Result *result = task.result; + XCTAssertTrue(result.contents.count == 37); + return nil; + }] waitUntilFinished]; + + request = [OSSGetBucketV2Request new]; + request.bucketName = bucketName; + request.encodingType = @"url"; + request.prefix = @"+="; + [[[_client getBucketV2:request] continueWithBlock:^id _Nullable(OSSTask * _Nonnull task) { + XCTAssertNil(task.error); + OSSGetBucketV2Result *result = task.result; + XCTAssertTrue([result.prefix isEqual:[OSSUtil encodeURL:request.prefix]]); + return nil; + }] waitUntilFinished]; + + request = [OSSGetBucketV2Request new]; + request.bucketName = bucketName; + request.fetchOwner = true; + [[[_client getBucketV2:request] continueWithBlock:^id _Nullable(OSSTask * _Nonnull task) { + XCTAssertNil(task.error); + OSSGetBucketV2Result *result = task.result; + for (NSDictionary *content in result.contents) { + XCTAssertNotNil(content[@"Owner"]); + } + return nil; + }] waitUntilFinished]; + + [OSSTestUtils cleanBucket:bucketName with:_client]; +} + +- (NSData *)createRandomData:(NSInteger)size { + void * bytes = malloc(size); + NSData * data = [NSData dataWithBytes:bytes length:size]; + free(bytes); + return data; +} + @end