Skip to content

Commit

Permalink
fix: qbittorrent get cookie api.
Browse files Browse the repository at this point in the history
  • Loading branch information
chivehao committed Oct 18, 2024
1 parent b421b91 commit b1be99e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

# 17.1.1

- 修复qBitTorrent的login接口格式问题

# 17.1.0

- 升级适配本地0.17.0
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
group=run.ikaros.plugin
description=A mikan plugin for ikaros.
version=17.1.0
version=17.1.1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;
Expand Down Expand Up @@ -98,7 +97,7 @@ public synchronized void refreshHttpHeadersCookies() {
&& StringUtils.isNotBlank(config.getQbPassword())) {
try {
List<String> cookies =
getCookieByLogin(config.getQbUsername(), config.getQbPassword());
getCookieByPostLogin(config.getQbUsername(), config.getQbPassword());
this.httpHeaders.clear();
this.httpHeaders.put(HttpHeaders.COOKIE, cookies);
} catch (Exception exception) {
Expand Down Expand Up @@ -162,21 +161,23 @@ public void init() throws Exception {
}

@Retryable
public List<String> getCookieByLogin(String username, String password) {
public List<String> getCookieByPostLogin(String username, String password) {
if (StringUtils.isBlank(username)) {
username = DefaultConst.OPTION_QBITTORRENT_USERNAME;
}
if (StringUtils.isBlank(password)) {
password = DefaultConst.OPTION_QBITTORRENT_PASSWORD;
}

UriComponents uriComponents = UriComponentsBuilder.fromHttpUrl(getUrlPrefix() + API.AUTH)
.queryParam("username", username)
.queryParam("password", password)
.build();
MultiValueMap<String, Object> requestBody = new LinkedMultiValueMap<>();
requestBody.put("username", List.of(username));
requestBody.put("password", List.of(password));

HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(requestBody, httpHeaders);


ResponseEntity<String> responseEntity =
restTemplate.getForEntity(uriComponents.toUriString(), String.class);
restTemplate.postForEntity(getUrlPrefix() + API.AUTH, requestEntity, String.class);
if (responseEntity.getBody() != null && responseEntity.getBody().contains("Ok")) {
HttpHeaders headers = responseEntity.getHeaders();
List<String> cookies = headers.get("set-cookie");
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: PluginMikan
# plugin entry class that extends BasePlugin
clazz: run.ikaros.plugin.mikan.MikanPlugin
# plugin 'version' is a valid semantic version string (see semver.org).
version: 17.1.0
version: 17.1.1
requires: ">=0.17.0"
author:
name: Ikaros OSS Team
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@

class QbittorrentClientTest {

@Test
void testGetCookieByPostLogin() {

QbConfig config = new QbConfig();
config.setQbUrlPrefix("http://192.168.9.10:8181");
config.setQbUsername("admin");
config.setQbPassword("adminadmin");

QbittorrentClient qbittorrentClient = new QbittorrentClient(null);
qbittorrentClient.setConfig(config);
qbittorrentClient.getCookieByPostLogin(config.getQbUsername(), config.getQbPassword());
}

// @Test
void testAddTorrentFromUrl() throws Exception {
String name =
Expand Down

0 comments on commit b1be99e

Please sign in to comment.