mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 22:03:55 +01:00
Fix uploads getting stuck (#2309)
* Fix uploads getting stuck * Fix test * Use single instance of Gson across the app * More logs to help debug upload failure * Add request identifier * wip * Fix issues with image quality check dialogs
This commit is contained in:
parent
07f9af19f5
commit
532ab8aeae
16 changed files with 85 additions and 91 deletions
|
|
@ -896,7 +896,7 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
|
|||
|
||||
CustomApiResult result = api.upload(filename, file, dataLength, pageContents, editSummary, getCentralAuthToken(), getEditToken(), progressListener::onProgress);
|
||||
|
||||
Timber.wtf("Result: " + result.toString());
|
||||
Timber.d("Result: %s", result.toString());
|
||||
|
||||
String resultStatus = result.getString("/api/upload/@result");
|
||||
|
||||
|
|
|
|||
|
|
@ -36,15 +36,15 @@ public class CustomApiResult {
|
|||
this.evaluator = XPathFactory.newInstance().newXPath();
|
||||
}
|
||||
|
||||
static CustomApiResult fromRequestBuilder(Http.HttpRequestBuilder builder, HttpClient client) throws IOException {
|
||||
|
||||
static CustomApiResult fromRequestBuilder(String requestIdentifier, Http.HttpRequestBuilder builder, HttpClient client) throws IOException {
|
||||
try {
|
||||
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
Document doc = docBuilder.parse(builder.use(client).charset("utf-8").data("format", "xml").asResponse().getEntity().getContent());
|
||||
printStringFromDocument(doc);
|
||||
printStringFromDocument(requestIdentifier, doc);
|
||||
return new CustomApiResult(doc);
|
||||
} catch (ParserConfigurationException e) {
|
||||
// I don't know wtf I can do about this on...
|
||||
Timber.e(e, "Error occurred while parsing the response for method %s", requestIdentifier);
|
||||
throw new RuntimeException(e);
|
||||
} catch (IllegalStateException e) {
|
||||
// So, this should never actually happen - since we assume MediaWiki always generates valid json
|
||||
|
|
@ -52,14 +52,16 @@ public class CustomApiResult {
|
|||
// Sooo... I can throw IOError
|
||||
// Thanks Java, for making me spend significant time on shit that happens once in a bluemoon
|
||||
// I surely am writing Nuclear Submarine controller code
|
||||
Timber.e(e, "Error occurred while parsing the response for method %s", requestIdentifier);
|
||||
throw new IOError(e);
|
||||
} catch (SAXException e) {
|
||||
// See Rant above
|
||||
Timber.e(e, "Error occurred while parsing the response for method %s", requestIdentifier);
|
||||
throw new IOError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void printStringFromDocument(Document doc)
|
||||
public static void printStringFromDocument(String requestIdentifier, Document doc)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -69,11 +71,11 @@ public class CustomApiResult {
|
|||
TransformerFactory tf = TransformerFactory.newInstance();
|
||||
Transformer transformer = tf.newTransformer();
|
||||
transformer.transform(domSource, result);
|
||||
Timber.d("API response is\n %s", writer.toString());
|
||||
Timber.d("API response for method %s is\n %s", requestIdentifier, writer.toString());
|
||||
}
|
||||
catch(TransformerException ex)
|
||||
{
|
||||
Timber.d("Error occurred in transforming", ex);
|
||||
Timber.e(ex, "Error occurred in transforming response for method %s", requestIdentifier);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -140,6 +140,7 @@ public class CustomMwApi {
|
|||
}
|
||||
|
||||
public CustomApiResult upload(String filename, InputStream file, long length, String text, String comment, String centralAuthToken, String token, ProgressListener uploadProgressListener) throws IOException {
|
||||
Timber.d("Initiating upload for file %s", filename);
|
||||
Http.HttpRequestBuilder builder = Http.multipart(apiURL)
|
||||
.data("action", "upload")
|
||||
.data("token", token)
|
||||
|
|
@ -155,7 +156,7 @@ public class CustomMwApi {
|
|||
builder.file("file", filename, file);
|
||||
}
|
||||
|
||||
return CustomApiResult.fromRequestBuilder(builder, client);
|
||||
return CustomApiResult.fromRequestBuilder("uploadFile", builder, client);
|
||||
}
|
||||
|
||||
public void logout() throws IOException {
|
||||
|
|
@ -174,7 +175,7 @@ public class CustomMwApi {
|
|||
builder = Http.get(apiURL);
|
||||
}
|
||||
builder.data(params);
|
||||
return CustomApiResult.fromRequestBuilder(builder, client);
|
||||
return CustomApiResult.fromRequestBuilder(apiURL, builder, client);
|
||||
}
|
||||
}
|
||||
;
|
||||
|
|
|
|||
|
|
@ -34,6 +34,17 @@ public class UploadResult {
|
|||
this.imageUrl = imageUrl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UploadResult{" +
|
||||
"errorCode='" + errorCode + '\'' +
|
||||
", resultStatus='" + resultStatus + '\'' +
|
||||
", dateUploaded='" + dateUploaded.toString() + '\'' +
|
||||
", imageUrl='" + imageUrl + '\'' +
|
||||
", canonicalFilename='" + canonicalFilename + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets uploaded date
|
||||
* @return Upload date
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue