fix(android): log reject failures, handle trailing slashes in path, remove unused attr param

This commit is contained in:
plebeius
2026-02-23 19:00:50 +08:00
parent e32cacca4e
commit 3eb97e623f
3 changed files with 8 additions and 6 deletions
@@ -113,7 +113,8 @@ public class FileUploaderPlugin extends Plugin {
Log.e(TAG, "Upload failed", e);
try {
call.reject("Upload failed: " + e.getMessage());
} catch (Exception ignored) {
} catch (Exception rejectEx) {
Log.e(TAG, "Failed to reject call", rejectEx);
}
}
})
@@ -51,8 +51,12 @@ public class FileUtils {
if (result == null) {
String path = uri.getPath();
if (path != null) {
path = path.replaceAll("/+$", "");
int cut = path.lastIndexOf('/');
result = (cut != -1) ? path.substring(cut + 1) : path;
if (result.isEmpty()) {
result = "unknown";
}
} else {
result = "unknown";
}
@@ -134,7 +134,6 @@ public final class MediaUploadRecipes {
*/
public static String getSuccessJs(String provider) {
String[] selectorCandidates;
String attribute;
if (PROVIDER_IMGUR.equals(provider)) {
selectorCandidates =
new String[] {
@@ -143,7 +142,6 @@ public final class MediaUploadRecipes {
"[class*=\"copy-link\"] input",
"[data-link]",
};
attribute = "href";
} else if (PROVIDER_POSTIMAGES.equals(provider)) {
selectorCandidates =
new String[] {
@@ -152,14 +150,13 @@ public final class MediaUploadRecipes {
"[class*=\"direct-link\"]",
"textarea",
};
attribute = "value";
} else {
return null;
}
return buildSuccessJs(selectorCandidates, attribute);
return buildSuccessJs(selectorCandidates);
}
private static String buildSuccessJs(String[] selectors, String attr) {
private static String buildSuccessJs(String[] selectors) {
StringBuilder sb = new StringBuilder("(function(){var s=[");
for (int i = 0; i < selectors.length; i++) {
if (i > 0) sb.append(",");