Fix wrong extension when downloading
This commit is contained in:
1 parent
ce274cf65b
commit
5267cad896
2 files changed
-61
No files matched your search
@@ -57,7 +57,6 @@ import com.hippo.yorozuya.IOUtils;
|
||||
import com.hippo.yorozuya.MathUtils;
|
||||
import com.hippo.yorozuya.OSUtils;
|
||||
import com.hippo.yorozuya.StringUtils;
|
||||
import com.hippo.yorozuya.Utilities;
|
||||
import com.hippo.yorozuya.collect.SparseJLArray;
|
||||
import com.hippo.yorozuya.thread.PriorityThread;
|
||||
import com.hippo.yorozuya.thread.PriorityThreadFactory;
|
||||
@@ -1276,10 +1275,6 @@ public final class SpiderQueen implements Runnable {
|
||||
if (mediaType != null) {
|
||||
extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(mediaType.toString());
|
||||
}
|
||||
// Ensure extension
|
||||
if (!Utilities.contain(PageLoader2.SUPPORT_IMAGE_EXTENSIONS, extension)) {
|
||||
extension = PageLoader2.SUPPORT_IMAGE_EXTENSIONS[0];
|
||||
}
|
||||
|
||||
OutputStreamPipe osPipe = null;
|
||||
try {
|
||||
|
||||
@@ -16,22 +16,10 @@
|
||||
|
||||
package com.hippo.yorozuya;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.webkit.MimeTypeMap;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public final class Utilities {
|
||||
|
||||
private static final String[] MIME_TYPE_ARRAY = {
|
||||
"image/jpg"
|
||||
};
|
||||
private static final String[] EXTENSION_ARRAY = {
|
||||
"jpg"
|
||||
};
|
||||
|
||||
/**
|
||||
* Whether the array contain the element
|
||||
*
|
||||
@@ -71,48 +59,4 @@ public final class Utilities {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String getNameFromUrl(String url) {
|
||||
if (!TextUtils.isEmpty(url)) {
|
||||
int fragment = url.lastIndexOf('#');
|
||||
if (fragment > 0) {
|
||||
url = url.substring(0, fragment);
|
||||
}
|
||||
|
||||
int query = url.lastIndexOf('?');
|
||||
if (query > 0) {
|
||||
url = url.substring(0, query);
|
||||
}
|
||||
|
||||
int filenamePos = url.lastIndexOf('/');
|
||||
String filename =
|
||||
0 <= filenamePos ? url.substring(filenamePos + 1) : url;
|
||||
|
||||
// if the filename contains special characters, we don't
|
||||
// consider it valid for our matching purposes:
|
||||
if (filename.length() != 0 &&
|
||||
Pattern.matches("[a-zA-Z_0-9\\.\\-\\(\\)%]+", filename)) {
|
||||
int dotPos = filename.lastIndexOf('.');
|
||||
if (0 < dotPos) {
|
||||
return filename.substring(0, dotPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getExtensionFromMimeType(String mimeType) {
|
||||
if (TextUtils.isEmpty(mimeType)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (int i = 0, n = MIME_TYPE_ARRAY.length; i < n; i++) {
|
||||
if (MIME_TYPE_ARRAY[i].equals(mimeType)) {
|
||||
return EXTENSION_ARRAY[i];
|
||||
}
|
||||
}
|
||||
|
||||
return MimeTypeMap.getSingleton().getExtensionFromMimeType(mimeType);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user