[FEATURE] Загрузка лога на Hastebin

This commit is contained in:
LoomeL 2020-02-29 22:34:29 +06:00
parent 477b0d2fbe
commit 79d7bdf930
4 changed files with 68 additions and 13 deletions

View file

@ -19,6 +19,9 @@ var config = {
}
],
//*** Сервер Hastebin для сохранения лога ***//
hasteserver: "https://hasteb.in/",
//*** Стандартные настройки клиента ***//
autoEnterDefault: false, // Автоматический вход на выбранный сервер
fullScreenDefault: false, // Клиент в полный экран

View file

@ -22,7 +22,7 @@
</padding>
</TextArea>
<Pane layoutY="405.0" prefHeight="45.0" prefWidth="693.0" style="-fx-background-color: #ffffff;" />
<Button fx:id="copy" defaultButton="true" layoutX="373.0" layoutY="415.0" prefHeight="30.0" prefWidth="100.0" text="Копировать" />
<Button fx:id="copy" defaultButton="true" layoutX="373.0" layoutY="415.0" prefHeight="30.0" prefWidth="100.0" text="Загрузить на Hastebin" />
<Button fx:id="action" layoutX="533.0" layoutY="415.0" prefHeight="25.0" prefWidth="150.0" text="Убить" />
<Label fx:id="version" layoutX="14.0" layoutY="419.0" text="GravitLauncher" />
</Pane>

View file

@ -21,8 +21,17 @@ var debug = {
debug.copy = debug.overlay.lookup("#copy");
debug.copy.setOnAction(function(event) {
var haste = FunctionalBridge.hastebin(config.hasteserver, debug.output.getText());
if (haste == null) {
debug.copy.setText("Ошибка!");
return;
}
openURL(new java.net.URL(haste));
var content = new javafx.scene.input.ClipboardContent();
content.putString(debug.output.getText());
content.putString(haste);
javafx.scene.input.Clipboard.getSystemClipboard().
setContent(content);

View file

@ -6,6 +6,16 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
import com.google.gson.JsonParser;
import pro.gravit.launcher.LauncherAPI;
import pro.gravit.launcher.api.AuthService;
import pro.gravit.launcher.events.request.AuthRequestEvent;
@ -133,4 +143,37 @@ public static String getLauncherVersion() {
Version.BUILD
);
}
@LauncherAPI
public static String hastebin(String hasteserver, String log) {
HttpURLConnection connection = null;
try {
//Create connection
URL url = new URL(hasteserver + "documents");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoInput(true);
connection.setDoOutput(true);
//Send request
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
wr.writeBytes(log);
wr.flush();
wr.close();
//Get Response
BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String result = rd.readLine();
return hasteserver + new JsonParser().parse(result).getAsJsonObject().get("key").getAsString();
} catch (IOException e) {
LogHelper.error(e);
return null;
} finally {
if (connection == null) return null;
connection.disconnect();
}
}
}