Skip to content

Commit

Permalink
NClientV2 3.0.0
Browse files Browse the repository at this point in the history
* Fixed wrong behaviour when using special url character (#574)
  • Loading branch information
Dar9586 committed Mar 3, 2023
1 parent 72f9a4d commit daa01a8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ android {
applicationId "com.dar.nclientv2"
minSdkVersion 14
targetSdkVersion 33
versionCode 299
versionCode 300
multiDexEnabled true
versionName "2.9.9-stable"
versionName "3.0.0-stable"
vectorDrawables.useSupportLibrary true
proguardFiles 'proguard-rules.pro'
}
Expand Down
13 changes: 4 additions & 9 deletions app/src/main/java/com/dar/nclientv2/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -831,15 +831,10 @@ public void onEnd() {
@Override
public void onFailure(Exception e) {
super.onFailure(e);
if (e instanceof InspectorV3.InvalidResponseException) {
CookieInterceptor interceptor = new CookieInterceptor(MANAGER);
interceptor.intercept();
} else {
showError(R.string.unable_to_connect_to_the_site, v -> {
inspector = inspector.cloneInspector(MainActivity.this, inspector.getResponse());
inspector.start();
});
}
showError(R.string.unable_to_connect_to_the_site, v -> {
inspector = inspector.cloneInspector(MainActivity.this, inspector.getResponse());
inspector.start();
});
}

@Override
Expand Down
23 changes: 11 additions & 12 deletions app/src/main/java/com/dar/nclientv2/api/InspectorV3.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
import org.jsoup.select.Elements;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.ref.WeakReference;
import java.net.HttpURLConnection;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -263,6 +265,12 @@ private void tryByAllPopular() {
}

private void createUrl() {
String query;
try {
query = this.query == null ? null : URLEncoder.encode(this.query, "UTF-8");
} catch (UnsupportedEncodingException ignore) {
query = this.query;
}
StringBuilder builder = new StringBuilder(Utility.getBaseUrl());
if (requestType == ApiRequestType.BYALL) builder.append("?page=").append(page);
else if (requestType == ApiRequestType.RANDOM) builder.append("random/");
Expand All @@ -274,19 +282,11 @@ else if (requestType == ApiRequestType.FAVORITE) {
builder.append("?q=").append(query).append('&');
else builder.append('?');
builder.append("page=").append(page);
}/*else if(requestType==ApiRequestType.BYTAG){
for(Tag tt:tags)t=tt;
assert t!=null;
builder.append(t.getTypeSingleName()).append('/')
.append(t.getName().replace(' ','-').replace(".",""));
if(byPopular)builder.append("/popular");
else builder.append('/');
builder.append("?page=").append(page);
}*/ else if (requestType == ApiRequestType.BYSEARCH || requestType == ApiRequestType.BYTAG) {
} else if (requestType == ApiRequestType.BYSEARCH || requestType == ApiRequestType.BYTAG) {
builder.append("search/?q=").append(query);
for (Tag tt : tags) {
if (builder.toString().contains(tt.toQueryTag(TagStatus.ACCEPTED))) continue;
builder.append('+').append(tt.toQueryTag());
builder.append('+').append(URLEncoder.encode(tt.toQueryTag()));
}
if (ranges != null)
builder.append('+').append(ranges.toQuery());
Expand Down Expand Up @@ -343,8 +343,7 @@ public void run() {
LogUtility.d("Starting download: " + url);
if (response != null) response.onStart();
try {
if (!createDocument())
throw new InvalidResponseException();
createDocument();
parseDocument();
if (response != null) {
response.onSuccess(galleries);
Expand Down

0 comments on commit daa01a8

Please sign in to comment.