|
@@ -20,6 +20,7 @@ import com.loopj.android.http.MySSLSocketFactory;
|
20
|
20
|
|
21
|
21
|
import java.io.File;
|
22
|
22
|
import java.security.KeyStore;
|
|
23
|
+import java.security.MessageDigest;
|
23
|
24
|
|
24
|
25
|
import cz.msebera.android.httpclient.HttpEntity;
|
25
|
26
|
import cz.msebera.android.httpclient.entity.ByteArrayEntity;
|
|
@@ -76,6 +77,20 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
|
76
|
77
|
}
|
77
|
78
|
}
|
78
|
79
|
|
|
80
|
+ public static String getMD5(String input) {
|
|
81
|
+ MessageDigest md = MessageDigest.getInstance("MD5");
|
|
82
|
+ md.update(input.getBytes());
|
|
83
|
+ byte[] digest = md.digest();
|
|
84
|
+
|
|
85
|
+ StringBuffer sb = new StringBuffer();
|
|
86
|
+
|
|
87
|
+ for (byte b : digest) {
|
|
88
|
+ sb.append(String.format("%02x", b & 0xff))
|
|
89
|
+ }
|
|
90
|
+
|
|
91
|
+ return sb.toString();
|
|
92
|
+ }
|
|
93
|
+
|
79
|
94
|
@Override
|
80
|
95
|
public void run() {
|
81
|
96
|
|
|
@@ -107,6 +122,17 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
|
107
|
122
|
|
108
|
123
|
}
|
109
|
124
|
|
|
125
|
+ String key = this.taskId;
|
|
126
|
+ if (this.options.key != null) {
|
|
127
|
+ key = RNFetchBlobReq.getMD5(this.options.key);
|
|
128
|
+
|
|
129
|
+ File file = new File(RNFetchBlobFileHandler.getFilePath(ctx, taskId, key, this.options))
|
|
130
|
+ if (file.exists()) {
|
|
131
|
+ callback.invoke(null, file.getAbsolutePath());
|
|
132
|
+ return;
|
|
133
|
+ }
|
|
134
|
+ }
|
|
135
|
+
|
110
|
136
|
try {
|
111
|
137
|
|
112
|
138
|
req = new AsyncHttpClient();
|
|
@@ -141,7 +167,7 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
|
141
|
167
|
|
142
|
168
|
// create handler
|
143
|
169
|
if(options.fileCache || options.path != null) {
|
144
|
|
- handler = new RNFetchBlobFileHandler(ctx, taskId, options, callback);
|
|
170
|
+ handler = new RNFetchBlobFileHandler(ctx, taskId, key, options, callback);
|
145
|
171
|
// if path format invalid, throw error
|
146
|
172
|
if (!((RNFetchBlobFileHandler)handler).isValid) {
|
147
|
173
|
callback.invoke("RNFetchBlob fetch error, configuration path `"+ options.path +"` is not a valid path.");
|