Removed pastie paste service.

This commit is contained in:
Jeremy Wood 2019-01-31 21:26:12 -05:00
parent d832e9e6d9
commit 564a7d3684
5 changed files with 2 additions and 129 deletions

View File

@ -160,10 +160,7 @@ public class VersionCommand extends MultiverseCommand {
public void run() {
if (args.size() == 1) {
String pasteUrl;
if (args.get(0).equalsIgnoreCase("-p")) {
// private post to pastie
pasteUrl = postToService(PasteServiceType.PASTIE, true, data, files);
} else if (args.get(0).equalsIgnoreCase("-b")) {
if (args.get(0).equalsIgnoreCase("-b")) {
// private post to pastebin
pasteUrl = postToService(PasteServiceType.PASTEBIN, true, data, files);
} else if (args.get(0).equalsIgnoreCase("-g")) {

View File

@ -13,7 +13,7 @@ import java.util.Map;
*
* Services that provide a distinction between "public" and "private" pastes
* should implement a custom constructor that specifies which kind the PasteService
* instance is submitting; an example of this is the PastiePasteService class.
* instance is submitting; an example of this is the PastebinPasteService class.
*/
public interface PasteService {

View File

@ -16,8 +16,6 @@ public class PasteServiceFactory {
switch(type) {
case PASTEBIN:
return new PastebinPasteService(isPrivate);
case PASTIE:
return new PastiePasteService(isPrivate);
case GITHUB:
return new GithubPasteService(isPrivate);
default:

View File

@ -11,10 +11,6 @@ public enum PasteServiceType {
* @see PastebinPasteService
*/
PASTEBIN,
/**
* @see PastiePasteService
*/
PASTIE,
/**
* @see GithubPasteService
*/

View File

@ -1,118 +0,0 @@
package com.onarandombox.MultiverseCore.utils.webpaste;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Pastes to {@code pastie.org}.
*/
public class PastiePasteService implements PasteService {
private boolean isPrivate;
public PastiePasteService(boolean isPrivate) {
this.isPrivate = isPrivate;
}
/**
* {@inheritDoc}
*/
@Override
public URL getPostURL() {
try {
return new URL("http://pastie.org/pastes");
} catch (MalformedURLException e) {
return null; // should never hit here
}
}
/**
* {@inheritDoc}
*/
@Override
public String encodeData(String data) {
try {
String encData = URLEncoder.encode("paste[authorization]", "UTF-8") + "=" + URLEncoder.encode("burger", "UTF-8"); // burger is magic
encData += "&" + URLEncoder.encode("paste[restricted]", "UTF-8") + "=" + URLEncoder.encode(this.isPrivate ? "1" : "0", "UTF-8");
encData += "&" + URLEncoder.encode("paste[parser_id]", "UTF-8") + "=" + URLEncoder.encode("6", "UTF-8"); // 6 is plain text
encData += "&" + URLEncoder.encode("paste[body]", "UTF-8") + "=" + URLEncoder.encode(data, "UTF-8");
return encData;
} catch (UnsupportedEncodingException e) {
return ""; // should never hit here
}
}
@Override
public String encodeData(Map<String, String> data) {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public String postData(String encodedData, URL url) throws PasteFailedException {
OutputStreamWriter wr = null;
BufferedReader rd = null;
try {
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(encodedData);
wr.flush();
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
String pastieUrl = "";
Pattern pastiePattern = this.getURLMatchingPattern();
while ((line = rd.readLine()) != null) {
Matcher m = pastiePattern.matcher(line);
if (m.matches()) {
String pastieID = m.group(1);
pastieUrl = this.formatURL(pastieID);
}
}
return pastieUrl;
} catch (Exception e) {
throw new PasteFailedException(e);
} finally {
if (wr != null) {
try {
wr.close();
} catch (IOException ignore) { }
}
if (rd != null) {
try {
rd.close();
} catch (IOException ignore) { }
}
}
}
@Override
public boolean supportsMultiFile() {
return false;
}
private Pattern getURLMatchingPattern() {
if (this.isPrivate) {
return Pattern.compile(".*http://pastie.org/.*key=([0-9a-z]+).*");
} else {
return Pattern.compile(".*http://pastie.org/([0-9]+).*");
}
}
private String formatURL(String pastieID) {
return "http://pastie.org/" + (this.isPrivate ? "private/" : "") + pastieID;
}
}