Skip to content

Commit 1659938

Browse files
[O] Make PasteBinStorage configurable
Co-Authored-By: MstrPikachu <[email protected]>
1 parent dd4270b commit 1659938

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/main/java/org/hydev/mcpm/client/database/export/PasteBinStorage.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,26 @@
88
/**
99
* Store string content to a pastebin that supports raw text requests (e.g. https://github.com/w4/bin)
1010
*
11+
* @param host Pastebin host URL
1112
* @author Peter (https://github.com/MstrPikachu)
1213
* @author Azalea (https://github.com/hykilpikonna)
1314
* @since 2022-11-23
1415
*/
15-
public class PasteBinStorage implements StringStorage
16+
public record PasteBinStorage(String host) implements StringStorage
1617
{
17-
private static final String HOST = "https://mcpm.hydev.org/paste/";
18+
/**
19+
* Construct with default host
20+
*/
21+
public PasteBinStorage()
22+
{
23+
this("https://mcpm.hydev.org/paste/");
24+
}
1825

1926
@Override
2027
public String store(String content) throws IOException
2128
{
2229
// Send request
23-
return Request.put(HOST)
30+
return Request.put(host)
2431
.bodyString(content, ContentType.TEXT_PLAIN)
2532
.execute().returnContent().asString();
2633
}
@@ -31,7 +38,7 @@ public String load(String token) throws IOException
3138
// If token is not a URL, treat it as the pastebin token and append host from it
3239
if (!token.startsWith("http://") && !token.startsWith("https://"))
3340
{
34-
token = HOST + token;
41+
token = host + token;
3542
}
3643

3744
// Send request
@@ -43,6 +50,6 @@ public String load(String token) throws IOException
4350
@Override
4451
public String instruction()
4552
{
46-
return String.format("Please save the content to the pastebin at %s, and paste in the URL", HOST);
53+
return String.format("Please save the content to the pastebin at %s, and paste in the URL", host);
4754
}
4855
}

0 commit comments

Comments
 (0)