temp
This commit is contained in:
parent
69dcbd22b0
commit
cabe83d07d
@ -17,5 +17,12 @@ router["GET /qb/config"] = async function (ctx: Context) {
|
|||||||
ctx.body = await service.getAddress();
|
ctx.body = await service.getAddress();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取qb配置
|
||||||
|
*/
|
||||||
|
router["GET /qb/bt/list"] = async function (ctx: Context) {
|
||||||
|
ctx.body = await service.getAddress();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
28
openRenamerBackend/entity/dto/BtListItemDto.ts
Normal file
28
openRenamerBackend/entity/dto/BtListItemDto.ts
Normal 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;
|
||||||
|
}
|
@ -1,6 +0,0 @@
|
|||||||
export default interface QbAddressDto {
|
|
||||||
address: string;
|
|
||||||
username: string;
|
|
||||||
password: string;
|
|
||||||
valid: boolean;
|
|
||||||
}
|
|
22
openRenamerBackend/entity/dto/QbConfigDto.ts
Normal file
22
openRenamerBackend/entity/dto/QbConfigDto.ts
Normal 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>;
|
||||||
|
}
|
637
openRenamerBackend/pnpm-lock.yaml
generated
637
openRenamerBackend/pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,8 @@
|
|||||||
import QbAddressDto from "../entity/dto/QbAddressDto";
|
import QbConfigDto from "../entity/dto/QbConfigDto";
|
||||||
import {tryLogin, updateQbInfo, getQbInfo} from '../util/QbApiUtil';
|
import {tryLogin, get, post, updateQbInfo, getQbInfo} from '../util/QbApiUtil';
|
||||||
import GlobalConfigService from "./GlobalConfigService";
|
import GlobalConfigService from "./GlobalConfigService";
|
||||||
import GlobalConfig from "../entity/po/GlobalConfig";
|
import GlobalConfig from "../entity/po/GlobalConfig";
|
||||||
|
import BtListItemDto from "../entity/dto/BtListItemDto";
|
||||||
|
|
||||||
class QbService {
|
class QbService {
|
||||||
|
|
||||||
@ -9,32 +10,40 @@ class QbService {
|
|||||||
* 保存地址
|
* 保存地址
|
||||||
* @param body
|
* @param body
|
||||||
*/
|
*/
|
||||||
static async saveAddress(body: QbAddressDto): Promise<boolean> {
|
static async saveAddress(body: QbConfigDto): Promise<QbConfigDto> {
|
||||||
await GlobalConfigService.insertOrReplace(new GlobalConfig("qbAddress", body.address, "qbAdress"));
|
if (body.address.endsWith("/")) {
|
||||||
await GlobalConfigService.insertOrReplace(new GlobalConfig("qbUsername", body.username, ""));
|
body.address = body.address.substring(0, body.address.length - 1);
|
||||||
await GlobalConfigService.insertOrReplace(new GlobalConfig("qbPassword", body.password, ""));
|
}
|
||||||
body.valid = await tryLogin();
|
await GlobalConfigService.insertOrReplace(new GlobalConfig("qbConfig", JSON.stringify(body), "qb config"));
|
||||||
updateQbInfo(body);
|
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();
|
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() {
|
static async init() {
|
||||||
let config = await GlobalConfigService.getMultVal(["qbAddress", "qbUsername", "qbPassword"]);
|
let config = await GlobalConfigService.getVal("qbConfig");
|
||||||
let qbInfo: QbAddressDto = {
|
let qbInfo: QbConfigDto = config == null ? {} : JSON.parse(config);
|
||||||
address: config.qbAddress,
|
|
||||||
username: config.qbUsername,
|
|
||||||
password: config.qbPassword,
|
|
||||||
valid: true
|
|
||||||
}
|
|
||||||
updateQbInfo(qbInfo);
|
updateQbInfo(qbInfo);
|
||||||
qbInfo.valid = await tryLogin();
|
qbInfo.valid = await tryLogin();
|
||||||
|
qbInfo.version = qbInfo.valid ? (await get("/app/version", null)) : null;
|
||||||
|
return qbInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
import {Method} from "axios";
|
import {Method} from "axios";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import querystring from "querystring";
|
import querystring from "querystring";
|
||||||
import QbAddressDto from "../entity/dto/QbAddressDto";
|
import QbConfigDto from "../entity/dto/QbConfigDto";
|
||||||
import GlobalService from '../service/GlobalConfigService';
|
import GlobalService from '../service/GlobalConfigService';
|
||||||
|
|
||||||
let qbInfo: QbAddressDto = null;
|
let qbInfo: QbConfigDto = null;
|
||||||
let cookie: string = null;
|
let cookie: any = null;
|
||||||
|
|
||||||
export function updateQbInfo(info: QbAddressDto) {
|
export function updateQbInfo(info: QbConfigDto) {
|
||||||
qbInfo = info;
|
qbInfo = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -15,12 +15,12 @@ export function getQbInfo() {
|
|||||||
return qbInfo;
|
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) {
|
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({
|
let res = await axios.request({
|
||||||
baseURL: qbInfo.address,
|
baseURL: qbInfo.address,
|
||||||
url: url,
|
url: "/api/v2" + url,
|
||||||
method,
|
method,
|
||||||
params: query,
|
params: query,
|
||||||
data: body,
|
data: body,
|
||||||
@ -71,7 +71,7 @@ export async function tryLogin(): Promise<boolean> {
|
|||||||
});
|
});
|
||||||
let success = res.data.toLocaleLowerCase().indexOf('ok') > -1;
|
let success = res.data.toLocaleLowerCase().indexOf('ok') > -1;
|
||||||
if (success) {
|
if (success) {
|
||||||
cookie = res.headers['Cookie'];
|
cookie = res.headers['set-cookie'];
|
||||||
}
|
}
|
||||||
qbInfo.valid = success;
|
qbInfo.valid = success;
|
||||||
return success;
|
return success;
|
||||||
|
3892
openRenamerFront/pnpm-lock.yaml
generated
3892
openRenamerFront/pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1,14 +1,11 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>配置qb</div>
|
<div>配置qb</div>
|
||||||
<div class="item">
|
<el-form :model="data.qbConfig" label-width="8em">
|
||||||
<div class="left">qb信息</div>
|
<el-form-item label="qb版本">
|
||||||
<div class="right">{{ qbInfo }}
|
{{ data.qbConfig.version ? data.qbConfig.version : "配置错误,无法访问" }}
|
||||||
<el-button @click="editInfo = true">编辑</el-button>
|
</el-form-item>
|
||||||
</div>
|
<el-form-item label="访问地址">
|
||||||
</div>
|
<el-input type="text" v-model="data.qbConfig.address" placeholder="qb访问地址"/>
|
||||||
<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-item>
|
</el-form-item>
|
||||||
<el-form-item label="用户名">
|
<el-form-item label="用户名">
|
||||||
<el-input type="text" v-model="data.qbConfig.username" placeholder="qb访问用户名"/>
|
<el-input type="text" v-model="data.qbConfig.username" placeholder="qb访问用户名"/>
|
||||||
@ -16,6 +13,12 @@
|
|||||||
<el-form-item label="密码">
|
<el-form-item label="密码">
|
||||||
<el-input type="password" v-model="data.qbConfig.password" placeholder="qb访问密码"/>
|
<el-input type="password" v-model="data.qbConfig.password" placeholder="qb访问密码"/>
|
||||||
</el-form-item>
|
</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">
|
<div style="text-align: center">
|
||||||
<el-button type="" @click="editInfo = false">取消</el-button>
|
<el-button type="" @click="editInfo = false">取消</el-button>
|
||||||
<el-button type="primary" @click="submitQb">提交</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";
|
import http from "@/utils/HttpUtil";
|
||||||
//表单
|
//表单
|
||||||
const data = reactive({
|
const data = reactive({
|
||||||
currentQbConfig: {},
|
qbConfig: {},
|
||||||
qbConfig: {
|
|
||||||
address: "",
|
|
||||||
username: "",
|
|
||||||
password: "",
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
//qb是否可访问
|
//qb是否可访问
|
||||||
let qbReach = ref(true);
|
|
||||||
let editInfo = ref(false);
|
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 () => {
|
onMounted(async () => {
|
||||||
data.currentQbConfig = await http.get("/qb/config");
|
data.qbConfig = await http.get("/qb/config");
|
||||||
data.qbConfig.address = data.currentQbConfig.address;
|
|
||||||
data.qbConfig.username = data.currentQbConfig.username;
|
|
||||||
data.qbConfig.password = data.currentQbConfig.password;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
async function submitQb() {
|
async function submitQb() {
|
||||||
let res = await http.post("/qb/saveQbInfo", null, qbBody);
|
data.qbConfig = await http.post("/qb/saveQbInfo", null, data.qbConfig);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user