From 5fc06d7de33cc2e10e103ecf5943cc0b224121a0 Mon Sep 17 00:00:00 2001 From: aooiuu Date: Fri, 31 May 2024 20:24:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=AE=B0=E5=BD=95=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 -- package.json | 1 + packages/cli/package.json | 8 +- packages/shared/src/api.ts | 89 ++++++++++++-------- packages/shared/src/ruleExtraManager.ts | 10 ++- packages/shared/src/ruleFileManager.ts | 2 +- packages/vscode/package.json | 13 ++- packages/web/package.json | 2 +- packages/web/src/pages/pc/rules/index.vue | 62 +++++++++++++- packages/web/src/utils/rule.ts | 2 +- pnpm-lock.yaml | 99 +++++------------------ 11 files changed, 165 insertions(+), 129 deletions(-) diff --git a/README.md b/README.md index 2107e15d..6bf18e6f 100644 --- a/README.md +++ b/README.md @@ -11,12 +11,6 @@ QQ群: 50057637 -## 快速体验 - -```sh -npx any-reader -``` - ## 多端支持 ### VSCode 插件 diff --git a/package.json b/package.json index ccb68952..daa540b7 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "electron:build": "npm -C packages/web run electron:build", "vscode:server": "npm -C packages/web run vscode:dev", "vscode:dev": "npm-run-all build:core build:shared --parallel vscode:server server", + "vscode:build": "npm -C packages/vscode run build", "server:build": "npm -C packages/server run build", "cli:build-tpl": "npm -C packages/web run cli:build", "cli:build-js": "npm -C packages/cli run build", diff --git a/packages/cli/package.json b/packages/cli/package.json index 55badda3..465f4af1 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@any-reader/cli", - "version": "1.0.0", + "version": "1.0.1", "description": "", "type": "commonjs", "files": [ @@ -18,11 +18,9 @@ "keywords": [], "author": "", "license": "GPL3", - "dependencies": { - "@any-reader/server": "workspace:^", - "open": "^10.1.0" - }, "devDependencies": { + "@any-reader/server": "workspace:^", + "open": "^10.1.0", "@rollup/plugin-alias": "^5.0.0", "@rollup/plugin-commonjs": "^25.0.2", "@rollup/plugin-json": "^6.0.0", diff --git a/packages/shared/src/api.ts b/packages/shared/src/api.ts index ef704bd6..5856992f 100644 --- a/packages/shared/src/api.ts +++ b/packages/shared/src/api.ts @@ -25,6 +25,16 @@ export async function discoverMap(ruleId: string) { return ruleManager.discoverMap() } +/** + * 发现页列表 + * @returns + */ +export async function discover({ ruleId, data }: any) { + const rule = await ruleFileManager.findById(ruleId) + const ruleManager = new RuleManager(rule) + return ruleManager.discover(data.value) +} + /** * 收藏列表 * @returns @@ -49,16 +59,6 @@ export function getLocalBooks(dir: string) { return localBookManager.getBookList(dir) } -/** - * 发现页列表 - * @returns - */ -export async function discover({ ruleId, data }: any) { - const rule = await ruleFileManager.findById(ruleId) - const ruleManager = new RuleManager(rule) - return ruleManager.discover(data.value) -} - /** * 收藏 * @param param0 @@ -231,26 +231,51 @@ function success(data: any, 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))) - register('post@delRules', async (data: any) => success(await delRules(data))) - register('post@updateRuleSort', async (data: any) => success(await ruleFileManager.updateRuleSort(data && data.id))) - register('post@importRules', async (data: any) => success(await ruleFileManager.importRules(data && data.url))) + const registerApi = async (apiPath: string, handle: Function, log?: { + ruleId: (...arg: any) => string + check: (arg: any) => boolean + }) => { + register(apiPath, async (...arg: any) => { + // 原始返回值 + const result = await handle(...arg).catch(() => {}) + + // 记录接口调用情况 + if (typeof log === 'object' && log.ruleId && log.check) { + const isOk = log.check(result) + ruleExtraManager.updateApiStatus(log.ruleId(...arg), isOk ? `${apiPath}.ok` : `${apiPath}.fail`) + } + + // 返回数据 + return success(result) + }) + } + + const discoverLog = { + ruleId: (data: any) => data.ruleId, + check: (v: any[]) => Array.isArray(v) && v.length > 0, + } + + // 注册接口 + registerApi('get@discoverMap', async ({ ruleId = '' } = {}) => await discoverMap(ruleId), discoverLog) + registerApi('post@discover', async (data: any) => await discover(data), discoverLog) + registerApi('get@getFavorites', async () => await getFavorites()) + registerApi('get@getHistory', async () => await getHistory()) + registerApi('get@getLocalBooks', async () => await getLocalBooks(bookDir)) + registerApi('post@star', async (data: any) => await star(data)) + registerApi('post@unstar', async (data: any) => await unstar(data)) + registerApi('get@rules', async () => await rules()) + registerApi('get@getRuleById', async ({ id = '' } = {}) => await getRuleById(id)) + registerApi('post@createRule', async (data: any) => await createRule(data)) + registerApi('post@updateRule', async (data: any) => await updateRule(data)) + registerApi('post@searchByRuleId', async (data: any) => await searchByRuleId(data), discoverLog) + registerApi('post@content', async (data: any) => await content(data)) + registerApi('post@getChapter', async (data: any) => await getChapter(data)) + registerApi('get@readConfig', async () => await readConfig(CONFIG_PATH)) + registerApi('post@updateConfig', async (data: any) => await updateConfig(CONFIG_PATH, data)) + registerApi('get@getRuleExtras', async () => await getRuleExtras()) + registerApi('post@ping', async (data: any) => await ping(data)) + registerApi('post@batchUpdateRules', async (data: any) => await batchUpdateRules(data)) + registerApi('post@delRules', async (data: any) => await delRules(data)) + registerApi('post@updateRuleSort', async (data: any) => await ruleFileManager.updateRuleSort(data && data.id)) + registerApi('post@importRules', async (data: any) => await ruleFileManager.importRules(data && data.url)) } diff --git a/packages/shared/src/ruleExtraManager.ts b/packages/shared/src/ruleExtraManager.ts index 760a0299..8aa4da37 100644 --- a/packages/shared/src/ruleExtraManager.ts +++ b/packages/shared/src/ruleExtraManager.ts @@ -7,7 +7,7 @@ import { RULE_EXTRA_PATH } from './constants' import _ping from './ping' export interface SourceExtraRow { - ping?: number + [_: string]: number } export interface SourceExtra { @@ -47,3 +47,11 @@ export async function getRuleExtras(): Promise { const db = await getDb() return db.data } + +export async function updateApiStatus(id: string, field: string) { + const db = await getDb() + if (!db.data[id]) + db.data[id] = {} + _.set(db.data[id], field, _.get(db.data[id], field, 0) + 1) + writeDB() +} diff --git a/packages/shared/src/ruleFileManager.ts b/packages/shared/src/ruleFileManager.ts index bfd2eb5d..1b0d75f3 100644 --- a/packages/shared/src/ruleFileManager.ts +++ b/packages/shared/src/ruleFileManager.ts @@ -97,7 +97,7 @@ export function isRule(rule: any): boolean { if (typeof rule !== 'object') return false - return rule.id && rule.host && rule.contentType + return rule.id && rule.host && typeof rule.contentType !== 'undefined' } export async function importRules(url: string) { diff --git a/packages/vscode/package.json b/packages/vscode/package.json index d1efba64..3aa35a37 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.3.2", + "version": "1.3.3", "publisher": "aooiu", "qna": "https://github.com/aooiuu/any-reader/issues", "bugs": { @@ -30,7 +30,16 @@ ], "activationEvents": [ "onView:any-reader", - "onWebviewPanel:any-reader" + "onWebviewPanel:any-reader", + "onCommand:any-reader.getBookSource", + "onCommand:any-reader.searchBook", + "onCommand:any-reader.searchBookByRule", + "onCommand:any-reader.discover", + "onCommand:any-reader.home", + "onCommand:any-reader.gamePlay", + "onCommand:any-reader.star", + "onCommand:any-reader.unstar", + "onCommand:any-reader.openLocalBookDir" ], "main": "./dist/extension.js", "scripts": { diff --git a/packages/web/package.json b/packages/web/package.json index 6c223119..43d56043 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -1,6 +1,6 @@ { "name": "any-reader-web", - "version": "1.0.0-dev.6", + "version": "1.0.0-dev.8", "private": true, "scripts": { "dev": "cross-env VITE_APP_PLATFORM=browser vite", diff --git a/packages/web/src/pages/pc/rules/index.vue b/packages/web/src/pages/pc/rules/index.vue index 87ad1cd5..aacad126 100644 --- a/packages/web/src/pages/pc/rules/index.vue +++ b/packages/web/src/pages/pc/rules/index.vue @@ -236,6 +236,65 @@ const tableColumns = ref([ /> ) }, + { + title: '接口调用', + width: 120, + align: 'center', + filterable: { + filters: [ + { + text: '搜索失败>3且成功=0', + value: 1 + }, + { + text: '发现分类失败>3且成功=0', + value: 2 + }, + { + text: '发现列表失败>3且成功=0', + value: 3 + } + ], + filter: (value, record) => { + if (value.includes(1)) { + const ok = _.get(record, 'extra.post@searchByRuleId.ok', 0); + const fail = _.get(record, 'extra.post@searchByRuleId.fail', 0); + return ok === 0 && fail > 3; + } + if (value.includes(2)) { + const ok = _.get(record, 'extra.get@discoverMap.ok', 0); + const fail = _.get(record, 'extra.get@discoverMap.fail', 0); + return ok === 0 && fail > 3; + } + if (value.includes(2)) { + const ok = _.get(record, 'extra.post@discover.ok', 0); + const fail = _.get(record, 'extra.post@discover.fail', 0); + return ok === 0 && fail > 3; + } + return true; + }, + multiple: false + }, + render: ({ record }) => ( +
+
+ 搜索 + {_.get(record, 'extra.post@searchByRuleId.ok', 0)}/ + {_.get(record, 'extra.post@searchByRuleId.fail', 0)} +
+
+ 发现分类 + {_.get(record, 'extra.get@discoverMap.ok', 0)}/ + {_.get(record, 'extra.get@discoverMap.fail', 0)} +
+
+ 发现列表 + {_.get(record, 'extra.post@discover.ok', 0)}/ + {_.get(record, 'extra.post@discover.fail', 0)} +
+
+ ) + }, { title: '操作', width: 120, @@ -365,7 +424,8 @@ async function handleChange(data, extra, currentData) { } async function drop(event) { - event.preventdefault(); + // vscode + if (typeof event.preventdefault === 'function') event.preventdefault(); const files = event.dataTransfer.files; for (const file of files) { await dropFile(file); diff --git a/packages/web/src/utils/rule.ts b/packages/web/src/utils/rule.ts index 8bcb29bf..7fd39090 100644 --- a/packages/web/src/utils/rule.ts +++ b/packages/web/src/utils/rule.ts @@ -5,5 +5,5 @@ export const isRule = (rule: any) => { if (typeof rule !== 'object') return false; - return rule.id && rule.host && rule.contentType; + return rule.id && rule.host && typeof rule.contentType !== 'undefined'; }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a1973702..656131a7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,9 +1,5 @@ lockfileVersion: '6.0' -settings: - autoInstallPeers: true - excludeLinksFromLockfile: false - importers: .: @@ -28,14 +24,10 @@ importers: version: 1.0.0-rc.45(@algolia/client-search@4.23.3)(search-insights@2.13.0) packages/cli: - dependencies: + devDependencies: '@any-reader/server': specifier: workspace:^ version: link:../server - open: - specifier: ^10.1.0 - version: 10.1.0 - devDependencies: '@rollup/plugin-alias': specifier: ^5.0.0 version: 5.0.0(rollup@3.26.0) @@ -48,6 +40,9 @@ importers: '@rollup/plugin-node-resolve': specifier: ^15.1.0 version: 15.1.0(rollup@3.26.0) + open: + specifier: ^10.1.0 + version: 10.1.0 rollup-plugin-esbuild: specifier: ^5.0.0 version: 5.0.0(esbuild@0.21.3)(rollup@3.26.0) @@ -273,7 +268,7 @@ importers: version: 5.0.0(esbuild@0.21.3)(rollup@3.26.0) ts-jest: specifier: ^29.1.1 - version: 29.1.1(esbuild@0.21.3)(jest@29.7.0)(typescript@5.3.3) + version: 29.1.1(@babel/core@7.24.5)(esbuild@0.21.3)(jest@29.7.0)(typescript@5.1.6) typescript: specifier: ^5.1.6 version: 5.3.3 @@ -6038,7 +6033,7 @@ packages: engines: {node: '>=18'} dependencies: run-applescript: 7.0.0 - dev: false + dev: true /bundle-require@4.0.2(esbuild@0.21.3): resolution: {integrity: sha512-jwzPOChofl67PSTW2SGubV9HBQAhhR2i6nskiOThauo9dzwDUgOWQScFVaJkjEfYX+UXiD+LEx8EblQMc2wIag==} @@ -6774,7 +6769,7 @@ packages: /default-browser-id@5.0.0: resolution: {integrity: sha512-A6p/pu/6fyBcA1TRz/GqWYPViplrftcW2gZC9q79ngNCKAeR/X3gcEdXQHl4KNXV+3wgIJ1CPkJQ3IHM6lcsyA==} engines: {node: '>=18'} - dev: false + dev: true /default-browser@5.2.1: resolution: {integrity: sha512-WY/3TUME0x3KPYdRRxEJJvXRHV4PyPoUsxtZa78lwItwRQRHhd2U9xOscaT/YTf8uCXIAjeJOFBVEh/7FtD8Xg==} @@ -6782,7 +6777,7 @@ packages: dependencies: bundle-name: 4.1.0 default-browser-id: 5.0.0 - dev: false + dev: true /defer-to-connect@2.0.1: resolution: {integrity: sha512-4tvttepXG1VaYGrRibk5EwJd1t4udunSOVMdLSAL6mId1ix438oPwPZMALY41FCijukO1L0twNcGsdzS7dHgDg==} @@ -6800,7 +6795,7 @@ packages: /define-lazy-prop@3.0.0: resolution: {integrity: sha512-N+MeXYoqr3pOgn8xfyRPREN7gHakLYjhsHhWGT3fWAiL4IkAt0iDw14QiiEm2bE30c5XX5q0FtAA3CK5f9/BUg==} engines: {node: '>=12'} - dev: false + dev: true /define-properties@1.2.1: resolution: {integrity: sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg==} @@ -9450,7 +9445,7 @@ packages: resolution: {integrity: sha512-eljcgEDlEns/7AXFosB5K/2nCM4P7FQPkGc/DWLy5rmFEWvZayGrik1d9/QIY5nJ4f9YsVvBkA6kJpHn9rISdQ==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} hasBin: true - dev: false + dev: true /is-extglob@2.1.1: resolution: {integrity: sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==} @@ -9491,7 +9486,7 @@ packages: hasBin: true dependencies: is-docker: 3.0.0 - dev: false + dev: true /is-module@1.0.0: resolution: {integrity: sha512-51ypPSPCoTEIN9dy5Oy+h4pShgJmPCygKfyRCISBI+JoWT/2oJvK8QPxmwv7b/p239jXrm9M1mlQbyKJ5A152g==} @@ -9594,7 +9589,7 @@ packages: engines: {node: '>=16'} dependencies: is-inside-container: 1.0.0 - dev: false + dev: true /isarray@1.0.0: resolution: {integrity: sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==} @@ -11063,7 +11058,7 @@ packages: define-lazy-prop: 3.0.0 is-inside-container: 1.0.0 is-wsl: 3.1.0 - dev: false + dev: true /optionator@0.9.3: resolution: {integrity: sha512-JjCoypp+jKn1ttEFExxhetCKeJt9zhAgAve5FXHixTvFDW/5aEktX9bufBKLRRMdU7bNtpLfcGu94B3cdEJgjg==} @@ -11765,7 +11760,7 @@ packages: resolution: {integrity: sha512-P8ur/gp/AmbEzjr729bZnLjXK5Z+4P0zhIJgBgzqRih7hL7BOukHGtSTA3ACMY467GRFz3duQsi0bDZdR7DKdw==} hasBin: true dependencies: - is-core-module: 2.12.1 + is-core-module: 2.13.1 path-parse: 1.0.7 supports-preserve-symlinks-flag: 1.0.0 dev: true @@ -11908,7 +11903,7 @@ packages: /run-applescript@7.0.0: resolution: {integrity: sha512-9by4Ij99JUr/MCFBUkDKLWK3G9HVXmabKz9U5MlIAIuvuzkiOicRYs8XJLxX+xahD+mLiiCYDqF9dKAgtzKP1A==} engines: {node: '>=18'} - dev: false + dev: true /run-parallel@1.2.0: resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==} @@ -12617,30 +12612,6 @@ packages: webpack: 5.91.0(esbuild@0.21.3) dev: true - /terser-webpack-plugin@5.3.10(webpack@5.73.0): - resolution: {integrity: sha512-BKFPWlPDndPs+NGGCr1U59t0XScL5317Y0UReNrHaw9/FwhPENlq6bfgs+4yPfyP51vqC1bQ4rp1EfXW5ZSH9w==} - engines: {node: '>= 10.13.0'} - peerDependencies: - '@swc/core': '*' - esbuild: '*' - uglify-js: '*' - webpack: ^5.1.0 - peerDependenciesMeta: - '@swc/core': - optional: true - esbuild: - optional: true - uglify-js: - optional: true - dependencies: - '@jridgewell/trace-mapping': 0.3.20 - jest-worker: 27.5.1 - schema-utils: 3.3.0 - serialize-javascript: 6.0.2 - terser: 5.27.0 - webpack: 5.73.0(webpack-cli@4.10.0) - dev: true - /terser@5.27.0: resolution: {integrity: sha512-bi1HRwVRskAjheeYl291n3JC4GgO/Ty4z1nVs5AAsmonJulGxpSektecnNedrwK9C7vpvVtcX3cw00VSLt7U2A==} engines: {node: '>=10'} @@ -12786,40 +12757,6 @@ packages: yargs-parser: 21.1.1 dev: true - /ts-jest@29.1.1(esbuild@0.21.3)(jest@29.7.0)(typescript@5.3.3): - resolution: {integrity: sha512-D6xjnnbP17cC85nliwGiL+tpoKN0StpgE0TeOjXQTU6MVCfsB4v7aW05CgQ/1OywGb0x/oy9hHFnN+sczTiRaA==} - engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} - hasBin: true - peerDependencies: - '@babel/core': '>=7.0.0-beta.0 <8' - '@jest/types': ^29.0.0 - babel-jest: ^29.0.0 - esbuild: '*' - jest: ^29.0.0 - typescript: '>=4.3 <6' - peerDependenciesMeta: - '@babel/core': - optional: true - '@jest/types': - optional: true - babel-jest: - optional: true - esbuild: - optional: true - dependencies: - bs-logger: 0.2.6 - esbuild: 0.21.3 - fast-json-stable-stringify: 2.1.0 - jest: 29.7.0(@types/node@18.16.19) - jest-util: 29.7.0 - json5: 2.2.3 - lodash.memoize: 4.1.2 - make-error: 1.3.6 - semver: 7.5.4 - typescript: 5.3.3 - yargs-parser: 21.1.1 - dev: true - /ts-loader@9.3.1(typescript@4.7.4)(webpack@5.73.0): resolution: {integrity: sha512-OkyShkcZTsTwyS3Kt7a4rsT/t2qvEVQuKCTg4LJmpj9fhFR7ukGdZwV6Qq3tRUkqcXtfGpPR7+hFKHCG/0d3Lw==} engines: {node: '>=12.0.0'} @@ -13772,7 +13709,7 @@ packages: neo-async: 2.6.2 schema-utils: 3.3.0 tapable: 2.2.1 - terser-webpack-plugin: 5.3.10(webpack@5.73.0) + terser-webpack-plugin: 5.3.10(esbuild@0.21.3)(webpack@5.91.0) watchpack: 2.4.0 webpack-cli: 4.10.0(webpack@5.73.0) webpack-sources: 3.2.3 @@ -14076,3 +14013,7 @@ packages: compress-commons: 4.1.2 readable-stream: 3.6.2 dev: true + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false