use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.
the class Theme method votePost.
public String votePost(int postId, boolean type) throws Exception {
NetworkResponse response = Api.getWebClient().get("https://4pda.ru/forum/zka.php?i=".concat(Integer.toString(postId)).concat("&v=").concat(type ? "1" : "-1"));
String result = null;
Matcher m = Pattern.compile("ok:\\s*?((?:\\+|\\-)?\\d+)").matcher(response.getBody());
if (m.find()) {
int code = Integer.parseInt(m.group(1));
switch(code) {
case 0:
result = "Ошибка: Вы уже голосовали за это сообщение";
break;
case 1:
result = "Репутация поста повышена";
break;
case -1:
result = "Репутация поста понижена";
break;
}
}
if (result == null)
result = "Ошибка изменения репутации поста";
return result;
}
use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.
the class Theme method deletePost.
public Boolean deletePost(int postId) throws Exception {
String url = "https://4pda.ru/forum/index.php?act=zmod&auth_key=".concat(Api.getWebClient().getAuthKey()).concat("&code=postchoice&tact=delete&selectedpids=").concat(Integer.toString(postId));
NetworkResponse response = Api.getWebClient().request(new NetworkRequest.Builder().url(url).xhrHeader().build());
return response.getBody().equals("ok");
}
use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.
the class EditPost method deleteFiles.
public List<AttachmentItem> deleteFiles(int postId, List<AttachmentItem> items) throws Exception {
NetworkResponse response;
Matcher matcher;
for (AttachmentItem item : items) {
response = Api.getWebClient().get("https://4pda.ru/forum/index.php?&act=attach&code=attach_upload_remove&attach_rel_id=".concat(postId == 0 ? "" : Integer.toString(postId)).concat("&attach_id=").concat(Integer.toString(item.getId())));
matcher = statusInfo.matcher(response.getBody());
if (matcher.find())
fillAttachmentStatus(item, matcher);
}
return items;
}
use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.
the class EditPost method uploadFilesV2.
public List<AttachmentItem> uploadFilesV2(int postId, List<RequestFile> files, List<AttachmentItem> pending) throws Exception {
NetworkRequest.Builder builder = new NetworkRequest.Builder().url("https://4pda.ru/forum/index.php?act=attach").xhrHeader().formHeader("index", "1").formHeader("relId", Integer.toString(postId)).formHeader("maxSize", "134217728").formHeader("allowExt", "").formHeader("forum-attach-files", "").formHeader("code", "check");
NetworkResponse response;
Matcher matcher = null;
for (int i = 0; i < files.size(); i++) {
RequestFile file = files.get(i);
AttachmentItem item = pending.get(i);
file.setRequestName("FILE_UPLOAD[]");
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
byte[] targetArray = new byte[file.getFileStream().available()];
file.getFileStream().read(targetArray);
InputStream is1 = new ByteArrayInputStream(targetArray);
file.getFileStream().close();
file.setFileStream(is1);
messageDigest.update(targetArray);
byte[] hash = messageDigest.digest();
String md5 = ByteArraytoHexString(hash);
builder.formHeader("md5", md5).formHeader("size", "" + file.getFileStream().available()).formHeader("name", file.getFileName());
response = Api.getWebClient().request(builder.build());
if (response.getBody().equals("0")) {
NetworkRequest.Builder uploadRequest = new NetworkRequest.Builder().url("https://4pda.ru/forum/index.php?act=attach").xhrHeader().formHeader("index", "1").formHeader("relId", Integer.toString(postId)).formHeader("maxSize", "134217728").formHeader("allowExt", "").formHeader("forum-attach-files", "").formHeader("code", "upload").file(file);
response = Api.getWebClient().request(uploadRequest.build(), item.getProgressListener());
}
if (matcher == null) {
matcher = attachmentsPattern.matcher(response.getBody());
} else {
matcher = matcher.reset(response.getBody());
}
if (matcher.find()) {
fillAttachmentV2(item, matcher);
}
item.setStatus(AttachmentItem.STATUS_UPLOADED);
}
return pending;
}
use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.
the class EditPost method loadForm.
public EditPostForm loadForm(int postId) throws Exception {
EditPostForm form = new EditPostForm();
String url = "https://4pda.ru/forum/index.php?act=post&do=edit_post&p=".concat(Integer.toString(postId));
// url = url.concat("&t=").concat(Integer.toString(topicId)).concat("&f=").concat(Integer.toString(forumId));
NetworkResponse response = Api.getWebClient().get(url);
if (response.getBody().equals("nopermission")) {
form.setErrorCode(EditPostForm.ERROR_NO_PERMISSION);
return form;
}
Matcher matcher = postPattern.matcher(response.getBody());
if (matcher.find()) {
form.setMessage(ApiUtils.fromHtml(ApiUtils.escapeNewLine(matcher.group(1))));
form.setEditReason(matcher.group(2));
}
matcher = pollInfoPattern.matcher(response.getBody());
if (matcher.find()) {
EditPoll poll = createPoll(matcher);
form.setPoll(poll);
EditPost.printPoll(poll);
}
response = Api.getWebClient().get("https://4pda.ru/forum/index.php?act=attach&index=1&relId=" + postId + "&maxSize=134217728&allowExt=&code=init&unlinked=");
matcher = attachmentsPattern.matcher(response.getBody());
while (matcher.find()) {
form.addAttachment(fillAttachmentV2(new AttachmentItem(), matcher));
}
return form;
}
Aggregations