use of io.discloader.discloader.client.render.util.Resource in project DiscLoader by R3alCl0ud.
the class ModContainer method handleAssets.
private void handleAssets() {
ZipFile zip = null;
try {
try {
zip = mod.getZipFile();
} catch (ZipException e) {
e.printStackTrace();
}
if (zip != null) {
for (ZipEntry e : readEntries(zip.entries())) {
if (!e.getName().startsWith("assets/" + modInfo.modid()))
continue;
String name = e.getName().substring(("assets/" + modInfo.modid()).length() + 1);
Resource r = new Resource(modInfo.modid(), name);
ResourceManager.instance.addResource(r);
}
}
} catch (Exception e1) {
e1.printStackTrace();
}
}
use of io.discloader.discloader.client.render.util.Resource in project DiscLoader by R3alCl0ud.
the class APIRequest method createRequest.
public BaseRequest createRequest() throws IOException {
BaseRequest request = null;
switch(this.method) {
case Methods.GET:
request = Unirest.get(this.route);
break;
case Methods.POST:
request = Unirest.post(this.route);
if (multi) {
// try {
SendableMessage sdata = (SendableMessage) this.data;
File file = sdata.file;
Resource resource = sdata.resource;
byte[] bytes = new byte[0];
if (file != null)
bytes = DLUtil.readAllBytes(file);
if (resource != null)
bytes = DLUtil.readAllBytes(resource);
MultipartBody body = ((HttpRequestWithBody) request).fields(null);
String loc = "";
if (file != null)
loc = file.getName();
if (resource != null)
loc = resource.getFileName();
body.field("Content-type", "multipart/form-data").field("file", bytes, loc).field("payload_json", gson.toJson(sdata));
// } catch (IOException ex) {
// ex.printStackTrace();
// }
} else {
((HttpRequestWithBody) request).body(gson.toJson(data));
}
break;
case Methods.PATCH:
request = Unirest.patch(this.route);
((HttpRequestWithBody) request).body(gson.toJson(data));
break;
case Methods.DELETE:
request = Unirest.delete(this.route);
break;
case DLUtil.Methods.PUT:
request = Unirest.put(this.route);
((HttpRequestWithBody) request).body(gson.toJson(this.data));
break;
default:
request = Unirest.get(this.route);
break;
}
return request;
}
use of io.discloader.discloader.client.render.util.Resource in project DiscLoader by R3alCl0ud.
the class Route method createRequest.
public BaseRequest createRequest(Request<T> request) {
BaseRequest base = null;
switch(method) {
case GET:
base = Unirest.get(endpoint);
break;
case POST:
base = Unirest.post(endpoint);
if (request.getData() instanceof SendableMessage) {
MultipartBody body = ((HttpRequestWithBody) base).fields(null);
body.field("Content-Type", "multipart/form-data");
SendableMessage sdata = (SendableMessage) request.getData();
if (sdata.file != null || sdata.resource != null) {
try {
File file = sdata.file;
Resource resource = sdata.resource;
byte[] bytes = new byte[0];
if (file != null)
bytes = DLUtil.readAllBytes(file);
if (resource != null && resource.getResourceAsStream() != null)
bytes = DLUtil.readAllBytes(resource);
String loc = "";
if (file != null)
loc = file.getName();
if (resource != null)
loc = resource.getFileName();
body.field("file", bytes, loc);
} catch (Exception ex) {
ex.printStackTrace();
}
}
try {
if (request.getData() instanceof JSONObject) {
body.field("payload_json", request.getData().toString());
} else if (request.getData() instanceof String) {
body.field("payload_json", request.getData());
} else {
body.field("payload_json", gson.toJson(request.getData()));
}
} catch (Exception ex) {
ex.printStackTrace();
}
} else {
base.getHttpRequest().header("Content-Type", "application/json");
if (request.getData() instanceof JSONObject) {
((HttpRequestWithBody) base).body(request.getData().toString());
} else if (request.getData() instanceof String) {
((HttpRequestWithBody) base).body(request.getData());
} else {
((HttpRequestWithBody) base).body(gson.toJson(request.getData()));
}
}
break;
case DELETE:
base = Unirest.delete(endpoint);
break;
case PATCH:
base = Unirest.patch(endpoint);
base.getHttpRequest().header("Content-Type", "application/json");
if (request.getData() instanceof JSONObject) {
((HttpRequestWithBody) base).body(request.getData().toString());
} else if (request.getData() instanceof String) {
((HttpRequestWithBody) base).body(request.getData().toString());
} else {
((HttpRequestWithBody) base).body(gson.toJson(request.getData()));
}
break;
case PUT:
base = Unirest.put(endpoint);
base.getHttpRequest().header("Content-Type", "application/json");
if (request.getData() instanceof JSONObject) {
((HttpRequestWithBody) base).body(request.getData().toString());
} else if (request.getData() instanceof String) {
((HttpRequestWithBody) base).body(request.getData());
} else {
((HttpRequestWithBody) base).body(gson.toJson(request.getData()));
}
break;
default:
base = Unirest.get(endpoint);
break;
}
// body.
HttpRequest httprequest = base.getHttpRequest();
if (auth && rest.loader.token != null)
httprequest.header("Authorization", rest.loader.token);
if (request.getOptions() != null && request.getOptions().getReason() != null) {
httprequest.header("X-Audit-Log-Reason", request.getOptions().getReason());
System.out.println("is this thing working?");
}
httprequest.header("user-agent", "DiscordBot (http://discloader.io, v0.2.0)");
httprequest.header("Accept-Encoding", "gzip");
return base;
}
Aggregations