mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(upload): resolve electron file-path fallback and android provider automation stalls
This commit is contained in:
@@ -49,6 +49,8 @@ public class MediaUploadAutomationRunner {
|
||||
private final Handler mainHandler;
|
||||
private final Runnable pollRunnable;
|
||||
private boolean finished;
|
||||
private boolean fileChooserHandled;
|
||||
private boolean fileInputTriggerAttempted;
|
||||
private long startTime;
|
||||
|
||||
public MediaUploadAutomationRunner(
|
||||
@@ -86,6 +88,7 @@ public class MediaUploadAutomationRunner {
|
||||
WebView webView,
|
||||
ValueCallback<Uri[]> filePathCallback,
|
||||
FileChooserParams fileChooserParams) {
|
||||
fileChooserHandled = true;
|
||||
MediaUploadAutomationRunner.this.filePathCallback = filePathCallback;
|
||||
if (fileUri != null) {
|
||||
filePathCallback.onReceiveValue(new Uri[] {fileUri});
|
||||
@@ -120,7 +123,21 @@ public class MediaUploadAutomationRunner {
|
||||
finish(new MediaUploadResult(false, null, "No trigger JS for " + provider));
|
||||
return;
|
||||
}
|
||||
webView.evaluateJavascript(js, value -> schedulePoll());
|
||||
fileInputTriggerAttempted = true;
|
||||
webView.evaluateJavascript(
|
||||
js,
|
||||
value -> {
|
||||
String normalized = value == null ? "" : value.replace("\"", "").trim();
|
||||
if ("true".equals(normalized)) {
|
||||
schedulePoll();
|
||||
} else {
|
||||
finish(
|
||||
new MediaUploadResult(
|
||||
false,
|
||||
null,
|
||||
"Could not find upload file input for provider " + provider));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void schedulePoll() {
|
||||
@@ -136,6 +153,14 @@ public class MediaUploadAutomationRunner {
|
||||
finish(new MediaUploadResult(false, null, "Upload timeout"));
|
||||
return;
|
||||
}
|
||||
if (fileInputTriggerAttempted
|
||||
&& !fileChooserHandled
|
||||
&& elapsed >= MediaUploadRecipes.FILE_INPUT_TIMEOUT_MS) {
|
||||
finish(
|
||||
new MediaUploadResult(
|
||||
false, null, "Provider file chooser was not triggered for " + provider));
|
||||
return;
|
||||
}
|
||||
|
||||
String successJs = MediaUploadRecipes.getSuccessJs(provider);
|
||||
String blockedJs = MediaUploadRecipes.getBlockedJs(provider);
|
||||
|
||||
@@ -13,6 +13,8 @@ public final class MediaUploadRecipes {
|
||||
|
||||
/** Max time to wait for upload completion (ms). */
|
||||
public static final long UPLOAD_TIMEOUT_MS = 45_000;
|
||||
/** Max time to wait for provider file input to be found/triggered (ms). */
|
||||
public static final long FILE_INPUT_TIMEOUT_MS = 8_000;
|
||||
/** Poll interval for success/blocked checks (ms). */
|
||||
public static final long POLL_INTERVAL_MS = 500;
|
||||
|
||||
@@ -61,7 +63,7 @@ public final class MediaUploadRecipes {
|
||||
if (i > 0) sb.append(",");
|
||||
sb.append("\"").append(escapeJs(selectors[i])).append("\"");
|
||||
}
|
||||
sb.append("];for(var i=0;i<s.length;i++){var el=document.querySelector(s[i]);if(el){el.click();return;}}})();");
|
||||
sb.append("];for(var i=0;i<s.length;i++){var el=document.querySelector(s[i]);if(el){el.click();return true;}}return false;})()");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user