Compare commits
6 Commits
861d5f35bf
...
4c8c1a355c
Author | SHA1 | Date | |
---|---|---|---|
|
4c8c1a355c | ||
|
f3bcacfc4a | ||
|
4b8a7829d9 | ||
|
164553abf0 | ||
|
cabe83d07d | ||
|
69dcbd22b0 |
@ -10,5 +10,19 @@ router["POST /qb/saveQbInfo"] = async function (ctx: Context) {
|
|||||||
ctx.body = await service.saveAddress(ctx.request.body);
|
ctx.body = await service.saveAddress(ctx.request.body);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取qb配置
|
||||||
|
*/
|
||||||
|
router["GET /qb/config"] = async function (ctx: Context) {
|
||||||
|
ctx.body = await service.getConfig();
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取qb配置
|
||||||
|
*/
|
||||||
|
router["GET /qb/bt/list"] = async function (ctx: Context) {
|
||||||
|
ctx.body = await service.getBtList();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
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,5 +0,0 @@
|
|||||||
export default interface QbAddressDto {
|
|
||||||
address: string;
|
|
||||||
username: string;
|
|
||||||
password: string;
|
|
||||||
}
|
|
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>;
|
||||||
|
}
|
@ -9,9 +9,8 @@ import handleError from "./middleware/handleError";
|
|||||||
import init from "./middleware/init";
|
import init from "./middleware/init";
|
||||||
import SqliteUtil from './util/SqliteHelper';
|
import SqliteUtil from './util/SqliteHelper';
|
||||||
import log from './util/LogUtil';
|
import log from './util/LogUtil';
|
||||||
import {updateQbInfo} from './util/QbApiUtil';
|
import QbService from './service/QbService';
|
||||||
import TimeUtil from "./util/TimeUtil";
|
import qbService from "./service/QbService";
|
||||||
|
|
||||||
|
|
||||||
console.log(config);
|
console.log(config);
|
||||||
|
|
||||||
@ -33,7 +32,7 @@ app.use(handleError);
|
|||||||
app.use(RouterMW(router, path.join(config.rootPath, "dist/api")));
|
app.use(RouterMW(router, path.join(config.rootPath, "dist/api")));
|
||||||
(async () => {
|
(async () => {
|
||||||
await SqliteUtil.createPool();
|
await SqliteUtil.createPool();
|
||||||
await updateQbInfo(null, null);
|
await qbService.init();
|
||||||
app.listen(config.port);
|
app.listen(config.port);
|
||||||
log.info(`server listened `, config.port);
|
log.info(`server listened `, config.port);
|
||||||
})();
|
})();
|
||||||
|
@ -1,16 +1,51 @@
|
|||||||
import QbAddressDto from "../entity/dto/QbAddressDto";
|
import QbConfigDto from "../entity/dto/QbConfigDto";
|
||||||
import { tryLogin, updateQbInfo } 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 {
|
||||||
|
|
||||||
static async saveAddress(body: QbAddressDto) {
|
/**
|
||||||
await tryLogin(body.address, body.username, body.password, false);
|
* 保存地址
|
||||||
await GlobalConfigService.insertOrReplace(new GlobalConfig("qbAddress", body.address, "qbAdress"));
|
* @param body
|
||||||
await GlobalConfigService.insertOrReplace(new GlobalConfig("qbUsername", body.username, ""));
|
*/
|
||||||
await GlobalConfigService.insertOrReplace(new GlobalConfig("qbPassword", body.password, ""));
|
static async saveAddress(body: QbConfigDto): Promise<QbConfigDto> {
|
||||||
await updateQbInfo(body, true);
|
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);
|
||||||
|
body.valid = await tryLogin();
|
||||||
|
body.version = body ? (await get("/app/version", null)) : null;
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
a
|
||||||
|
/**
|
||||||
|
* 获取当前配置
|
||||||
|
*/
|
||||||
|
static async getConfig(): Promise<QbConfigDto> {
|
||||||
|
return getQbInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get torrents list from qb
|
||||||
|
*/
|
||||||
|
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.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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,48 +1,30 @@
|
|||||||
import {Method} from "axios";
|
import {Method} from "axios";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import QbAddressDto from "../entity/dto/QbAddressDto";
|
import querystring from "querystring";
|
||||||
|
import QbConfigDto from "../entity/dto/QbConfigDto";
|
||||||
import GlobalService from '../service/GlobalConfigService';
|
import GlobalService from '../service/GlobalConfigService';
|
||||||
import { setUncaughtExceptionCaptureCallback } from "process";
|
|
||||||
|
|
||||||
//qb状态,true正常,false:无法访问
|
let qbInfo: QbConfigDto = null;
|
||||||
let qbStatus = true;
|
let cookie: any = null;
|
||||||
let qbInfo: QbAddressDto = null;
|
|
||||||
let cookie: string = null;
|
|
||||||
|
|
||||||
export function getQbStatus() {
|
export function updateQbInfo(info: QbConfigDto) {
|
||||||
return qbStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function updateQbInfo(info: QbAddressDto, status: boolean) {
|
|
||||||
if (!info) {
|
|
||||||
let obj = await GlobalService.getMultVal(["qbAddress", "qbUsername", "qbPassword"]);
|
|
||||||
if (!obj.qbAddress) {
|
|
||||||
qbStatus = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
qbInfo.address = obj.qbAddress;
|
|
||||||
qbInfo.username = obj.qbUsername;
|
|
||||||
qbInfo.password = obj.qbPassword;
|
|
||||||
} else {
|
|
||||||
qbInfo = info;
|
qbInfo = info;
|
||||||
}
|
}
|
||||||
if (status) {
|
|
||||||
qbStatus = status;
|
export function getQbInfo() {
|
||||||
|
return qbInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
axios.defaults.baseURL = qbInfo.address;
|
export async function get(url: string, data: object) {
|
||||||
|
return await request("get", url, data, null, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function get() {
|
export async function post(url: string, data: object, isForm = false) {
|
||||||
|
return await request("post", url, null, data, isForm);
|
||||||
}
|
|
||||||
|
|
||||||
export function post() {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
if (!qbStatus) {
|
if (!qbInfo.valid) {
|
||||||
throw new Error("qbittorrent无法连接,请检查配置");
|
throw new Error("qbittorrent无法连接,请检查配置");
|
||||||
}
|
}
|
||||||
let isTryLogin = false;
|
let isTryLogin = false;
|
||||||
@ -55,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,
|
||||||
@ -63,11 +45,12 @@ async function request(method: Method, url: string, query: any, body: any, isFor
|
|||||||
});
|
});
|
||||||
if (res.status == 200) {
|
if (res.status == 200) {
|
||||||
return res.data;
|
return res.data;
|
||||||
} if (res.status == 403) {
|
}
|
||||||
|
if (res.status == 403) {
|
||||||
if (isTryLogin) {
|
if (isTryLogin) {
|
||||||
throw new Error("qb用户名密码设置有误");
|
throw new Error("qb用户名密码设置有误");
|
||||||
} else {
|
} else {
|
||||||
await tryLogin(qbInfo.address, qbInfo.username, qbInfo.password, true);
|
await tryLogin();
|
||||||
isTryLogin = true;
|
isTryLogin = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -77,26 +60,24 @@ async function request(method: Method, url: string, query: any, body: any, isFor
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function tryLogin(address: string, username: string, password: string, updateStatus: boolean): Promise<void> {
|
export async function tryLogin(): Promise<boolean> {
|
||||||
let body = { username, password };
|
if (qbInfo == null || qbInfo.address == null || qbInfo.address == "") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
let body = {username: qbInfo.username, password: qbInfo.password};
|
||||||
try {
|
try {
|
||||||
let res = await axios.post(address + "/api/v2/auth/login", body, {
|
let res = await axios.post(qbInfo.address + `/api/v2/auth/login`, querystring.stringify(body), {
|
||||||
headers: { "Content-Type": "multipart/form-data;boundary=--------------------------125002698093981740970152" }
|
headers: {"Content-Type": "application/x-www-form-urlencoded"}
|
||||||
});
|
});
|
||||||
let success = res.data.toLocaleLowerCase().contains('ok');
|
let success = res.data.toLocaleLowerCase().indexOf('ok') > -1;
|
||||||
if (updateStatus) {
|
if (success) {
|
||||||
qbStatus = success;
|
cookie = res.headers['set-cookie'];
|
||||||
}
|
|
||||||
if (!success) {
|
|
||||||
throw new Error("登录失败");
|
|
||||||
} else {
|
|
||||||
cookie = res.headers['Cookie'];
|
|
||||||
}
|
}
|
||||||
|
qbInfo.valid = success;
|
||||||
|
return success;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("登录报错:", error);
|
console.error("登录报错:", error);
|
||||||
if (updateStatus) {
|
return false;
|
||||||
qbStatus = false;
|
|
||||||
}
|
|
||||||
throw new Error("登录出错");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
344
openRenamerBackend/util/TranslateUtil.ts
Normal file
344
openRenamerBackend/util/TranslateUtil.ts
Normal file
@ -0,0 +1,344 @@
|
|||||||
|
// ToolGood.Words.Translate.js
|
||||||
|
// 2020, Lin Zhijun, https://github.com/toolgood/ToolGood.Words
|
||||||
|
// Licensed under the Apache License 2.0
|
||||||
|
import {_s2t_s, _s2t_t, _t2hk_t, _t2hk_hk, _t2s_s, _t2tw_t, _t2s_t, _t2tw_tw} from './TranslateWord'
|
||||||
|
|
||||||
|
class TrieNode {
|
||||||
|
Index = 0;
|
||||||
|
Layer = 0;
|
||||||
|
End = false;
|
||||||
|
Char = '';
|
||||||
|
Results = [];
|
||||||
|
m_values = {};
|
||||||
|
Failure = null;
|
||||||
|
Parent = null;
|
||||||
|
|
||||||
|
public Add(c) {
|
||||||
|
if (this.m_values[c] != null) {
|
||||||
|
return this.m_values[c];
|
||||||
|
}
|
||||||
|
var node = new TrieNode();
|
||||||
|
node.Parent = this;
|
||||||
|
node.Char = c;
|
||||||
|
this.m_values[c] = node;
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public SetResults(index) {
|
||||||
|
if (this.End == false) {
|
||||||
|
this.End = true;
|
||||||
|
}
|
||||||
|
this.Results.push(index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class TrieNode2 {
|
||||||
|
End = false;
|
||||||
|
Results = [];
|
||||||
|
m_values = {};
|
||||||
|
minflag = 1;
|
||||||
|
maxflag = 0;
|
||||||
|
|
||||||
|
public Add(c, node3) {
|
||||||
|
if (typeof c !== 'number') {
|
||||||
|
c = parseInt(c);
|
||||||
|
}
|
||||||
|
if (this.minflag > c) {
|
||||||
|
this.minflag = c;
|
||||||
|
}
|
||||||
|
if (this.maxflag < c) {
|
||||||
|
this.maxflag = c;
|
||||||
|
}
|
||||||
|
this.m_values[c] = node3;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SetResults(index) {
|
||||||
|
if (this.End == false) {
|
||||||
|
this.End = true;
|
||||||
|
}
|
||||||
|
if (this.Results.indexOf(index) == -1) {
|
||||||
|
this.Results.push(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public HasKey(c) {
|
||||||
|
return this.m_values[c] != undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TryGetValue(c) {
|
||||||
|
if (this.minflag <= c && this.maxflag >= c) {
|
||||||
|
return this.m_values[c];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class WordsSearch {
|
||||||
|
|
||||||
|
|
||||||
|
_first: TrieNode2 = null;
|
||||||
|
_keywords = [];
|
||||||
|
_others = [];
|
||||||
|
|
||||||
|
public SetKeywords(keywords) {
|
||||||
|
this._keywords = keywords;
|
||||||
|
let root = new TrieNode();
|
||||||
|
|
||||||
|
let allNodeLayer = {};
|
||||||
|
for (let i = 0; i < this._keywords.length; i++) {
|
||||||
|
let p = this._keywords[i];
|
||||||
|
let nd = root;
|
||||||
|
for (let j = 0; j < p.length; j++) {
|
||||||
|
nd = nd.Add(p.charCodeAt(j));
|
||||||
|
if (nd.Layer == 0) {
|
||||||
|
nd.Layer = j + 1;
|
||||||
|
if (allNodeLayer[nd.Layer]) {
|
||||||
|
allNodeLayer[nd.Layer].push(nd)
|
||||||
|
} else {
|
||||||
|
allNodeLayer[nd.Layer] = [];
|
||||||
|
allNodeLayer[nd.Layer].push(nd)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
nd.SetResults(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
let allNode: TrieNode[] = [];
|
||||||
|
allNode.push(root);
|
||||||
|
for (let key in allNodeLayer) {
|
||||||
|
let nds = allNodeLayer[key];
|
||||||
|
for (let i = 0; i < nds.length; i++) {
|
||||||
|
allNode.push(nds[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
allNodeLayer = null;
|
||||||
|
|
||||||
|
for (let i = 1; i < allNode.length; i++) {
|
||||||
|
let nd: TrieNode = allNode[i];
|
||||||
|
nd.Index = i;
|
||||||
|
let r = nd.Parent.Failure;
|
||||||
|
let c = nd.Char;
|
||||||
|
while (r != null && !r.m_values[c])
|
||||||
|
r = r.Failure;
|
||||||
|
if (r == null)
|
||||||
|
nd.Failure = root;
|
||||||
|
else {
|
||||||
|
nd.Failure = r.m_values[c];
|
||||||
|
for (let key2 in nd.Failure.Results) {
|
||||||
|
if (nd.Failure.Results.hasOwnProperty(key2) == false) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let result = nd.Failure.Results[key2];
|
||||||
|
nd.SetResults(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
root.Failure = root;
|
||||||
|
|
||||||
|
let allNode2 = [];
|
||||||
|
for (let i = 0; i < allNode.length; i++) {
|
||||||
|
allNode2.push(new TrieNode2());
|
||||||
|
}
|
||||||
|
for (let i = 0; i < allNode2.length; i++) {
|
||||||
|
let oldNode = allNode[i];
|
||||||
|
let newNode = allNode2[i];
|
||||||
|
|
||||||
|
for (let key in oldNode.m_values) {
|
||||||
|
if (oldNode.m_values.hasOwnProperty(key) == false) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let index = oldNode.m_values[key].Index;
|
||||||
|
newNode.Add(key, allNode2[index]);
|
||||||
|
}
|
||||||
|
for (let index = 0; index < oldNode.Results.length; index++) {
|
||||||
|
let item = oldNode.Results[index];
|
||||||
|
newNode.SetResults(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
oldNode = oldNode.Failure;
|
||||||
|
while (oldNode != root) {
|
||||||
|
for (let key in oldNode.m_values) {
|
||||||
|
if (oldNode.m_values.hasOwnProperty(key) == false) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (newNode.HasKey(key) == false) {
|
||||||
|
let index = oldNode.m_values[key].Index;
|
||||||
|
newNode.Add(key, allNode2[index]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (let index = 0; index < oldNode.Results.length; index++) {
|
||||||
|
let item = oldNode.Results[index];
|
||||||
|
newNode.SetResults(item);
|
||||||
|
}
|
||||||
|
oldNode = oldNode.Failure;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
allNode = null;
|
||||||
|
root = null;
|
||||||
|
this._first = allNode2[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
public FindAll(text) {
|
||||||
|
var ptr = null;
|
||||||
|
var list = [];
|
||||||
|
|
||||||
|
for (let i = 0; i < text.length; i++) {
|
||||||
|
var t = text.charCodeAt(i);
|
||||||
|
var tn = null;
|
||||||
|
if (ptr == null) {
|
||||||
|
tn = this._first.TryGetValue(t);
|
||||||
|
} else {
|
||||||
|
tn = ptr.TryGetValue(t);
|
||||||
|
if (!tn) {
|
||||||
|
tn = this._first.TryGetValue(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (tn != null) {
|
||||||
|
if (tn.End) {
|
||||||
|
for (let j = 0; j < tn.Results.length; j++) {
|
||||||
|
var item = tn.Results[j];
|
||||||
|
var keyword = this._keywords[item];
|
||||||
|
list.push({
|
||||||
|
Keyword: keyword,
|
||||||
|
Success: true,
|
||||||
|
End: i,
|
||||||
|
Start: i + 1 - this._keywords[item].length,
|
||||||
|
Index: item,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ptr = tn;
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------
|
||||||
|
var s2tSearch = null; // WordsSearch
|
||||||
|
var t2sSearch = null;// WordsSearch
|
||||||
|
var t2twSearch = null;// WordsSearch
|
||||||
|
var tw2tSearch = null;// WordsSearch
|
||||||
|
var t2hkSearch = null;// WordsSearch
|
||||||
|
var hk2tSearch = null;// WordsSearch
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转繁体中文
|
||||||
|
* @param {any} text 原文本
|
||||||
|
* @param {any} type 0、繁体中文,1、港澳繁体,2、台湾正体
|
||||||
|
*/
|
||||||
|
export function ToTraditionalChinese(text: any, type: any) {
|
||||||
|
if (type == undefined) {
|
||||||
|
type = 0;
|
||||||
|
}
|
||||||
|
if (type > 2 || type < 0) {
|
||||||
|
throw "type 不支持该类型";
|
||||||
|
}
|
||||||
|
|
||||||
|
var s2t = GetWordsSearch(true, 0);
|
||||||
|
text = TransformationReplace(text, s2t);
|
||||||
|
if (type > 0) {
|
||||||
|
var t2 = GetWordsSearch(true, type);
|
||||||
|
text = TransformationReplace(text, t2);
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转简体中文
|
||||||
|
* @param {any} text 原文本
|
||||||
|
* @param {any} srcType 0、繁体中文,1、港澳繁体,2、台湾正体
|
||||||
|
*/
|
||||||
|
export function ToSimplifiedChinese(text: string, srcType: any) {
|
||||||
|
if (srcType == undefined) {
|
||||||
|
srcType = 0;
|
||||||
|
}
|
||||||
|
if (srcType > 2 || srcType < 0) {
|
||||||
|
throw "srcType 不支持该类型";
|
||||||
|
}
|
||||||
|
if (srcType > 0) {
|
||||||
|
var t2 = GetWordsSearch(false, srcType);
|
||||||
|
text = TransformationReplace(text, t2);
|
||||||
|
}
|
||||||
|
var s2t = GetWordsSearch(false, 0);
|
||||||
|
text = TransformationReplace(text, s2t);
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
function TransformationReplace(text: any, wordsSearch: any) {
|
||||||
|
var ts = wordsSearch.FindAll(text);
|
||||||
|
|
||||||
|
var sb = "";
|
||||||
|
var index = 0;
|
||||||
|
while (index < text.length) {
|
||||||
|
var t = null;
|
||||||
|
var max = -1;
|
||||||
|
for (var i = 0; i < ts.length; i++) {
|
||||||
|
var f = ts[i];
|
||||||
|
if (f.Start == index && f.End > max) {
|
||||||
|
max = f.End;
|
||||||
|
t = f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (t == null) {
|
||||||
|
sb += text[index];
|
||||||
|
index++;
|
||||||
|
} else {
|
||||||
|
sb += wordsSearch._others[t.Index]
|
||||||
|
index = t.End + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb;
|
||||||
|
}
|
||||||
|
|
||||||
|
function GetWordsSearch(s2t: boolean, srcType: number) {
|
||||||
|
if (s2t) {
|
||||||
|
if (srcType === 0) {
|
||||||
|
if (s2tSearch == null) {
|
||||||
|
s2tSearch = BuildWordsSearch(_s2t_s, _s2t_t);
|
||||||
|
}
|
||||||
|
return s2tSearch;
|
||||||
|
} else if (srcType === 1) {
|
||||||
|
if (t2hkSearch == null) {
|
||||||
|
t2hkSearch = BuildWordsSearch(_t2hk_t, _t2hk_hk);
|
||||||
|
}
|
||||||
|
return t2hkSearch;
|
||||||
|
} else if (srcType == 2) {
|
||||||
|
if (t2twSearch == null) {
|
||||||
|
t2twSearch = BuildWordsSearch(_t2tw_t, _t2tw_tw);
|
||||||
|
}
|
||||||
|
return t2twSearch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (srcType == 0) {
|
||||||
|
if (t2sSearch == null) {
|
||||||
|
t2sSearch = BuildWordsSearch(_t2s_t, _t2s_s);
|
||||||
|
}
|
||||||
|
return t2sSearch;
|
||||||
|
} else if (srcType == 1) {
|
||||||
|
if (hk2tSearch == null) {
|
||||||
|
hk2tSearch = BuildWordsSearch(_t2hk_hk, _t2hk_t);
|
||||||
|
}
|
||||||
|
return hk2tSearch;
|
||||||
|
} else if (srcType == 2) {
|
||||||
|
if (tw2tSearch == null) {
|
||||||
|
tw2tSearch = BuildWordsSearch(_t2tw_tw, _t2tw_t);
|
||||||
|
}
|
||||||
|
return tw2tSearch;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function BuildWordsSearch(keywords: string[], toWords: any[]) {
|
||||||
|
var wordsSearch = new WordsSearch();
|
||||||
|
wordsSearch.SetKeywords(keywords);
|
||||||
|
wordsSearch._others = toWords;
|
||||||
|
return wordsSearch;
|
||||||
|
}
|
8
openRenamerBackend/util/TranslateWord.ts
Normal file
8
openRenamerBackend/util/TranslateWord.ts
Normal file
File diff suppressed because one or more lines are too long
@ -49,17 +49,6 @@ export default {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
async beforeCreate() {
|
async beforeCreate() {
|
||||||
console.log("beforeCreate");
|
|
||||||
let queryMap = {};
|
|
||||||
location.search.substring(1).split("&").forEach(item => {
|
|
||||||
let arr = item.split("=");
|
|
||||||
queryMap[arr[0]] = arr[1];
|
|
||||||
})
|
|
||||||
if (queryMap.port) {
|
|
||||||
window.baseUrl = "http://localhost:" + queryMap.port;
|
|
||||||
} else {
|
|
||||||
window.baseUrl = "";
|
|
||||||
}
|
|
||||||
window.token = localStorage.getItem("token");
|
window.token = localStorage.getItem("token");
|
||||||
window.isWindows = await httpUtil.get("/file/isWindows");
|
window.isWindows = await httpUtil.get("/file/isWindows");
|
||||||
},
|
},
|
||||||
|
@ -1,13 +1,24 @@
|
|||||||
<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 }}<el-button @click="editInfo = true">编辑</el-button></div>
|
{{ data.qbConfig.version ? data.qbConfig.version : "配置错误,无法访问" }}
|
||||||
</div>
|
</el-form-item>
|
||||||
<el-form v-if="editInfo" :model="qbBody" label-width="4em">
|
<el-form-item label="访问地址">
|
||||||
<el-form-item label="qb地址"><el-input type="text" v-model="qbBody.address" placeholder="例如:http://192.168.1.4:8080" /></el-form-item>
|
<el-input type="text" v-model="data.qbConfig.address" placeholder="例如:http://localhost:8080(仅支持v4.1及以上)"/>
|
||||||
<el-form-item label="用户名"><el-input type="text" v-model="qbBody.username" placeholder="qb访问用户名" /></el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="密码"><el-input type="password" v-model="qbBody.password" placeholder="qb访问密码" /></el-form-item>
|
<el-form-item label="用户名">
|
||||||
|
<el-input type="text" v-model="data.qbConfig.username" placeholder="qb访问用户名"/>
|
||||||
|
</el-form-item>
|
||||||
|
<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">
|
<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>
|
||||||
@ -19,31 +30,18 @@
|
|||||||
import {ref, reactive, onMounted, computed} from "vue";
|
import {ref, reactive, onMounted, computed} from "vue";
|
||||||
import http from "@/utils/HttpUtil";
|
import http from "@/utils/HttpUtil";
|
||||||
//表单
|
//表单
|
||||||
const qbBody = reactive({
|
const data = reactive({
|
||||||
address: "",
|
qbConfig: {},
|
||||||
username: "",
|
|
||||||
password: "",
|
|
||||||
});
|
});
|
||||||
//配置中心数据
|
|
||||||
let downloadConfig = reactive({});
|
|
||||||
//qb是否可访问
|
//qb是否可访问
|
||||||
let qbReach = ref(true);
|
|
||||||
let editInfo = ref(false);
|
let editInfo = ref(false);
|
||||||
|
|
||||||
const qbInfo = computed(() => {
|
|
||||||
if (downloadConfig.qbAddress) {
|
|
||||||
return downloadConfig.qbAddress + " 用户名:" + downloadConfig.qbUsername;
|
|
||||||
} else {
|
|
||||||
return "尚未配置";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
downloadConfig = reactive(await http.post("/config/multCode", null, ["qbAddress", "qbUsername", "qbPassword"]));
|
data.qbConfig = await http.get("/qb/config");
|
||||||
});
|
});
|
||||||
|
|
||||||
async function submitQb() {
|
async function submitQb() {
|
||||||
let res = await http.post("");
|
data.qbConfig = await http.post("/qb/saveQbInfo", null, data.qbConfig);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -52,10 +50,12 @@ async function submitQb() {
|
|||||||
display: flex;
|
display: flex;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
padding-bottom: 0.5em;
|
padding-bottom: 0.5em;
|
||||||
|
|
||||||
.left {
|
.left {
|
||||||
width: 6em;
|
width: 6em;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
|
|
||||||
.right {
|
.right {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user