Compare commits

...

18 Commits

Author SHA1 Message Date
fanxb
4c8c1a355c feat:增加中英文转换util 2024-07-01 21:36:47 +08:00
fanxb
f3bcacfc4a Merge branch 'refs/heads/qb' into electron
# Conflicts:
#	openRenamerBackend/index.ts
#	openRenamerBackend/package.json
#	openRenamerBackend/pnpm-lock.yaml
#	openRenamerFront/pnpm-lock.yaml
#	openRenamerFront/src/App.vue
2024-07-01 21:34:38 +08:00
fanxb
861d5f35bf feat:支持windows桌面应用 2024-01-07 15:34:24 +08:00
fanxb
55af6bd54e temp 2024-01-03 22:26:24 +08:00
fanxb
8c6416ec87 temp 2024-01-03 22:11:08 +08:00
fanxb
f04d3bf636 feat:windows打包 2024-01-03 21:07:29 +08:00
fanxb
0b87ecae94 temp 2023-12-20 22:04:06 +08:00
fleyx
9c001c5403 electron兼容 2023-12-20 17:02:56 +08:00
fanxb
4b8a7829d9 fix:修复bug 2023-12-01 15:30:38 +08:00
fanxb
164553abf0 temp 2023-10-21 11:31:29 +08:00
fleyx
cabe83d07d temp 2023-10-11 17:34:26 +08:00
fanxb
69dcbd22b0 temp 2023-07-28 20:12:34 +08:00
fanxb
4002db4c22 Merge pull request 'feat:优化集数识别' (#47) from dev into main
Reviewed-on: #47
2023-06-25 22:12:22 +08:00
fanxb
1876e98a0e Merge pull request 'fix:修复文件过多报错问题' (#46) from dev into main
Reviewed-on: #46
2023-06-15 20:56:11 +08:00
fanxb
3f8b659462 Merge pull request 'fix:修复文件过多报错问题' (#45) from dev into main
Reviewed-on: #45
2023-06-15 20:17:35 +08:00
fanxb
ea859cc6c3 Merge pull request 'feat:超长文本隐藏显示' (#44) from dev into main
Reviewed-on: #44
2023-05-25 18:33:08 +08:00
fanxb
b0f1901731 Merge pull request 'dev' (#43) from dev into main
Reviewed-on: #43
2023-05-10 20:55:42 +08:00
fanxb
ae9a2d53c5 Merge pull request 'dev' (#42) from dev into main
Reviewed-on: #42
2023-04-13 20:48:22 +08:00
30 changed files with 7241 additions and 2331 deletions

View File

@ -2,7 +2,11 @@
![预览图](https://s3.fleyx.com/picbed/2022/11/18386180128d01eb1a59b8eacf652895.png) ![预览图](https://s3.fleyx.com/picbed/2022/11/18386180128d01eb1a59b8eacf652895.png)
renamer 的开源实现版本BS 应用,支持 arm/x86 部署使用 renamer 的开源实现版本BS 应用,支持 arm/x86 部署使用,两种使用方式:
已打包镜像到 dockerhub 中:[hub.docker.com/r/fleyx/open-renamer](https://hub.docker.com/r/fleyx/open-renamer)
1. 部署容器到 nas
已打包到 dockerhub 中:[hub.docker.com/r/fleyx/open-renamer](https://hub.docker.com/r/fleyx/open-renamer)
2. 下载桌面应用使用,目前仅支持 windows后续计划支持 mac,linux[下载地址](https://github.com/FleyX/open-renamer/releases/latest)
[点击查看参考文档](https://blog.fleyx.com/blog/detail/20221130) [点击查看参考文档](https://blog.fleyx.com/blog/detail/20221130)

6
electron/.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
node_modules
dist
openRenamerBackend
build
.idea
*.exe

1
electron/.npmrc Normal file
View File

@ -0,0 +1 @@
electron_mirror=https://npmmirror.com/mirrors/electron/

11
electron/build.sh Normal file
View File

@ -0,0 +1,11 @@
cd ../openRenamerFront
yarn
npm run build
cd ../openRenamerBackend
yarn
tsc
rm -rf ./static/js
rm -rf ./static/css
cp -r ../openRenamerFront/dist/* ./static
cd ../electron
npm run build

129
electron/main.js Normal file
View File

@ -0,0 +1,129 @@
// main.js
// 控制应用生命周期和创建原生浏览器窗口的模组
const {app, BrowserWindow, Menu} = require('electron')
const path = require('path')
const fs = require('fs');
const {spawn} = require('child_process');
const net = require('net');
const log = require('electron-log');
const userHome = process.env.HOME || process.env.USERPROFILE;
const dataPath = path.join(userHome, "openRenamer");
log.transports.file.resolvePathFn = () => path.join(dataPath, 'logs/main.log');
async function createWindow() {
// 隐藏菜单栏
Menu.setApplicationMenu(null)
// 创建浏览器窗口
const win = new BrowserWindow({
//width: 800, //窗口宽度,单位像素. 默认是 800
//height: 600, //窗口高度,单位像素. 默认是 600
icon: './logo.ico', // 设置窗口左上角的图标
show: false, //窗口创建的时候是否显示. 默认为 true
webPreferences: {
nodeIntegration: true, // 是否完整支持node。默认为 true
preload: path.join(__dirname, 'preload.js') //界面的其它脚本运行之前预先加载一个指定脚本。
}
})
// 下面这两行代码配合上面 new BrowserWindow 里面的 show: false可以实现打开时窗口最大化
win.maximize()
win.show()
log.info(__dirname);
let port = await startBackend()
// 并且为你的应用加载index.html
// win.loadFile('./dist/index.html')
log.info("backend service started")
win.loadURL(`http://localhost:` + port);
// win.webContents.openDevTools()
}
// Electron会在初始化完成并且准备好创建浏览器窗口时调用这个方法
// 部分 API 在 ready 事件触发后才能使用。
app.whenReady().then(createWindow)
// 当所有窗口都被关闭后退出
app.on('windows-all-closed', () => {
// 在 macOS 上,除非用户用 Cmd + Q 确定地退出,
// 否则绝大部分应用及其菜单栏会保持激活。
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
// 在macOS上当单击dock图标并且没有其他窗口打开时
// 通常在应用程序中重新创建一个窗口。
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
/**
* 启动后台服务
* @returns {Promise<number>}
*/
async function startBackend() {
let port = 51000;
while (true) {
let ok = await checkPort(port);
if (ok) {
break;
}
port = port + 1;
}
log.info("start check folder exist", __dirname, __filename)
let exist = fs.existsSync("openRenamerBackend");
const childProcess = spawn('node', [(exist ? '' : '../') + 'openRenamerBackend/dist/index.js'], {
env: {
"PORT": port,
"DATA_PATH": dataPath
}
});
childProcess.stdout.on('data', (data) => {
log.info(`stdout: ${data}`);
});
childProcess.stderr.on('data', (data) => {
log.error(`stderr: ${data}`);
});
childProcess.on('close', (code) => {
log.info(`child process exited with code ${code}`);
});
log.info("check service start");
while (true) {
await sleep(100);
let success = !(await checkPort(port));
if (success) {
log.info("service start");
break;
}
}
return port;
}
/**
* 判断端口是否可用
* @param port
* @returns {Promise<unknown>}
*/
function checkPort(port) {
return new Promise((resolve, reject) => {
let server = net.createServer().listen(port);
server.on("listening", function () {
server.close();
resolve(true);
})
server.on("error", function (err) {
console.error(err);
resolve(false);
})
})
}
function sleep(time) {
return new Promise((resolve, reject) => {
setTimeout(() => resolve(), time);
})
}

71
electron/package.json Normal file
View File

@ -0,0 +1,71 @@
{
"name": "electron",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"start": "electron .",
"test": "echo \"Error: no test specified\" && exit 1",
"build": "electron-builder --win --x64"
},
"author": "",
"license": "ISC",
"devDependencies": {
"electron": "^28.0.0",
"electron-builder": "^24.9.1"
},
"build": {
"productName": "openRenamer",
"appId": "openRenamer.app",
"directories": {
"output": "build"
},
"files": [
"main.js",
"preload.js"
],
"extraFiles": [
{
"from": "../openRenamerBackend",
"to": "openRenamerBackend"
}
],
"copyright": "open-renamer",
"nsis": {
"oneClick": false,
"allowElevation": true,
"allowToChangeInstallationDirectory": true,
"installerIcon": "./renamer.ico",
"uninstallerIcon": "./renamer.ico",
"installerHeaderIcon": "./renamer.ico",
"createDesktopShortcut": true,
"createStartMenuShortcut": true,
"shortcutName": "openRenamer"
},
"win": {
"icon": "./renamer.ico",
"target": [
"nsis",
"zip"
],
"extraFiles": [
{
"from": "windows/node.exe",
"to": "node.exe"
}
]
},
"mac": {
"target": [
"dmg",
"zip"
]
},
"linux": {
"icon": "build/icons"
}
},
"dependencies": {
"electron-log": "^5.0.1"
}
}

12
electron/preload.js Normal file
View File

@ -0,0 +1,12 @@
// preload.js
// 所有Node.js API都可以在预加载过程中使用。
// 它拥有与Chrome扩展一样的沙盒。
window.addEventListener('DOMContentLoaded', () => {
const replaceText = (selector, text) => {
const element = document.getElementById(selector)
if (element) element.innerText = text
}
for (const dependency of ['chrome', 'node', 'electron']) {
replaceText(`${dependency}-version`, process.versions[dependency])
}
})

1
electron/readme.md Normal file
View File

@ -0,0 +1 @@
需要下载windows版的node.js压缩包将其中的node.exe 放到windowes目录下

BIN
electron/renamer.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

1705
electron/yarn.lock Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
import { Context } from "koa"; import {Context} from "koa";
import service from "../service/QbService"; import service from "../service/QbService";
const router = {}; const router = {};
@ -7,7 +7,21 @@ const router = {};
* *
*/ */
router["POST /qb/saveQbInfo"] = async function (ctx: Context) { 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();
}; };

View File

@ -1,10 +1,12 @@
import * as path from 'path'; import * as path from 'path';
import * as process from "process";
//后台所在绝对路径 //后台所在绝对路径
const rootPath = path.resolve(__dirname, '..'); const rootPath = path.resolve(__dirname, '..');
let config = { let config = {
rootPath, rootPath,
dataPath: process.env.DATA_PATH ? process.env.DATA_PATH : path.join(rootPath, 'data'),
port: process.env.PORT ? parseInt(process.env.PORT) : 8089, port: process.env.PORT ? parseInt(process.env.PORT) : 8089,
token: process.env.TOKEN ? process.env.TOKEN : null, token: process.env.TOKEN ? process.env.TOKEN : null,
urlPrefix: '/openRenamer/api', urlPrefix: '/openRenamer/api',

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,5 +0,0 @@
export default interface QbAddressDto {
address: string;
username: string;
password: string;
}

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>;
}

View File

@ -9,8 +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 qbService from "./service/QbService";
console.log(config); console.log(config);
@ -32,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);
})(); })();

View File

@ -9,22 +9,20 @@
"author": "fxb", "author": "fxb",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@types/fs-extra": "^5.0.4", "@types/fs-extra": "5.0.4",
"@types/koa": "^2.0.47", "@types/koa": "2.13.12",
"@types/node": "^11.13.4", "@types/node": "11.13.4",
"axios": "^0.21.4", "axios": "0.21.4",
"fs-extra": "^7.0.0", "fs-extra": "7.0.0",
"koa": "^2.5.3", "koa": "2.5.3",
"koa-body": "^4.0.4", "koa-body": "4.0.4",
"koa-router": "^7.4.0", "koa-router": "7.4.0",
"koa-static": "^5.0.0", "koa-static": "5.0.0",
"koa2-cors": "^2.0.6", "koa2-cors": "2.0.6",
"log4js": "^6.3.0", "log4js": "6.3.0",
"moment": "^2.22.2", "moment": "2.22.2",
"mysql2": "^2.2.5", "sqlite": "4.0.23",
"sqlite": "^4.0.23", "sqlite3": "5.0.2",
"sqlite3": "^5.0.2", "uuid": "3.3.2"
"uuid": "^3.3.2",
"winston": "^3.1.0"
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,17 +1,52 @@
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;
}
} }
export default QbService; export default QbService;

View File

@ -1,108 +0,0 @@
import mysql from "mysql2/promise";
import config from '../config';
import * as fs from "fs-extra";
import * as path from 'path';
import log from '../util/LogUtil';
const HISTORY_NAME = "history.json";
interface Res {
rows: any;
fields: mysql.FieldPacket;
}
class MysqlUtil {
public static pool: mysql.Pool = null;
static async createPool(mysqlConfig: any) {
MysqlUtil.pool = await mysql.createPool(mysqlConfig);
let basePath = path.join(config.rootPath, "sqls");
let hisPath = path.join(basePath, HISTORY_NAME);
let history: Array<string>;
if (fs.existsSync(hisPath)) {
history = JSON.parse(await fs.readFile(hisPath, "utf-8"));
} else {
history = new Array();
}
//执行数据库
let files = (await fs.readdir(basePath)).sort((a, b) => a.localeCompare(b)).filter(item => !(item === HISTORY_NAME));
let error = null;
for (let i = 0; i < files.length; i++) {
if (history.indexOf(files[i]) > -1) {
log.info("sql无需重复执行:", files[i]);
continue;
}
let sqlLines = (await fs.readFile(path.join(basePath, files[i]), 'utf-8')).split(/[\r\n]/g);
try {
let sql = "";
for (let j = 0; j < sqlLines.length; j++) {
sql = sql + sqlLines[j];
if (sqlLines[j].endsWith(";")) {
await MysqlUtil.pool.execute(sql);
sql = "";
}
}
log.info("sql执行成功:", files[i]);
history.push(files[i]);
} catch (err) {
error = err;
break;
}
}
await fs.writeFile(hisPath, JSON.stringify(history));
if (error != null) {
throw error;
}
}
static async getRows(sql: string, params: Array<any>, connection: mysql.PoolConnection = null): Promise<Array<any>> {
return (await MysqlUtil.execute(sql, params, connection)).rows;
}
static async getRow(sql: string, params: Array<any>, connection: mysql.PoolConnection = null): Promise<any> {
let rows = (await MysqlUtil.execute(sql, params, connection)).rows;
return rows.length > 0 ? rows[0] : null;
}
static async getSingle(sql: string, params: Array<any>, connection: mysql.PoolConnection = null): Promise<any> {
let rows = (await MysqlUtil.execute(sql, params, connection)).rows;
if (rows.length == 0) {
return null;
}
let row = rows[0];
return row[Object.keys(row)[0]];
}
static async execute(sql: string, params: Array<any>, connection: mysql.PoolConnection = null): Promise<Res> {
let res: any = {};
if (connection == null) {
let [rows, fields] = await MysqlUtil.pool.query(sql, params);
res['rows'] = fields === undefined ? null : rows;
res['fields'] = fields === undefined ? rows : fields;
} else {
let [rows, fields] = await connection.query(sql, params);
res['rows'] = rows;
res['fields'] = fields;
}
return res;
}
static async test() {
let connection = await MysqlUtil.pool.getConnection();
connection.beginTransaction();
connection.query(`insert into url value(6,"GET","asd","public")`);
connection.query(`insert into url value(7,"GET","asd","public")`);
await connection.commit();
connection.release();
}
}
export {
MysqlUtil,
Res,
mysql
}

View File

@ -1,102 +1,83 @@
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; qbInfo = info;
} }
export async function updateQbInfo(info: QbAddressDto, status: boolean) { export function getQbInfo() {
if (!info) { return qbInfo;
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;
}
if (status) {
qbStatus = status;
}
axios.defaults.baseURL = qbInfo.address;
} }
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) {
if (!qbStatus) { if (!qbInfo.valid) {
throw new Error("qbittorrent无法连接请检查配置"); throw new Error("qbittorrent无法连接请检查配置");
} }
let isTryLogin = false; let isTryLogin = false;
while (true) { while (true) {
let headers = { "Cookie": cookie }; let headers = {"Cookie": cookie};
if (isForm) { if (isForm) {
headers['content-type'] = "multipart/form-data"; headers['content-type'] = "multipart/form-data";
} else if (method == "post") { } else if (method == "post") {
headers['content-type'] = "application/json"; headers['content-type'] = "application/json";
} }
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,
headers, headers,
}); });
if (res.status == 200) { if (res.status == 200) {
return res.data; return res.data;
} if (res.status == 403) { }
if (isTryLogin) { if (res.status == 403) {
throw new Error("qb用户名密码设置有误"); if (isTryLogin) {
} else { throw new Error("qb用户名密码设置有误");
await tryLogin(qbInfo.address, qbInfo.username, qbInfo.password, true); } else {
isTryLogin = true; await tryLogin();
} isTryLogin = true;
} else { }
throw new Error("请求报错:" + res.data); } else {
} throw new Error("请求报错:" + res.data);
} }
}
} }
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 == "") {
try { return false;
let res = await axios.post(address + "/api/v2/auth/login", body, { }
headers: { "Content-Type": "multipart/form-data;boundary=--------------------------125002698093981740970152" } let body = {username: qbInfo.username, password: qbInfo.password};
}); try {
let success = res.data.toLocaleLowerCase().contains('ok'); let res = await axios.post(qbInfo.address + `/api/v2/auth/login`, querystring.stringify(body), {
if (updateStatus) { headers: {"Content-Type": "application/x-www-form-urlencoded"}
qbStatus = success; });
} let success = res.data.toLocaleLowerCase().indexOf('ok') > -1;
if (!success) { if (success) {
throw new Error("登录失败"); cookie = res.headers['set-cookie'];
} 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("登录出错");
}
} }

View File

@ -1,5 +1,5 @@
import sqlite3 from 'sqlite3'; import sqlite3 from 'sqlite3';
import { open, Database } from 'sqlite'; import {open, Database} from 'sqlite';
import config from '../config'; import config from '../config';
import * as fs from "fs-extra"; import * as fs from "fs-extra";
import * as path from 'path'; import * as path from 'path';
@ -12,9 +12,9 @@ class SqliteHelper {
public static pool: Database = null; public static pool: Database = null;
static async createPool() { static async createPool() {
let dataFolder = path.join(config.rootPath, "data"); let dataFolder = config.dataPath;
if (!fs.existsSync(dataFolder)) { if (!fs.existsSync(dataFolder)) {
fs.mkdir(dataFolder); await fs.mkdir(dataFolder);
} }
SqliteHelper.pool = await open({ SqliteHelper.pool = await open({
filename: path.join(dataFolder, "database.db"), filename: path.join(dataFolder, "database.db"),
@ -26,7 +26,7 @@ class SqliteHelper {
if (fs.existsSync(hisPath)) { if (fs.existsSync(hisPath)) {
history = JSON.parse(await fs.readFile(hisPath, "utf-8")); history = JSON.parse(await fs.readFile(hisPath, "utf-8"));
} else { } else {
history = new Array(); history = [];
} }
//执行数据库 //执行数据库
let files = (await fs.readdir(basePath)).sort((a, b) => a.localeCompare(b)).filter(item => !(item === HISTORY_NAME)); let files = (await fs.readdir(basePath)).sort((a, b) => a.localeCompare(b)).filter(item => !(item === HISTORY_NAME));

View 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 012
*/
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 012
*/
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;
}

File diff suppressed because one or more lines are too long

View File

@ -8,21 +8,21 @@
"lint": "vue-cli-service lint" "lint": "vue-cli-service lint"
}, },
"dependencies": { "dependencies": {
"@element-plus/icons-vue": "^2.0.10", "@element-plus/icons-vue": "2.0.10",
"axios": "^0.21.1", "axios": "1.6.0",
"core-js": "^3.6.5", "core-js": "3.35.0",
"dayjs": "^1.10.7", "dayjs": "1.10.7",
"element-plus": "^2.2.25", "element-plus": "2.2.25",
"vue": "^3.2.45", "vue": "3.2.45",
"vue-router": "^4.0.0-0" "vue-router": "4.2.5"
}, },
"devDependencies": { "devDependencies": {
"@vue/cli-plugin-babel": "~5.0.8", "@vue/cli-plugin-babel": "5.0.8",
"@vue/cli-plugin-router": "~5.0.8", "@vue/cli-plugin-router": "5.0.8",
"@vue/cli-service": "~5.0.8", "@vue/cli-service": "5.0.8",
"@vue/compiler-sfc": "^3.0.0", "@vue/compiler-sfc": "3.0.0",
"less": "^3.0.4", "less": "3.0.4",
"less-loader": "^5.0.0", "less-loader": "5.0.0",
"prettier": "^2.2.1" "prettier": "2.2.1"
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -29,8 +29,8 @@
</el-tooltip> </el-tooltip>
&nbsp;&nbsp; &nbsp;&nbsp;
</template> </template>
开源地址:<a href="https://github.com/FleyX/open-renamer">open-renamer</a> 开源地址:<a href="https://github.com/FleyX/open-renamer" target="_blank">open-renamer</a>
&nbsp;&nbsp;<a href="https://github.com/FleyX/open-renamer/issues">反馈</a> &nbsp;&nbsp;<a href="https://github.com/FleyX/open-renamer/issues" target="_blank">反馈</a>
</div> </div>
</div> </div>
</template> </template>

View File

@ -14,7 +14,7 @@ import router from '../router/index';
async function request(url, method, params, body, isForm) { async function request(url, method, params, body, isForm) {
let options = { let options = {
url, url,
baseURL: '/openRenamer/api', baseURL: window.baseUrl + '/openRenamer/api',
method, method,
params, params,
headers: {token: window.token} headers: {token: window.token}

View File

@ -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>
@ -16,34 +27,21 @@
</template> </template>
<script setup> <script setup>
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;
} }

View File

@ -1,5 +1,6 @@
module.exports = { module.exports = {
devServer: { devServer: {
proxy: "http://localhost:8089", proxy: "http://localhost:8089",
}, },
publicPath: "./"
}; };