diff --git a/README.md b/README.md
index 3734e3d2..92b95904 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,5 @@
# any-reader
-[![vsc version][vsc-src]][vsc-href]
[![npm version][npm-version-src]][npm-version-href]
[![JSDocs][jsdocs-src]][jsdocs-href]
[![satr][satr-src]][satr-href]
@@ -12,13 +11,64 @@
## VSCode 插件
+
+
+
+
+
+
+
+
+
+
+
+
[文档](https://aooiuu.github.io/any-reader/vsc/)
+### 功能
+
+- [x] 本地小说阅读
+ - [x] txt格式
+ - [x] epub格式
+ - [x] 小说章节识别
+- [x] 在线小说阅读
+- [x] 自定义书源规则
+- [x] 自定义热键
+- [x] 漫画
+- [x] 聚合搜索
+- [x] 发现页分类排行榜
+- [x] 侧边栏阅读(可拖动到底部栏)
+- [x] 收藏
+- [x] 历史记录
+
## 桌面端
[文档](https://aooiuu.github.io/any-reader/desktop/)
-🚧 开发中
+### 功能
+
+- [x] 本地小说阅读
+ - [x] txt格式
+ - [x] epub格式
+ - [x] 小说章节识别
+- [x] 在线小说阅读
+- [x] 自定义书源规则
+- [x] 自定义热键
+- [x] 漫画
+- [x] 视频
+- [x] 聚合搜索
+- [x] 发现页分类排行榜
+- [x] 收藏
+- [x] 历史记录
diff --git a/packages/server/src/index.ts b/packages/server/src/index.ts
index c493b4f8..95c9cea2 100644
--- a/packages/server/src/index.ts
+++ b/packages/server/src/index.ts
@@ -4,8 +4,8 @@ import Koa from 'koa'
import { bodyParser } from '@koa/bodyparser'
import cors from '@koa/cors'
import serve from 'koa-static'
-import { favoritesManager, historyManager, ruleFileManager } from '@any-reader/shared'
-import { router } from './router'
+import { api } from '@any-reader/shared'
+import { router } from './routes'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.resolve(path.dirname(__filename), '..')
@@ -13,11 +13,7 @@ const __dirname = path.resolve(path.dirname(__filename), '..')
const app = new Koa()
async function start() {
- await Promise.all([
- ruleFileManager.init(),
- favoritesManager.init(),
- historyManager.init(),
- ])
+ await api.init()
app
.use(bodyParser())
.use(cors())
diff --git a/packages/server/src/router/index.ts b/packages/server/src/router/index.ts
deleted file mode 100644
index b808206d..00000000
--- a/packages/server/src/router/index.ts
+++ /dev/null
@@ -1,76 +0,0 @@
-import Router from 'koa-router'
-import { api } from '@any-reader/shared'
-import type { Rule } from '@any-reader/core'
-
-export const router = new Router()
-
-function success(data: any, msg = '') {
- return {
- code: 0,
- data,
- msg,
- }
-}
-
-// 获取全部规则
-router.get('/rules', async (ctx) => {
- ctx.body = success(api.rules())
-})
-
-// 获取单个规则
-router.get('/getRuleById', async (ctx) => {
- ctx.body = success(api.getRuleById(ctx.query.id as string))
-})
-
-// 添加单个规则
-router.post('/createRule', async (ctx) => {
- const rule: Rule = ctx.request.body
- await api.createRule(rule)
- ctx.body = success(rule)
-})
-
-// 更新规则
-router.post('/updateRule', async (ctx) => {
- const rule: Rule = ctx.request.body
- await api.updateRule(rule)
- ctx.body = success(rule)
-})
-
-// 根据规则搜索
-router.post('/searchByRuleId', async (ctx) => {
- const { ruleId, keyword } = ctx.request.body
- ctx.body = success(await api.searchByRuleId({ ruleId, keyword }).catch(() => []))
-})
-
-// 获取收藏列表
-router.get('/getFavorites', async (ctx) => {
- ctx.body = success(await api.getFavorites())
-})
-
-router.get('/getLocalBooks', async (ctx) => {
- ctx.body = success(await api.getLocalBooks())
-})
-
-router.get('/getHistory', async (ctx) => {
- ctx.body = success(await api.getHistory())
-})
-
-router.post('/getChapter', async (ctx) => {
- const { filePath = '', ruleId = undefined } = ctx.request.body
- ctx.body = success(await api.getChapter({ filePath, ruleId }).catch(() => []))
-})
-
-router.post('/content', async (ctx) => {
- const { filePath, chapterPath, ruleId } = ctx.request.body
- ctx.body = success(await api.content({ filePath, chapterPath, ruleId }))
-})
-
-router.get('/discoverMap', async (ctx) => {
- const { ruleId } = ctx.query
- ctx.body = success(await api.discoverMap(ruleId as string))
-})
-
-router.post('/discover', async (ctx) => {
- const { ruleId, data } = ctx.request.body
- ctx.body = success(await api.discover({ ruleId, data }))
-})
diff --git a/packages/server/src/routes.ts b/packages/server/src/routes.ts
new file mode 100644
index 00000000..83d3773b
--- /dev/null
+++ b/packages/server/src/routes.ts
@@ -0,0 +1,22 @@
+import Router from 'koa-router'
+import { CONSTANTS, api } from '@any-reader/shared'
+
+export const router = new Router()
+
+api.useApi(
+ async (path: string, cb: any) => {
+ if (path.startsWith('get')) {
+ router.get(path.replace(/get@/, '/'), async (ctx) => {
+ ctx.body = await cb(ctx.query)
+ })
+ }
+ else if (path.startsWith('post')) {
+ router.get(path.replace(/post@/, '/'), async (ctx) => {
+ ctx.body = await cb(ctx.request.body)
+ })
+ }
+ },
+ {
+ CONFIG_PATH: '',
+ bookDir: CONSTANTS.LOCAL_BOOK_DIR,
+ })
diff --git a/packages/shared/src/api.ts b/packages/shared/src/api.ts
index 0ee7dee9..88500046 100644
--- a/packages/shared/src/api.ts
+++ b/packages/shared/src/api.ts
@@ -1,4 +1,5 @@
-import { ensureFile, readJson, writeJson } from 'fs-extra'
+// @ts-expect-error
+import { ensureFile, readJson, writeJson } from 'fs-extra/esm'
import type { Rule } from '@any-reader/core'
import { ContentType, RuleManager } from '@any-reader/core'
import * as ruleFileManager from './ruleFileManager'
@@ -85,13 +86,17 @@ export function rules() {
return ruleFileManager.list()
}
+export function batchUpdateRules(data: { ids: string[]; rule: Rule }) {
+ return ruleFileManager.batchUpdate(data)
+}
+
/**
* 根据规则ID获取规则
* @param ruleId
* @returns
*/
-export function getRuleById(ruleId: string) {
- const rules = ruleFileManager.list()
+export async function getRuleById(ruleId: string) {
+ const rules = await ruleFileManager.list()
return rules.find(e => e.id === ruleId)
}
@@ -134,7 +139,7 @@ export async function content({ filePath, chapterPath, ruleId }: any) {
if (ruleId) {
const rule = await ruleFileManager.findById(ruleId)
const rm = new RuleManager(rule)
- const content = await rm.getContent(chapterPath).catch(() => [])
+ const content: string[] = await rm.getContent(chapterPath).catch(() => [])
let text = ''
if (rule.contentType === ContentType.MANGA)
text = content.map(src => ``).join('')
@@ -205,3 +210,34 @@ export function getRuleExtras() {
export function ping(data: { id: string; host: string }) {
return ruleExtraManager.ping(data.id, data.host)
}
+
+function success(data: any, msg = '') {
+ return {
+ code: 0,
+ data,
+ msg,
+ }
+}
+
+// vscode 、electron、服务端通用注册接口
+export function useApi(register: any, { CONFIG_PATH, bookDir }: any) {
+ register('get@discoverMap', async ({ ruleId = '' } = {}) => success(await discoverMap(ruleId)))
+ register('get@getFavorites', async () => success(await getFavorites()))
+ register('get@getHistory', async () => success(await getHistory()))
+ register('get@getLocalBooks', async () => success(await getLocalBooks(bookDir)))
+ register('post@discover', async (data: any) => success(await discover(data)))
+ register('post@star', async (data: any) => success(await star(data)))
+ register('post@unstar', async (data: any) => success(await unstar(data)))
+ register('get@rules', async () => success(await rules()))
+ register('get@getRuleById', async ({ id = '' } = {}) => success(await getRuleById(id)))
+ register('post@createRule', async (data: any) => success(await createRule(data)))
+ register('post@updateRule', async (data: any) => success(await updateRule(data)))
+ register('post@searchByRuleId', async (data: any) => success(await searchByRuleId(data)))
+ register('post@content', async (data: any) => success(await content(data)))
+ register('post@getChapter', async (data: any) => success(await getChapter(data)))
+ register('get@readConfig', async () => success(await readConfig(CONFIG_PATH)))
+ register('post@updateConfig', async (data: any) => success(await updateConfig(CONFIG_PATH, data)))
+ register('get@getRuleExtras', async () => success(await getRuleExtras()))
+ register('post@ping', async (data: any) => success(await ping(data)))
+ register('post@batchUpdateRules', async (data: any) => success(await batchUpdateRules(data)))
+}
diff --git a/packages/shared/src/ruleExtraManager.ts b/packages/shared/src/ruleExtraManager.ts
index 3a840e0d..760a0299 100644
--- a/packages/shared/src/ruleExtraManager.ts
+++ b/packages/shared/src/ruleExtraManager.ts
@@ -1,6 +1,6 @@
// @ts-expect-error
import { readJson } from 'fs-extra/esm'
-import debounce from 'lodash-es/debounce'
+import _ from 'lodash-es'
import { JSONFilePreset } from 'lowdb/node'
import type { Low } from 'lowdb/lib'
import { RULE_EXTRA_PATH } from './constants'
@@ -24,10 +24,10 @@ async function getDb() {
return mDb
}
-const writeDB = debounce(async () => {
+const writeDB = _.throttle(async () => {
const db = await getDb()
db.write()
-}, 500)
+}, 1000)
export async function ping(id: string, host: string) {
const db = await getDb()
diff --git a/packages/shared/src/ruleFileManager.ts b/packages/shared/src/ruleFileManager.ts
index cfe463d4..9b440105 100644
--- a/packages/shared/src/ruleFileManager.ts
+++ b/packages/shared/src/ruleFileManager.ts
@@ -1,65 +1,68 @@
// @ts-expect-error
-import { ensureFile, readJson, writeJson } from 'fs-extra/esm'
+import { readJson } from 'fs-extra/esm'
import { v4 as uuidV4 } from 'uuid'
+import _ from 'lodash-es'
+import type { Low } from 'lowdb/lib'
+import { JSONFilePreset } from 'lowdb/node'
import type { Rule } from '@any-reader/core'
-import { decodeRule } from '@any-reader/core'
import { BOOK_SOURCE_PATH } from './constants'
-let ruleList: Rule[] = []
+let mDb: Low
-async function readRuleList(): Promise {
- try {
- const list = await readJson(BOOK_SOURCE_PATH)
- for (let i = 0; i < list.length; i++) {
- const rule = list[i]
- if (typeof rule === 'string' && rule.includes('eso://'))
- list[i] = decodeRule(rule)
- }
- return list
- }
- catch (e) {
- return []
- }
+async function getDb() {
+ if (mDb)
+ return mDb
+ const data = await readJson(BOOK_SOURCE_PATH).catch(() => ([]))
+ mDb = await JSONFilePreset(BOOK_SOURCE_PATH, data)
+ return mDb
}
-// 初始化
-export async function init() {
- await ensureFile(BOOK_SOURCE_PATH)
- ruleList = await readRuleList()
-}
+const writeDB = _.throttle(async () => {
+ const db = await getDb()
+ db.write()
+}, 1000)
-// 保存配置文件
-async function writeFile() {
- await ensureFile(BOOK_SOURCE_PATH)
- return writeJson(BOOK_SOURCE_PATH, ruleList, { spaces: 2 })
-}
+// 初始化
+export async function init() {}
-export function list(): Rule[] {
- return ruleList
+export async function list(): Promise {
+ const db = await getDb()
+ return db.data
}
// 删除记录
export async function del(id: string, saveFile = true) {
- ruleList = ruleList.filter(e => e.id !== id)
+ const db = await getDb()
+ db.data = db.data.filter(e => e.id !== id)
if (saveFile)
- await writeFile()
+ await writeDB()
}
// 更新记录
export async function update(rule: Rule) {
if (!rule.id)
rule.id = uuidV4()
-
- const findIdx = ruleList.findIndex(e => e.id === rule.id)
- if (findIdx === -1)
- ruleList.push(rule)
+ const db = await getDb()
+ const row = db.data.find(e => e.id === rule.id)
+ if (!row)
+ db.data.push(rule)
else
- ruleList[findIdx] = rule
+ Object.assign(row, rule)
- await writeFile()
+ writeDB()
+}
+
+export async function batchUpdate({ ids, rule }: { ids: string[];rule: Rule }) {
+ const db = await getDb()
+ for (let i = 0; i < db.data.length; i++) {
+ const row = db.data[i]
+ if (ids.includes(row.id))
+ Object.assign(row, rule)
+ }
+ writeDB()
}
export async function findById(id: string): Promise {
- const list: Rule[] = await readRuleList()
- return list.find(e => e.id === id) as Rule
+ const db = await getDb()
+ return db.data.find(e => e.id === id) as Rule
}
diff --git a/packages/vscode/README.md b/packages/vscode/README.md
index e70a646b..f7f4c71c 100644
--- a/packages/vscode/README.md
+++ b/packages/vscode/README.md
@@ -34,6 +34,22 @@
+## 功能
+
+- [x] 本地小说阅读
+ - [x] txt格式
+ - [x] epub格式
+ - [x] 小说章节识别
+- [x] 在线小说阅读
+- [x] 自定义书源规则
+- [x] 自定义热键
+- [x] 漫画
+- [x] 聚合搜索
+- [x] 发现页分类排行榜
+- [x] 侧边栏阅读(可拖动到底部栏)
+- [x] 收藏
+- [x] 历史记录
+
## 预览
### 操作界面
diff --git a/packages/vscode/package.json b/packages/vscode/package.json
index 0bb02d9b..84a289af 100644
--- a/packages/vscode/package.json
+++ b/packages/vscode/package.json
@@ -3,7 +3,7 @@
"displayName": "any-reader",
"description": "自定义规则多站点聚合搜索阅读小说、漫画。包含JS规则解析库和VSCode插件。支持本地小说 TXT、EPUB",
"icon": "resources/icon.png",
- "version": "1.2.0",
+ "version": "1.3.0",
"publisher": "aooiu",
"qna": "https://github.com/aooiuu/any-reader/issues",
"bugs": {
diff --git a/packages/vscode/src/App.ts b/packages/vscode/src/App.ts
index 05c3b2b2..dc0ad1a7 100644
--- a/packages/vscode/src/App.ts
+++ b/packages/vscode/src/App.ts
@@ -2,7 +2,7 @@ import * as vscode from 'vscode';
import { stringify } from 'qs';
import { openExplorer } from 'explorer-opener';
import { Rule, RuleManager, SearchItem } from '@any-reader/core';
-import { CONSTANTS, api } from '@any-reader/shared';
+import { CONSTANTS, api, ruleFileManager } from '@any-reader/shared';
import { BookChapter, BOOK_TYPE, getBookType } from '@any-reader/shared/localBookManager';
import localBookManager from '@any-reader/shared/localBookManager';
import { COMMANDS, BOOK_SOURCE_PATH } from './constants';
@@ -14,7 +14,6 @@ import localProvider from './sidebar/localBook';
import bookManager from './sidebar/bookManager';
import { treeItemDecorationProvider } from './sidebar/TreeItemDecorationProvider';
import { webviewProvider } from './sidebar/webviewProvider';
-import * as ruleFileManager from './utils/ruleFileManager';
import historyManager from './utils/historyManager';
import favoritesManager from './utils/favoritesManager';
import { RecordFileRow } from './utils/RecordFile';
diff --git a/packages/vscode/src/sidebar/bookManager.ts b/packages/vscode/src/sidebar/bookManager.ts
index 56b4c895..9c1d25bc 100644
--- a/packages/vscode/src/sidebar/bookManager.ts
+++ b/packages/vscode/src/sidebar/bookManager.ts
@@ -1,5 +1,5 @@
import * as vscode from 'vscode';
-import * as ruleFileManager from '../utils/ruleFileManager';
+import { ruleFileManager } from '@any-reader/shared';
import { RuleManager, Rule, SearchItem, ChapterItem } from '@any-reader/core';
export interface TreeNode {
@@ -26,7 +26,7 @@ class BookManager implements vscode.Disposable {
}
if (!rule) {
- const bs = ruleFileManager.list();
+ const bs = await ruleFileManager.list();
if (bs.length === 0) {
return;
}
diff --git a/packages/vscode/src/sidebar/source.ts b/packages/vscode/src/sidebar/source.ts
index 9a05d5c6..b581b06f 100644
--- a/packages/vscode/src/sidebar/source.ts
+++ b/packages/vscode/src/sidebar/source.ts
@@ -4,7 +4,7 @@
import * as vscode from 'vscode';
import { Rule, ContentType } from '@any-reader/core';
-import * as ruleFileManager from '../utils/ruleFileManager';
+import { ruleFileManager } from '@any-reader/shared';
export class SourceProvider implements vscode.TreeDataProvider {
readonly _onDidChangeTreeData = new vscode.EventEmitter();
@@ -31,7 +31,7 @@ export class SourceProvider implements vscode.TreeDataProvider {
async getChildren(element?: Rule): Promise {
if (!element) {
- const rules = ruleFileManager.list();
+ const rules = await ruleFileManager.list();
return rules.filter(
(e: Rule) =>
(e.enableSearch || e.contentType === ContentType.GAME) &&
diff --git a/packages/vscode/src/utils/ruleFileManager.ts b/packages/vscode/src/utils/ruleFileManager.ts
deleted file mode 100644
index adc19c76..00000000
--- a/packages/vscode/src/utils/ruleFileManager.ts
+++ /dev/null
@@ -1,66 +0,0 @@
-import * as fs from 'fs-extra';
-import { v4 as uuidV4 } from 'uuid';
-import { BOOK_SOURCE_PATH } from '../constants';
-import { Rule, decodeRule } from '@any-reader/core';
-
-let ruleList: Rule[] = [];
-
-async function readRuleList(): Promise {
- try {
- const list = await fs.readJson(BOOK_SOURCE_PATH);
- for (let i = 0; i < list.length; i++) {
- const rule = list[i];
- if (typeof rule === 'string' && rule.includes('eso://')) {
- list[i] = decodeRule(rule);
- }
- }
- return list;
- } catch (e) {
- console.log(e);
-
- return [];
- }
-}
-
-// 初始化
-export async function init() {
- await fs.ensureFile(BOOK_SOURCE_PATH);
- ruleList = await readRuleList();
-}
-
-// 保存配置文件
-async function writeFile() {
- await fs.ensureFile(BOOK_SOURCE_PATH);
- return fs.writeJson(BOOK_SOURCE_PATH, ruleList, { spaces: 2 });
-}
-
-export function list(): Rule[] {
- return ruleList;
-}
-
-// 删除记录
-export async function del(id: string, saveFile = true) {
- ruleList = ruleList.filter((e) => e.id !== id);
- if (saveFile) {
- await writeFile();
- }
-}
-
-// 更新记录
-export async function update(rule: Rule) {
- if (!rule.id) {
- rule.id = uuidV4();
- }
- const findIdx = ruleList.findIndex((e) => e.id === rule.id);
- if (findIdx === -1) {
- ruleList.push(rule);
- } else {
- ruleList[findIdx] = rule;
- }
- await writeFile();
-}
-
-export async function findById(id: string): Promise {
- const list: Rule[] = await readRuleList();
- return list.find((e) => e.id === id) as Rule;
-}
diff --git a/packages/vscode/src/webview/WebviewEvent.ts b/packages/vscode/src/webview/WebviewEvent.ts
index a728dcf1..be462594 100644
--- a/packages/vscode/src/webview/WebviewEvent.ts
+++ b/packages/vscode/src/webview/WebviewEvent.ts
@@ -7,24 +7,15 @@ import * as path from 'node:path';
import * as vscode from 'vscode';
import openExplorer from 'explorer-opener';
import * as EasyPostMessage from 'easy-post-message';
-import { CONSTANTS, api } from '@any-reader/shared';
+import { CONSTANTS, api, ruleFileManager } from '@any-reader/shared';
import localBookManager from '@any-reader/shared/localBookManager';
import { COMMANDS } from '../constants';
-import * as ruleFileManager from '../utils/ruleFileManager';
import { createAdapter } from '../utils/easyPostMessage';
import { getConfig } from '../utils/config';
export const ROOT_PATH = path.join(os.homedir(), '.any-reader');
export const CONFIG_PATH = path.join(ROOT_PATH, 'config.vscode.json');
-function success(data: any, msg = '') {
- return {
- code: 0,
- data,
- msg
- };
-}
-
export class WebviewEvent {
private _pm: any;
@@ -44,22 +35,11 @@ export class WebviewEvent {
this._pm.answer('get@vscode/github', this._vscGithub.bind(this));
this._pm.answer('get@vscode/openLocalBookDir', this._vscOpenLocalBookDir.bind(this));
- this._pm.answer('get@discoverMap', async ({ ruleId = '' } = {}) => success(await api.discoverMap(ruleId)));
- this._pm.answer('get@getFavorites', async () => success(await api.getFavorites()));
- this._pm.answer('get@getHistory', async () => success(await api.getHistory()));
- this._pm.answer('get@getLocalBooks', async () => success(await api.getLocalBooks(getConfig().bookDir)));
- this._pm.answer('post@discover', async (data: any) => success(await api.discover(data)));
- this._pm.answer('post@star', async (data: any) => success(await api.star(data)));
- this._pm.answer('post@unstar', async (data: any) => success(await api.unstar(data)));
- this._pm.answer('get@rules', () => success(api.rules()));
- this._pm.answer('get@getRuleById', ({ id = '' } = {}) => success(api.getRuleById(id)));
- this._pm.answer('post@createRule', async (data: any) => success(await api.createRule(data)));
- this._pm.answer('post@updateRule', async (data: any) => success(await api.updateRule(data)));
- this._pm.answer('post@searchByRuleId', async (data: any) => success(await api.searchByRuleId(data)));
- this._pm.answer('post@content', async (data: any) => success(await api.content(data)));
- this._pm.answer('post@getChapter', async (data: any) => success(await api.getChapter(data)));
- this._pm.answer('get@readConfig', async () => success(await api.readConfig(CONFIG_PATH)));
- this._pm.answer('post@updateConfig', async (data: any) => success(await api.updateConfig(CONFIG_PATH, data)));
+ // 初始化通用接口
+ api.useApi(this._pm.answer.bind(this._pm), {
+ CONFIG_PATH,
+ bookDir: getConfig().bookDir
+ });
}
// 打开本地书籍目录
diff --git a/packages/web/electron/api.ts b/packages/web/electron/api.ts
index 34512e48..c218f446 100644
--- a/packages/web/electron/api.ts
+++ b/packages/web/electron/api.ts
@@ -20,25 +20,10 @@ export function createAPI(win: BrowserWindow) {
const pm = new EasyPostMessage(Adapter);
const { api } = require('@any-reader/shared');
- pm.answer('get@discoverMap', async ({ ruleId = '' } = {}) => success(await api.discoverMap(ruleId)));
- pm.answer('get@getFavorites', async () => success(await api.getFavorites()));
- pm.answer('get@getHistory', async () => success(await api.getHistory()));
-
- pm.answer('get@getLocalBooks', async () => success(await api.getLocalBooks(getConfig().bookDir)));
- pm.answer('post@discover', async (data: any) => success(await api.discover(data)));
- pm.answer('post@star', async (data: any) => success(await api.star(data)));
- pm.answer('post@unstar', async (data: any) => success(await api.unstar(data)));
- pm.answer('get@rules', () => success(api.rules()));
- pm.answer('get@getRuleById', ({ id = '' } = {}) => success(api.getRuleById(id)));
- pm.answer('post@createRule', async (data: any) => success(await api.createRule(data)));
- pm.answer('post@updateRule', async (data: any) => success(await api.updateRule(data)));
- pm.answer('post@searchByRuleId', async (data: any) => success(await api.searchByRuleId(data).catch(() => [])));
- pm.answer('post@content', async (data: any) => success(await api.content(data)));
- pm.answer('post@getChapter', async (data: any) => success(await api.getChapter(data)));
- pm.answer('get@readConfig', async () => success(getConfig()));
- pm.answer('post@updateConfig', async (data: any) => success(await api.updateConfig(CONFIG_PATH, data)));
- pm.answer('get@getRuleExtras', async () => success(await api.getRuleExtras()));
- pm.answer('post@ping', async (data: any) => success(await api.ping(data)));
+ api.useApi(pm.answer.bind(pm), {
+ CONFIG_PATH,
+ bookDir: getConfig().bookDir
+ });
pm.answer('get@minimize', () => {
win.minimize();
diff --git a/packages/web/package.json b/packages/web/package.json
index 082c0f38..46eef74b 100644
--- a/packages/web/package.json
+++ b/packages/web/package.json
@@ -1,6 +1,6 @@
{
"name": "any-reader-web",
- "version": "1.0.0-dev.4",
+ "version": "1.0.0-dev.5",
"private": true,
"scripts": {
"dev": "cross-env VITE_APP_PLATFORM=browser vite",
diff --git a/packages/web/src/api/index.ts b/packages/web/src/api/index.ts
index f5daf4eb..7dfa1a77 100644
--- a/packages/web/src/api/index.ts
+++ b/packages/web/src/api/index.ts
@@ -159,3 +159,11 @@ export function ping(data: any) {
data
});
}
+
+export function batchUpdateRules(data: any) {
+ return request({
+ method: 'post',
+ url: 'batchUpdateRules',
+ data
+ });
+}
diff --git a/packages/web/src/pages/pc/rules/index.vue b/packages/web/src/pages/pc/rules/index.vue
index 956e43d5..4434b222 100644
--- a/packages/web/src/pages/pc/rules/index.vue
+++ b/packages/web/src/pages/pc/rules/index.vue
@@ -9,16 +9,36 @@
- 测速
+
+
+ 添加规则
+
+
测速
+
+ 批量操作
+
+ 批量启用搜索
+ 批量禁用搜索
+ 批量启用发现
+ 批量禁用发现
+
+
e.value).flat());
function editRule(row) {
router.push({
- path: '/pc/rule-info',
+ name: 'ruleInfo',
query: {
id: row.id
}
@@ -129,11 +150,8 @@ const tableColumns = ref([
- updateRule({
- ...record,
+ rulesStore.updateRuleById(record.id, {
enableSearch: v
- }).then(() => {
- record.enableSearch = v;
})
}
/>
@@ -150,11 +168,8 @@ const tableColumns = ref([
- updateRule({
- ...record,
+ rulesStore.updateRuleById(record.id, {
enableDiscover: v
- }).then(() => {
- record.enableDiscover = v;
})
}
/>
@@ -190,7 +205,9 @@ const tableData = computed(() => {
// 添加规则
function addRule() {
- router.push('/pc/rule-info');
+ router.push({
+ name: 'ruleInfo'
+ });
}
async function pingAll() {
@@ -202,4 +219,12 @@ async function pingAll() {
await ruleExtra.sync();
}
}
+
+async function batchUpdate(rule) {
+ await batchUpdateRules({
+ ids: [...selectedKeys.value],
+ rule
+ });
+ rulesStore.sync();
+}
diff --git a/packages/web/src/pages/vscode/rules/index.vue b/packages/web/src/pages/vscode/rules/index.vue
deleted file mode 100644
index c4eb6970..00000000
--- a/packages/web/src/pages/vscode/rules/index.vue
+++ /dev/null
@@ -1,128 +0,0 @@
-
-
-
-
-
-
-
- {{ item.label }}
-
-
-
-
打开规则文件
-
-
-
-
- 添加规则
-
-
-
-
-
-
-
diff --git a/packages/web/src/router/router.ts b/packages/web/src/router/router.ts
index 8b4d3a42..4373b893 100644
--- a/packages/web/src/router/router.ts
+++ b/packages/web/src/router/router.ts
@@ -48,6 +48,7 @@ const router = createRouter({
},
{
path: 'rule-info',
+ name: 'ruleInfo',
component: () => import('@/pages/pc/rule-info/index.vue')
}
]
diff --git a/packages/web/src/router/router.vsc.ts b/packages/web/src/router/router.vsc.ts
index 14964b00..19b073de 100644
--- a/packages/web/src/router/router.vsc.ts
+++ b/packages/web/src/router/router.vsc.ts
@@ -14,10 +14,11 @@ const router = createRouter({
},
{
path: '/rules',
- component: () => import('@/pages/vscode/rules/index.vue')
+ component: () => import('@/pages/pc/rules/index.vue')
},
{
path: '/rule-info',
+ name: 'ruleInfo',
component: () => import('@/pages/vscode/rule-info/index.vue')
},
{
diff --git a/packages/web/src/stores/rules.ts b/packages/web/src/stores/rules.ts
index 588c3fd0..10ef98dd 100644
--- a/packages/web/src/stores/rules.ts
+++ b/packages/web/src/stores/rules.ts
@@ -1,4 +1,4 @@
-import { getRules } from '@/api';
+import { getRules, updateRule } from '@/api';
/**
* 收藏数据
@@ -17,8 +17,18 @@ export const useRulesStore = defineStore('rules', () => {
}
}
+ function updateRuleById(id: string, data: any) {
+ updateRule({ id, ...data }).then(() => {
+ const row = list.value.find((e) => e.id === id);
+ if (row) {
+ Object.assign(row, data);
+ }
+ });
+ }
+
return {
list,
- sync
+ sync,
+ updateRuleById
};
});