This commit is contained in:
fleyx 2023-10-11 17:34:26 +08:00
parent 69dcbd22b0
commit cabe83d07d
9 changed files with 3272 additions and 1428 deletions

View File

@ -17,5 +17,12 @@ router["GET /qb/config"] = async function (ctx: Context) {
ctx.body = await service.getAddress();
};
/**
* qb配置
*/
router["GET /qb/bt/list"] = async function (ctx: Context) {
ctx.body = await service.getAddress();
};
export default router;

View File

@ -0,0 +1,28 @@
export default interface BtListItemDto {
hash: string;
/**
*
*/
added_on: number;
/**
* left bytes num
*/
amount_left: number;
/**
* Percentage of file pieces currently available
*/
availability: number;
category: string;
/**
* Amount of transfer data completed (bytes)
*/
completed: number;
/**
* Time (Unix Epoch) when the torrent completed
*/
completion_on: number;
/**
* Absolute path of torrent content (root path for multifile torrents, absolute file path for singlefile torrents)
*/
content_path: string;
}

View File

@ -1,6 +0,0 @@
export default interface QbAddressDto {
address: string;
username: string;
password: string;
valid: boolean;
}

View File

@ -0,0 +1,22 @@
export default interface QbConfigDto {
address: string;
username: string;
password: string;
valid: boolean;
/**
* qb version,null if config is error
*/
version: string;
/**
* Qbittorrent's download
*/
qbDownloadPath: string;
/**
* Qbittorrent's download path corresponds to current system path
*/
renameQbDownloadPath: string;
/**
* config path to select convenient
*/
configPaths: Array<string>;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,8 @@
import QbAddressDto from "../entity/dto/QbAddressDto";
import {tryLogin, updateQbInfo, getQbInfo} from '../util/QbApiUtil';
import QbConfigDto from "../entity/dto/QbConfigDto";
import {tryLogin, get, post, updateQbInfo, getQbInfo} from '../util/QbApiUtil';
import GlobalConfigService from "./GlobalConfigService";
import GlobalConfig from "../entity/po/GlobalConfig";
import BtListItemDto from "../entity/dto/BtListItemDto";
class QbService {
@ -9,32 +10,40 @@ class QbService {
*
* @param body
*/
static async saveAddress(body: QbAddressDto): Promise<boolean> {
await GlobalConfigService.insertOrReplace(new GlobalConfig("qbAddress", body.address, "qbAdress"));
await GlobalConfigService.insertOrReplace(new GlobalConfig("qbUsername", body.username, ""));
await GlobalConfigService.insertOrReplace(new GlobalConfig("qbPassword", body.password, ""));
body.valid = await tryLogin();
static async saveAddress(body: QbConfigDto): Promise<QbConfigDto> {
if (body.address.endsWith("/")) {
body.address = body.address.substring(0, body.address.length - 1);
}
await GlobalConfigService.insertOrReplace(new GlobalConfig("qbConfig", JSON.stringify(body), "qb config"));
updateQbInfo(body);
return body.valid;
body.valid = await tryLogin();
body.version = body ? (await get("/app/version", null)) : null;
return body;
}
/**
*
*/
static async getAddress(): Promise<QbAddressDto> {
static async getAddress(): Promise<QbConfigDto> {
return getQbInfo();
}
static async getBtList(): Promise<Array<BtListItemDto>> {
let res = await get("/api/v2/torrents/info?category=&sort=added_on", null);
return res;
}
/**
*
*/
static async init() {
let config = await GlobalConfigService.getMultVal(["qbAddress", "qbUsername", "qbPassword"]);
let qbInfo: QbAddressDto = {
address: config.qbAddress,
username: config.qbUsername,
password: config.qbPassword,
valid: true
}
let config = await GlobalConfigService.getVal("qbConfig");
let qbInfo: QbConfigDto = config == null ? {} : JSON.parse(config);
updateQbInfo(qbInfo);
qbInfo.valid = await tryLogin();
qbInfo.version = qbInfo.valid ? (await get("/app/version", null)) : null;
return qbInfo;
}
}

View File

@ -1,13 +1,13 @@
import {Method} from "axios";
import axios from "axios";
import querystring from "querystring";
import QbAddressDto from "../entity/dto/QbAddressDto";
import QbConfigDto from "../entity/dto/QbConfigDto";
import GlobalService from '../service/GlobalConfigService';
let qbInfo: QbAddressDto = null;
let cookie: string = null;
let qbInfo: QbConfigDto = null;
let cookie: any = null;
export function updateQbInfo(info: QbAddressDto) {
export function updateQbInfo(info: QbConfigDto) {
qbInfo = info;
}
@ -15,12 +15,12 @@ export function getQbInfo() {
return qbInfo;
}
export function get() {
export async function get(url: string, data: object) {
return await request("get", url, data, null, false);
}
export function post() {
export async function post(url: string, data: object, isForm = false) {
return await request("post", url, null, data, isForm);
}
async function request(method: Method, url: string, query: any, body: any, isForm = false) {
@ -37,7 +37,7 @@ async function request(method: Method, url: string, query: any, body: any, isFor
}
let res = await axios.request({
baseURL: qbInfo.address,
url: url,
url: "/api/v2" + url,
method,
params: query,
data: body,
@ -71,7 +71,7 @@ export async function tryLogin(): Promise<boolean> {
});
let success = res.data.toLocaleLowerCase().indexOf('ok') > -1;
if (success) {
cookie = res.headers['Cookie'];
cookie = res.headers['set-cookie'];
}
qbInfo.valid = success;
return success;

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +1,11 @@
<template>
<div>配置qb</div>
<div class="item">
<div class="left">qb信息</div>
<div class="right">{{ qbInfo }}
<el-button @click="editInfo = true">编辑</el-button>
</div>
</div>
<el-form v-if="editInfo" :model="data.qbConfig" label-width="4em">
<el-form-item label="qb地址">
<el-input type="text" v-model="data.qbConfig.address" placeholder="例如:http://192.168.1.4:8080"/>
<el-form :model="data.qbConfig" label-width="8em">
<el-form-item label="qb版本">
{{ data.qbConfig.version ? data.qbConfig.version : "配置错误,无法访问" }}
</el-form-item>
<el-form-item label="访问地址">
<el-input type="text" v-model="data.qbConfig.address" placeholder="qb访问地址"/>
</el-form-item>
<el-form-item label="用户名">
<el-input type="text" v-model="data.qbConfig.username" placeholder="qb访问用户名"/>
@ -16,6 +13,12 @@
<el-form-item label="密码">
<el-input type="password" v-model="data.qbConfig.password" placeholder="qb访问密码"/>
</el-form-item>
<el-form-item label="qb下载路径">
<el-input type="text" v-model="data.qbConfig.qbDownloadPath" placeholder="qb下载路径(qb中选择的下载路径)"/>
</el-form-item>
<el-form-item label="对应本系统路径">
<el-input type="text" v-model="data.qbConfig.renameQbDownloadPath" placeholder="qb下载路径对应到本软件中的路径"/>
</el-form-item>
<div style="text-align: center">
<el-button type="" @click="editInfo = false">取消</el-button>
<el-button type="primary" @click="submitQb">提交</el-button>
@ -28,35 +31,17 @@ import {ref, reactive, onMounted, computed} from "vue";
import http from "@/utils/HttpUtil";
//
const data = reactive({
currentQbConfig: {},
qbConfig: {
address: "",
username: "",
password: "",
},
qbConfig: {},
});
//qb访
let qbReach = ref(true);
let editInfo = ref(false);
const qbInfo = computed(() => {
console.log("数据变了", data.qbConfig);
if (data.currentQbConfig.address) {
return data.qbConfig.address + " 用户名:" + data.qbConfig.username + " " + (data.currentQbConfig.valid ? "配置有效" : "配置无效");
} else {
return "尚未配置";
}
});
onMounted(async () => {
data.currentQbConfig = await http.get("/qb/config");
data.qbConfig.address = data.currentQbConfig.address;
data.qbConfig.username = data.currentQbConfig.username;
data.qbConfig.password = data.currentQbConfig.password;
data.qbConfig = await http.get("/qb/config");
});
async function submitQb() {
let res = await http.post("/qb/saveQbInfo", null, qbBody);
data.qbConfig = await http.post("/qb/saveQbInfo", null, data.qbConfig);
}
</script>