40 lines
1.4 KiB
Java
40 lines
1.4 KiB
Java
package eu.mikroskeem.utils.paste.providers;
|
|
|
|
import eu.mikroskeem.utils.paste.IPaste;
|
|
import org.jetbrains.annotations.NotNull;
|
|
import org.jetbrains.annotations.Nullable;
|
|
import org.json.JSONObject;
|
|
|
|
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.URL;
|
|
|
|
public class Hastebin implements IPaste {
|
|
@Nullable
|
|
public String paste(@NotNull String content) throws IOException {
|
|
HttpURLConnection connection = null;
|
|
try {
|
|
URL url = new URL("https://paste.nightsnack.cf/documents");
|
|
connection = (HttpURLConnection) url.openConnection();
|
|
connection.setRequestMethod("POST");
|
|
connection.setDoInput(true);
|
|
connection.setDoOutput(true);
|
|
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
|
|
wr.writeBytes(content);
|
|
wr.flush();
|
|
wr.close();
|
|
BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
|
return String.format("https://paste.nightsnack.cf/raw/%s", new JSONObject(rd.readLine()).get("key"));
|
|
} catch (MalformedURLException e) {
|
|
return null;
|
|
} finally {
|
|
if (connection == null) { return null; }
|
|
connection.disconnect();
|
|
}
|
|
}
|
|
}
|