|
18 | 18 |
|
19 | 19 | package nya.miku.wishmaster.api; |
20 | 20 |
|
| 21 | +import java.io.OutputStream; |
| 22 | + |
21 | 23 | import android.content.Context; |
22 | 24 | import android.content.SharedPreferences; |
23 | 25 | import android.content.res.Resources; |
|
26 | 28 | import cz.msebera.android.httpclient.cookie.Cookie; |
27 | 29 | import cz.msebera.android.httpclient.impl.cookie.BasicClientCookie; |
28 | 30 | import nya.miku.wishmaster.R; |
| 31 | +import nya.miku.wishmaster.api.interfaces.CancellableTask; |
| 32 | +import nya.miku.wishmaster.api.interfaces.ProgressListener; |
29 | 33 | import nya.miku.wishmaster.http.cloudflare.CloudflareException; |
| 34 | +import nya.miku.wishmaster.http.streamer.HttpRequestModel; |
| 35 | +import nya.miku.wishmaster.http.streamer.HttpStreamer; |
30 | 36 | import nya.miku.wishmaster.http.streamer.HttpWrongStatusCodeException; |
31 | 37 |
|
32 | 38 | public abstract class CloudflareChanModule extends AbstractChanModule { |
@@ -113,4 +119,16 @@ protected boolean cloudflareRecaptchaFallback() { |
113 | 119 | return preferences.getBoolean(getSharedKey(PREF_KEY_CLOUDFLARE_RECAPTCHA_FALLBACK), false); |
114 | 120 | } |
115 | 121 |
|
| 122 | + @Override |
| 123 | + public void downloadFile(String url, OutputStream out, ProgressListener listener, CancellableTask task) throws Exception { |
| 124 | + String fixedUrl = fixRelativeUrl(url); |
| 125 | + try { |
| 126 | + HttpRequestModel rqModel = HttpRequestModel.builder().setGET().build(); |
| 127 | + HttpStreamer.getInstance().downloadFileFromUrl(fixedUrl, out, rqModel, httpClient, listener, task, true); |
| 128 | + } catch (HttpWrongStatusCodeException e) { |
| 129 | + if (canCloudflare()) checkCloudflareError(e, fixedUrl); |
| 130 | + throw e; |
| 131 | + } |
| 132 | + } |
| 133 | + |
116 | 134 | } |
0 commit comments