Explorar el Código

feat: extend asynclistObject support delimiter|marker|maxkeys to list object in Android

luozhang002 hace 5 años
padre
commit
5585ea7ad4

+ 42
- 41
Example/Component/ObjectManager.js Ver fichero

16
 export class ObjectManager extends Component {  
16
 export class ObjectManager extends Component {  
17
   render() {  
17
   render() {  
18
      return(
18
      return(
19
-           <View style={styles.item}>
20
-      <Text style={styles.description}>管理文件</Text>
21
-      <View style={styles.detailitem}>
22
-        <View style={styles.button}>
23
-          <Button  style={styles.button}
24
-            onPress={this.clickHandle.bind(this,"asyncHeadObject")}
25
-            title="asyncHeadObject"
26
-            color="#841584"
27
-          />
28
-        </View>
19
+      <View style={styles.item}>
20
+        <Text style={styles.description}>管理文件</Text>
21
+        <View style={styles.detailitem}>
22
+          <View style={styles.button}>
23
+            <Button  style={styles.button}
24
+              onPress={this.clickHandle.bind(this,"asyncHeadObject")}
25
+              title="asyncHeadObject"
26
+              color="#841584"
27
+            />
28
+          </View>
29
 
29
 
30
-        <View style={styles.button}>
31
-          <Button  style={styles.button}
32
-            onPress={this.clickHandle.bind(this,"asyncListObjects")}
33
-            title="asyncListObjects"
34
-            color="#841584"
35
-          />
36
-        </View>
30
+          <View style={styles.button}>
31
+            <Button  style={styles.button}
32
+              onPress={this.clickHandle.bind(this,"asyncListObjects")}
33
+              title="asyncListObjects"
34
+              color="#841584"
35
+            />
36
+          </View>
37
 
37
 
38
-        <View style={styles.button}>
39
-          <Button  style={styles.button}
40
-            onPress={this.clickHandle.bind(this,"asyncCopyObject")}
41
-            title="asyncCopyObject"
42
-            color="#841584"
43
-          />
44
-        </View>
38
+          <View style={styles.button}>
39
+            <Button  style={styles.button}
40
+              onPress={this.clickHandle.bind(this,"asyncCopyObject")}
41
+              title="asyncCopyObject"
42
+              color="#841584"
43
+            />
44
+          </View>
45
 
45
 
46
-        <View style={styles.button}>
47
-          <Button  style={styles.button}
48
-            onPress={this.clickHandle.bind(this,"doesObjectExist")}
49
-            title="doesObjectExist"
50
-            color="#841584"
51
-          />
52
-        </View>
46
+          <View style={styles.button}>
47
+            <Button  style={styles.button}
48
+              onPress={this.clickHandle.bind(this,"doesObjectExist")}
49
+              title="doesObjectExist"
50
+              color="#841584"
51
+            />
52
+          </View>
53
 
53
 
54
-        <View style={styles.button}>
55
-          <Button  style={styles.button}
56
-            onPress={this.clickHandle.bind(this,"asyncDeleteObject")}
57
-            title="asyncDeleteObject"
58
-            color="#841584"
59
-          />
54
+          <View style={styles.button}>
55
+            <Button  style={styles.button}
56
+              onPress={this.clickHandle.bind(this,"asyncDeleteObject")}
57
+              title="asyncDeleteObject"
58
+              color="#841584"
59
+            />
60
+          </View>
60
         </View>
61
         </View>
61
       </View>
62
       </View>
62
-    </View>
63
-     )  
63
+    )  
64
   } 
64
   } 
65
   clickHandle(e) {
65
   clickHandle(e) {
66
     switch(e) {
66
     switch(e) {
74
 
74
 
75
       case "asyncListObjects" : {
75
       case "asyncListObjects" : {
76
         console.log("asyncListObjects")
76
         console.log("asyncListObjects")
77
-        AliyunOSS.asyncListObjects('luozhang002').then((e) => {
77
+        AliyunOSS.asyncListObjects('luozhang002',{
78
+          prefix:'xxxx'
79
+        }).then((e) => {
78
           console.log(e)
80
           console.log(e)
79
         }).catch((e)=>{
81
         }).catch((e)=>{
80
           console.log(e)
82
           console.log(e)
108
       default :break;
110
       default :break;
109
     }
111
     }
110
   }
112
   }
111
-
112
  }
113
  }

+ 14
- 1
README-CN.md Ver fichero

334
 ```
334
 ```
335
 ### asyncListObjects
335
 ### asyncListObjects
336
 
336
 
337
+列举指定bucket下的objects
338
+
339
+parameters:
340
+
341
+- name {String} bucket name
342
+- options {Object}
343
+  - [delimiter] {String} 用于对Object名字进行分组的字符。所有名字包含指定的前缀且第一次出现delimiter字符之间的object作为一组元素: CommonPrefixes。
344
+  - [marker] {String} 设定结果从marker之后按字母排序的第一个开始返回。
345
+  - [maxkeys] {Number} 限定此次返回object的最大数,如果不设定,默认为100,maxkeys取值不能大于1000。
346
+  - [prefix]  {String} 限定返回的object key必须以prefix作为前缀。注意使用prefix查询时,返回的key中仍会包含prefix。
347
+
337
 ```
348
 ```
338
- AliyunOSS.asyncListObjects('luozhang002').then((e)=>{
349
+ AliyunOSS.asyncListObjects('luozhang002',{
350
+    prefix:'xxxx'
351
+  }).then((e)=>{
339
     console.log(e)
352
     console.log(e)
340
   }).catch((e)=>{
353
   }).catch((e)=>{
341
      console.log(e)
354
      console.log(e)

+ 13
- 1
README.md Ver fichero

344
 ```
344
 ```
345
 ### asyncListObjects
345
 ### asyncListObjects
346
 
346
 
347
+list objects in some conditions
348
+
349
+parameters:
350
+
351
+- name {String} bucket name
352
+- options {Object}
353
+  - [delimiter] {String} 
354
+  - [prefix] {String} search buckets using `prefix` key
355
+  - [marker] {String} search start from `marker`, including `marker` key
356
+  - [max-keys] {String|Number} max buckets, default is `100`, limit to `1000` 
347
 ```
357
 ```
348
- AliyunOSS.asyncListObjects('luozhang002').then((e)=>{
358
+ AliyunOSS.asyncListObjects('luozhang002', {
359
+    prefix:'xxxx'
360
+}).then((e)=>{
349
     console.log(e)
361
     console.log(e)
350
   }).catch((e)=>{
362
   }).catch((e)=>{
351
      console.log(e)
363
      console.log(e)

+ 18
- 3
android/src/main/java/com/reactlibrary/AliyunObjectManager.java Ver fichero

92
     /**
92
     /**
93
      * asyncListObjects
93
      * asyncListObjects
94
      * @param bucketName
94
      * @param bucketName
95
-     * @param prefix
95
+     * @param opitons {delimiter|prefix|marker|maxkeys}
96
      * @param promise
96
      * @param promise
97
      */
97
      */
98
-    public void asyncListObjects(String bucketName,String prefix,final Promise promise) {
98
+    public void asyncListObjects(String bucketName, ReadableMap options, final Promise promise) {
99
         ListObjectsRequest listObjects = new ListObjectsRequest(bucketName);
99
         ListObjectsRequest listObjects = new ListObjectsRequest(bucketName);
100
-        listObjects.setPrefix(prefix);
100
+
101
+        if(options.hasKey("prefix")) {
102
+            listObjects.setPrefix(options.getString("prefix"));
103
+        }
104
+
105
+        if(options.hasKey("delimiter")) {
106
+            listObjects.setDelimiter(options.getString("delimiter"));
107
+        }
108
+
109
+        if(options.hasKey("marker")) {
110
+            listObjects.setMarker(options.getString("delimiter"));
111
+        }
112
+
113
+        if(options.hasKey("maxkeys")) {
114
+            listObjects.setMaxKeys(options.getInt(String.valueOf(options.getInt("maxkeys"))));
115
+        }
101
 
116
 
102
         // set success 、set fail 、set async request
117
         // set success 、set fail 、set async request
103
         OSSAsyncTask task = mOSS.asyncListObjects(listObjects, new OSSCompletedCallback<ListObjectsRequest, ListObjectsResult>() {
118
         OSSAsyncTask task = mOSS.asyncListObjects(listObjects, new OSSCompletedCallback<ListObjectsRequest, ListObjectsResult>() {

+ 2
- 2
android/src/main/java/com/reactlibrary/RNAliyunOssModule.java Ver fichero

332
      * @param promise
332
      * @param promise
333
      */
333
      */
334
     @ReactMethod
334
     @ReactMethod
335
-    public void asyncListObjects(String bucketName,String prefix,final Promise promise) {
336
-        mObjectManager.asyncListObjects(bucketName, prefix, promise);
335
+    public void asyncListObjects(String bucketName,ReadableMap options,final Promise promise) {
336
+        mObjectManager.asyncListObjects(bucketName, options, promise);
337
     }
337
     }
338
 
338
 
339
     /**
339
     /**