Skip to content

Commit

Permalink
v3.3.8 修复分页异常问题
Browse files Browse the repository at this point in the history
  • Loading branch information
LuckyPuppy514 committed Aug 6, 2023
1 parent 429132b commit cccd3d6
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 65 deletions.
4 changes: 4 additions & 0 deletions changelog.en_US.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

# Change Logs

## v3.3.8 2023-08-06

1. Fix bug of pagination

## v3.3.7 2023-08-06

1. Optimize search logic
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

# 变更日志

## v3.3.8 2023-08-06

1. 处理分页异常问题

## v3.3.7 2023-08-06

1. 优化查询逻辑
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<!-- 项目信息 -->
<groupId>com.lckp</groupId>
<artifactId>jproxy</artifactId>
<version>3.3.7</version>
<version>3.3.8</version>
<name>JProxy</name>
<description>介于 Sonarr/Radarr 和 Jackett/Prowlarr 之间的代理,主要用于优化查询和提升识别率</description>
<!-- 依赖版本 -->
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/lckp/jproxy/filter/IndexerFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
if (count > 0 || xml.length() == 0) {
xml = XmlUtil.merger(xml, newXml);
}
// 处理 Prowlarr 分页异常
if (count > indexerRequest.getLimit()) {
xml = XmlUtil.remove(xml, 99);
break;
}
if (++index >= size) {
break;
}
Expand Down
146 changes: 83 additions & 63 deletions src/main/java/com/lckp/jproxy/util/XmlUtil.java
Original file line number Diff line number Diff line change
@@ -1,63 +1,83 @@
package com.lckp.jproxy.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;

import com.lckp.jproxy.constant.ApiField;

/**
* <p>
* xml 工具类
* </p>
*
* @author LuckyPuppy514
* @date 2023-03-18
*/
public class XmlUtil {
XmlUtil() {
}

/**
*
* 计算 xml 中的 ApiField.INDEXER_ITEM 数量
*
* @param xml
* @return int
*/
public static int count(String xml) {
int count = 0;
if (StringUtils.isBlank(xml)) {
return count;
}
Matcher matcher = Pattern.compile("<" + ApiField.INDEXER_ITEM + ">[^<]+").matcher(xml);
while (matcher.find()) {
count++;
}
return count;
}

/**
*
* 合并
*
* @param xml1
* @param xml2
* @return String
*/
public static String merger(String xml1, String xml2) {
int index = xml1.indexOf("<" + ApiField.INDEXER_ITEM + ">");
if (index == -1) {
return xml2;
}
index = xml2.indexOf("<" + ApiField.INDEXER_ITEM + ">");
if (index == -1) {
return xml1;
}
StringBuilder builder = new StringBuilder();
builder.append(xml1.substring(0, xml1.indexOf("</" + ApiField.INDEXER_CHANNEL + ">")));
builder.append(xml2.substring(xml2.indexOf("<" + ApiField.INDEXER_ITEM + ">")));
return builder.toString();
}
}
package com.lckp.jproxy.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;

import com.lckp.jproxy.constant.ApiField;

/**
* <p>
* xml 工具类
* </p>
*
* @author LuckyPuppy514
* @date 2023-03-18
*/
public class XmlUtil {
XmlUtil() {
}

/**
*
* 计算 xml 中的 ApiField.INDEXER_ITEM 数量
*
* @param xml
* @return int
*/
public static int count(String xml) {
int count = 0;
if (StringUtils.isBlank(xml)) {
return count;
}
Matcher matcher = Pattern.compile("<" + ApiField.INDEXER_ITEM + ">[^<]+").matcher(xml);
while (matcher.find()) {
count++;
}
return count;
}

/**
*
* 合并
*
* @param xml1
* @param xml2
* @return String
*/
public static String merger(String xml1, String xml2) {
int index = xml1.indexOf("<" + ApiField.INDEXER_ITEM + ">");
if (index == -1) {
return xml2;
}
index = xml2.indexOf("<" + ApiField.INDEXER_ITEM + ">");
if (index == -1) {
return xml1;
}
StringBuilder builder = new StringBuilder();
builder.append(xml1.substring(0, xml1.indexOf("</" + ApiField.INDEXER_CHANNEL + ">")));
builder.append(xml2.substring(xml2.indexOf("<" + ApiField.INDEXER_ITEM + ">")));
return builder.toString();
}

/**
*
* 移除多余结果
*
* @param xml
* @param limit
* @return String
*/
public static String remove(String xml, int limit) {
int count = 0;
int index = 0;
String itemPrefix = "<" + ApiField.INDEXER_ITEM + ">";
String itemSuffix = "</" + ApiField.INDEXER_ITEM + ">";
while (count++ <= limit) {
index = xml.indexOf(itemPrefix, index + 1);
}
xml = xml.substring(0, index) + xml.substring(xml.lastIndexOf(itemSuffix) + itemSuffix.length());
return xml;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/rule/[email protected]

Large diffs are not rendered by default.

0 comments on commit cccd3d6

Please sign in to comment.