3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 00:22:51 +01:00

Move dumps to gists #608

Dieser Commit ist enthalten in:
Myles 2017-01-03 15:53:20 +00:00
Ursprung 528a8e5587
Commit c10c3547b9

Datei anzeigen

@ -55,42 +55,56 @@ public class DumpSubCmd extends ViaSubCommand {
HttpURLConnection con = null; HttpURLConnection con = null;
try { try {
con = (HttpURLConnection) new URL("http://hastebin.com/documents").openConnection(); con = (HttpURLConnection) new URL("https://api.github.com/gists").openConnection();
} catch (IOException e) { } catch (IOException e) {
sender.sendMessage(ChatColor.RED + "Failed to dump, please check the console for more information"); sender.sendMessage(ChatColor.RED + "Failed to dump, please check the console for more information");
Via.getPlatform().getLogger().log(Level.WARNING, "Could not paste ViaVersion dump to Hastebin", e); Via.getPlatform().getLogger().log(Level.WARNING, "Could not paste ViaVersion dump to Gist", e);
return; return;
} }
try { try {
con.setRequestProperty("Content-Type", "text/plain"); con.setRequestProperty("Content-Type", "application/jsom");
// Bypass cloudflare :( con.addRequestProperty("User-Agent", "ViaVersion");
con.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");
con.setRequestMethod("POST"); con.setRequestMethod("POST");
con.setDoOutput(true); con.setDoOutput(true);
OutputStream out = con.getOutputStream(); OutputStream out = con.getOutputStream();
out.write(GsonUtil.getGsonBuilder().setPrettyPrinting().create().toJson(template).getBytes(Charset.forName("UTF-8"))); String contents = GsonUtil.getGsonBuilder().setPrettyPrinting().create().toJson(template);
// Create payload
JsonObject payload = new JsonObject();
payload.addProperty("description", "ViaVersion Dump");
payload.addProperty("public", "false");
// Create file contents
JsonObject file = new JsonObject();
file.addProperty("content", contents);
// Create file list
JsonObject files = new JsonObject();
files.add("dump.json", file);
payload.add("files", files);
// Write to stream
out.write(GsonUtil.getGson().toJson(payload).getBytes(Charset.forName("UTF-8")));
out.close(); out.close();
String rawOutput = CharStreams.toString(new InputStreamReader(con.getInputStream())); String rawOutput = CharStreams.toString(new InputStreamReader(con.getInputStream()));
con.getInputStream().close(); con.getInputStream().close();
System.out.println("Raw output: " + rawOutput);
JsonObject output = GsonUtil.getGson().fromJson(rawOutput, JsonObject.class); JsonObject output = GsonUtil.getGson().fromJson(rawOutput, JsonObject.class);
if (!output.has("key")) if (!output.has("html_url"))
throw new InvalidObjectException("Key is not given in Hastebin output"); throw new InvalidObjectException("URL is not given in Gist output");
sender.sendMessage(ChatColor.GREEN + "We've made a dump with useful information, report your issue and provide this url: " + getUrl(output.get("key").getAsString())); sender.sendMessage(ChatColor.GREEN + "We've made a dump with useful information, report your issue and provide this url: " + output.get("html_url").getAsString());
} catch (Exception e) { } catch (Exception e) {
sender.sendMessage(ChatColor.RED + "Failed to dump, please check the console for more information"); sender.sendMessage(ChatColor.RED + "Failed to dump, please check the console for more information");
Via.getPlatform().getLogger().log(Level.WARNING, "Could not paste ViaVersion dump to Hastebin", e);
try { try {
if (con.getResponseCode() < 200 || con.getResponseCode() > 400) { if (con.getResponseCode() == 403) {
String rawOutput = CharStreams.toString(new InputStreamReader(con.getErrorStream())); // Ensure 403 is due to rate limit being hit
con.getErrorStream().close(); if("0".equals(con.getHeaderField("X-RateLimit-Remaining"))) {
Via.getPlatform().getLogger().log(Level.WARNING, "Page returned: " + rawOutput); Via.getPlatform().getLogger().log(Level.WARNING, "You may only create 60 dumps per hour, please try again later.");
return;
} }
}
Via.getPlatform().getLogger().log(Level.WARNING, "Could not paste ViaVersion dump to Gist", e);
} catch (IOException e1) { } catch (IOException e1) {
Via.getPlatform().getLogger().log(Level.WARNING, "Failed to capture further info", e1); Via.getPlatform().getLogger().log(Level.WARNING, "Failed to capture further info", e1);
} }
@ -100,8 +114,4 @@ public class DumpSubCmd extends ViaSubCommand {
return true; return true;
} }
private String getUrl(String id) {
return String.format("http://hastebin.com/%s.json", id);
}
} }