|
@@ -22,6 +22,7 @@ import java.io.File;
|
22
|
22
|
import java.io.IOException;
|
23
|
23
|
import java.io.InputStream;
|
24
|
24
|
import java.security.KeyStore;
|
|
25
|
+import java.security.MessageDigest;
|
25
|
26
|
|
26
|
27
|
import cz.msebera.android.httpclient.HttpEntity;
|
27
|
28
|
import cz.msebera.android.httpclient.entity.ByteArrayEntity;
|
|
@@ -78,6 +79,28 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
|
78
|
79
|
}
|
79
|
80
|
}
|
80
|
81
|
|
|
82
|
+ public static String getMD5(String input) {
|
|
83
|
+ String result = null;
|
|
84
|
+
|
|
85
|
+ try {
|
|
86
|
+ MessageDigest md = MessageDigest.getInstance("MD5");
|
|
87
|
+ md.update(input.getBytes());
|
|
88
|
+ byte[] digest = md.digest();
|
|
89
|
+
|
|
90
|
+ StringBuffer sb = new StringBuffer();
|
|
91
|
+
|
|
92
|
+ for (byte b : digest) {
|
|
93
|
+ sb.append(String.format("%02x", b & 0xff));
|
|
94
|
+ }
|
|
95
|
+
|
|
96
|
+ result = sb.toString();
|
|
97
|
+ } catch(Exception ex) {
|
|
98
|
+ ex.printStackTrace();
|
|
99
|
+ }
|
|
100
|
+
|
|
101
|
+ return result;
|
|
102
|
+ }
|
|
103
|
+
|
81
|
104
|
@Override
|
82
|
105
|
public void run() {
|
83
|
106
|
|
|
@@ -109,6 +132,20 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
|
109
|
132
|
|
110
|
133
|
}
|
111
|
134
|
|
|
135
|
+ String cacheKey = this.taskId;
|
|
136
|
+ if (this.options.key != null) {
|
|
137
|
+ cacheKey = RNFetchBlobReq.getMD5(this.options.key);
|
|
138
|
+ if (cacheKey == null) {
|
|
139
|
+ cacheKey = this.taskId;
|
|
140
|
+ }
|
|
141
|
+
|
|
142
|
+ File file = new File(RNFetchBlobFileHandler.getFilePath(ctx, taskId, cacheKey, this.options));
|
|
143
|
+ if (file.exists()) {
|
|
144
|
+ callback.invoke(null, file.getAbsolutePath());
|
|
145
|
+ return;
|
|
146
|
+ }
|
|
147
|
+ }
|
|
148
|
+
|
112
|
149
|
try {
|
113
|
150
|
|
114
|
151
|
req = new AsyncHttpClient();
|
|
@@ -145,7 +182,7 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
|
145
|
182
|
|
146
|
183
|
// create handler
|
147
|
184
|
if(options.fileCache || options.path != null) {
|
148
|
|
- handler = new RNFetchBlobFileHandler(ctx, taskId, options, callback);
|
|
185
|
+ handler = new RNFetchBlobFileHandler(ctx, taskId, cacheKey, options, callback);
|
149
|
186
|
// if path format invalid, throw error
|
150
|
187
|
if (!((RNFetchBlobFileHandler)handler).isValid) {
|
151
|
188
|
callback.invoke("RNFetchBlob fetch error, configuration path `"+ options.path +"` is not a valid path.");
|