mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
[FEATURE] Загрузка лога на Hastebin (#358)
This commit is contained in:
parent
477b0d2fbe
commit
c06257dbc6
4 changed files with 88 additions and 13 deletions
|
@ -19,6 +19,9 @@ var config = {
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
|
//*** Сервер Hastebin для сохранения лога ***//
|
||||||
|
hasteserver: "https://hasteb.in/",
|
||||||
|
|
||||||
//*** Стандартные настройки клиента ***//
|
//*** Стандартные настройки клиента ***//
|
||||||
autoEnterDefault: false, // Автоматический вход на выбранный сервер
|
autoEnterDefault: false, // Автоматический вход на выбранный сервер
|
||||||
fullScreenDefault: false, // Клиент в полный экран
|
fullScreenDefault: false, // Клиент в полный экран
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
</padding>
|
</padding>
|
||||||
</TextArea>
|
</TextArea>
|
||||||
<Pane layoutY="405.0" prefHeight="45.0" prefWidth="693.0" style="-fx-background-color: #ffffff;" />
|
<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="Убить" />
|
<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" />
|
<Label fx:id="version" layoutX="14.0" layoutY="419.0" text="GravitLauncher" />
|
||||||
</Pane>
|
</Pane>
|
||||||
|
|
|
@ -21,8 +21,22 @@ var debug = {
|
||||||
|
|
||||||
debug.copy = debug.overlay.lookup("#copy");
|
debug.copy = debug.overlay.lookup("#copy");
|
||||||
debug.copy.setOnAction(function(event) {
|
debug.copy.setOnAction(function(event) {
|
||||||
|
var haste = FunctionalBridge.hastebin(config.hasteserver, debug.output.getText());
|
||||||
|
|
||||||
|
if (haste == null) {
|
||||||
|
debug.copy.setText("Ошибка!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
openURL(new java.net.URL(haste));
|
||||||
|
} catch (e) {
|
||||||
|
LogHelper.error("Error Open Link");
|
||||||
|
LogHelper.error(e);
|
||||||
|
}
|
||||||
|
|
||||||
var content = new javafx.scene.input.ClipboardContent();
|
var content = new javafx.scene.input.ClipboardContent();
|
||||||
content.putString(debug.output.getText());
|
content.putString(haste);
|
||||||
|
|
||||||
javafx.scene.input.Clipboard.getSystemClipboard().
|
javafx.scene.input.Clipboard.getSystemClipboard().
|
||||||
setContent(content);
|
setContent(content);
|
||||||
|
|
|
@ -6,7 +6,20 @@
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
|
||||||
|
import pro.gravit.launcher.Launcher;
|
||||||
import pro.gravit.launcher.LauncherAPI;
|
import pro.gravit.launcher.LauncherAPI;
|
||||||
|
import pro.gravit.launcher.LauncherNetworkAPI;
|
||||||
import pro.gravit.launcher.api.AuthService;
|
import pro.gravit.launcher.api.AuthService;
|
||||||
import pro.gravit.launcher.events.request.AuthRequestEvent;
|
import pro.gravit.launcher.events.request.AuthRequestEvent;
|
||||||
import pro.gravit.launcher.guard.LauncherGuardManager;
|
import pro.gravit.launcher.guard.LauncherGuardManager;
|
||||||
|
@ -15,13 +28,19 @@
|
||||||
import pro.gravit.launcher.hwid.HWID;
|
import pro.gravit.launcher.hwid.HWID;
|
||||||
import pro.gravit.launcher.hwid.OshiHWIDProvider;
|
import pro.gravit.launcher.hwid.OshiHWIDProvider;
|
||||||
import pro.gravit.launcher.managers.ConsoleManager;
|
import pro.gravit.launcher.managers.ConsoleManager;
|
||||||
|
import pro.gravit.launcher.managers.GsonManager;
|
||||||
import pro.gravit.launcher.managers.HasherManager;
|
import pro.gravit.launcher.managers.HasherManager;
|
||||||
import pro.gravit.launcher.managers.HasherStore;
|
import pro.gravit.launcher.managers.HasherStore;
|
||||||
import pro.gravit.launcher.request.Request;
|
import pro.gravit.launcher.request.Request;
|
||||||
import pro.gravit.utils.Version;
|
import pro.gravit.utils.Version;
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
import pro.gravit.utils.HTTPRequest;
|
||||||
|
|
||||||
public class FunctionalBridge {
|
public class FunctionalBridge {
|
||||||
|
public class HasteResponse {
|
||||||
|
@LauncherNetworkAPI
|
||||||
|
public String key;
|
||||||
|
}
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public static ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(0);
|
public static ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(0);
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
|
@ -133,4 +152,43 @@ public static String getLauncherVersion() {
|
||||||
Version.BUILD
|
Version.BUILD
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@LauncherAPI
|
||||||
|
public static String hastebin(String hasteserver, String log) throws IOException {
|
||||||
|
JsonParser parser = new JsonParser();
|
||||||
|
Gson gson = Launcher.gsonManager.gson;
|
||||||
|
|
||||||
|
URL url = new URL(hasteserver + "documents");
|
||||||
|
|
||||||
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
|
connection.setDoInput(true);
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
connection.setRequestMethod("POST");
|
||||||
|
connection.setRequestProperty("Content-Type", "text/plain; charset=UTF-8");
|
||||||
|
connection.setRequestProperty("Accept", "application/json");
|
||||||
|
connection.setConnectTimeout(10000);
|
||||||
|
try (OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream(), StandardCharsets.UTF_8)) {
|
||||||
|
writer.write(log);
|
||||||
|
writer.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
InputStreamReader reader;
|
||||||
|
int statusCode = connection.getResponseCode();
|
||||||
|
|
||||||
|
if (200 <= statusCode && statusCode < 300)
|
||||||
|
reader = new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8);
|
||||||
|
else
|
||||||
|
reader = new InputStreamReader(connection.getErrorStream(), StandardCharsets.UTF_8);
|
||||||
|
try {
|
||||||
|
JsonElement response = parser.parse(reader);
|
||||||
|
HasteResponse obj = gson.fromJson(response, HasteResponse.class);
|
||||||
|
return hasteserver + obj.key;
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (200 > statusCode || statusCode > 300) {
|
||||||
|
LogHelper.error("JsonRequest failed. Server response code %d", statusCode);
|
||||||
|
throw new IOException(e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue