Fixes for the verbose uploader

This commit is contained in:
Luck 2017-04-04 17:17:57 +01:00
parent 2e40557b39
commit 7259e6be0a
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
3 changed files with 34 additions and 10 deletions

View File

@ -99,11 +99,11 @@ public enum Message {
*/
VERBOSE_INVALID_FILTER("&cInvalid verbose filter: &f{0}", true),
VERBOSE_ON("&bVerbose checking output set to &aTRUE &bfor all permissions.", true),
VERBOSE_ON_QUERY("&bVerbose checking output set to &aTRUE &bfor permissions matching the following filters: &f{0}", true),
VERBOSE_ON_QUERY("&bVerbose checking output set to &aTRUE &bfor permissions matching filter: &f{0}", true),
VERBOSE_OFF("&bVerbose checking output set to &cFALSE&b.", true),
VERBOSE_RECORDING_ON("&bVerbose recording set to &aTRUE &bfor all permissions.", true),
VERBOSE_RECORDING_ON_QUERY("&bVerbose recording set to &aTRUE &bfor permissions matching the following filters: &f{0}", true),
VERBOSE_RECORDING_ON_QUERY("&bVerbose recording set to &aTRUE &bfor permissions matching filter: &f{0}", true),
VERBOSE_RECORDING_UPLOAD_START("&bVerbose recording was disabled. Uploading results...", true),
VERBOSE_RECORDING_URL("&aVerbose results URL:", true),

View File

@ -26,6 +26,7 @@ import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.stream.JsonWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.StringWriter;
@ -36,8 +37,9 @@ import java.nio.charset.StandardCharsets;
public class PasteUtils {
public static String paste(String name, String desc, String contents) {
HttpURLConnection connection = null;
try {
HttpURLConnection connection = (HttpURLConnection) new URL("https://api.github.com/gists").openConnection();
connection = (HttpURLConnection) new URL("https://api.github.com/gists").openConnection();
connection.setRequestMethod("POST");
connection.setDoInput(true);
connection.setDoOutput(true);
@ -58,11 +60,17 @@ public class PasteUtils {
}
if (connection.getResponseCode() >= 400) {
return null;
throw new RuntimeException("Connection returned response code: " + connection.getResponseCode() + " - " + connection.getResponseMessage());
}
String pasteUrl;
try (InputStream inputStream = connection.getInputStream()) {
try (InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) {
JsonObject response = new Gson().fromJson(reader, JsonObject.class);
pasteUrl = response.get("html_url").getAsString();
}
}
JsonObject response = new Gson().fromJson(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8), JsonObject.class);
String pasteUrl = response.get("html_url").getAsString();
connection.disconnect();
try {
@ -72,15 +80,31 @@ public class PasteUtils {
try (OutputStream os = connection.getOutputStream()) {
os.write(("url=" + pasteUrl).getBytes(StandardCharsets.UTF_8));
}
pasteUrl = connection.getHeaderField("Location");
connection.disconnect();
if (connection.getResponseCode() >= 400) {
new RuntimeException("Connection returned response code: " + connection.getResponseCode() + " - " + connection.getResponseMessage()).printStackTrace();
} else {
String shortUrl = connection.getHeaderField("Location");
if (shortUrl != null) {
pasteUrl = shortUrl;
}
}
} catch (Exception e) {
// ignored
e.printStackTrace();
}
return pasteUrl;
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
if (connection != null) {
try {
connection.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}

View File

@ -44,7 +44,7 @@ import javax.script.ScriptEngine;
@RequiredArgsConstructor
public class VerboseListener {
private static final int DATA_TRUNCATION = 700;
private static final int DATA_TRUNCATION = 3500;
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
private final long startTime = System.currentTimeMillis();