Skip to content

Commit

Permalink
feat: 添加正文解密规则
Browse files Browse the repository at this point in the history
  • Loading branch information
aooiuu committed Sep 22, 2024
1 parent b62e884 commit 9654508
Show file tree
Hide file tree
Showing 16 changed files with 408 additions and 257 deletions.
129 changes: 2 additions & 127 deletions docs/rule/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,133 +14,8 @@ outline: deep

::: code-group

```typescript
export interface Rule {
// ===== 通用字段 =====
// 域名
// 当发起网络请求时, 如果最终的地址非 `http` 开头, 那么请求的时候会自动拼接上 `host`
// 规则里也可以使用变量 `$host` 来获取它
host: string;
id: string; // uuid, 用于区分规则的唯一性
name: string; // 规则名称
sort: number; // 规则排序, 越高越靠前
contentType: ContentType; // 规则类型
loadJs: string; // 全局JS脚本
author: string; // 规则作者
userAgent: string; // Headers JSON字符串

// ===== 解析流程 - 搜索 =====
enableSearch: boolean; // 表示搜索功能开启的状态
searchUrl: string; // 用法可参考 `URL地址规则`
// 以下规则用法可参考 `取列表规则`
// 可以使用变量: `result` 获取 `searchUrl` 的结果
searchList: string;
// 以下规则用法可参考 `取内容规则`
// 可以使用变量: `result` 获取 `searchList` 数组当前项的结果
searchCover: string; // 封面
searchName: string; // 标题
searchAuthor: string; // 作者
searchChapter: string; // 最新章节
searchDescription: string; // 描述
searchResult: string; // 结果

// ===== 解析流程 - 章节列表 =====
// 以下规则用法可参考 `URL地址规则`
// 可以使用变量: `result` 获取 `searchResult` 或者 `discoverResult` 的结果
chapterUrl: string;
// 以下规则用法可参考 `取列表规则`
// 可以使用变量: `result` 获取 `chapterUrl` 的结果
// 可以使用变量: `lastResult` 获取 `searchResult` 或者 `discoverResult` 的结果
chapterList: string; // 列表
// 以下规则用法可参考 `取内容规则`
// 可以使用变量: `result` 获取 `chapterList` 数组当前项的结果
// 可以使用变量: `lastResult` 获取 `searchResult` 或者 `discoverResult` 的结果
chapterName: string; // 标题
chapterCover: string; // 封面
chapterTime: string; // 时间
contentItems: string; // 内容
chapterNextUrl: string; // 下一页地址
chapterResult: string; // 结果

// ===== 解析流程 - 发现页 =====
enableDiscover: boolean; // 是否启用发现页
discoverUrl: string; // 用法可参考 `发现页分类规则`
// 以下规则用法可参考 `取列表规则`
// 可以使用变量: `result` 获取 `discoverUrl` 的结果
discoverList: string; // 列表
// 以下规则用法可参考 `取内容规则`
// 可以使用变量: `result` 获取 `discoverList` 数组当前项的结果
discoverName: string; // 标题
discoverCover: string; // 封面
discoverAuthor: string; // 作者
discoverDescription: string; // 描述
discoverResult: string; // 结果
// discoverItems: string
discoverTags: string;
discoverChapter: string;
discoverNextUrl: string; // 下一页地址

// ===== 解析流程 - 正文 =====
contentUrl: string;
contentNextUrl: string;
}

enum ContentType {
MANGA = 0, // 漫画
NOVEL = 1, // 小说
VIDEO = 2, // 视频
AUDIO = 3, // 音频
RSS = 4,
NOVELMORE = 5
}
```

```json
{
"id": "xxx-xxx-xxx-xxx-xxx",
"author": "",
"name": "",
"host": "",
"icon": "",
"contentType": 1,
"sort": 0,
"userAgent": "",
"enableDiscover": false,
"discoverUrl": "",
"discoverNextUrl": "",
"discoverList": "",
"discoverTags": "",
"discoverName": "",
"discoverCover": "",
"discoverChapter": "",
"discoverDescription": "",
"discoverResult": "",
"enableSearch": false,
"searchUrl": "",
"searchAuthor": "",
"chapterCover": "",
"chapterTime": "",
"discoverAuthor": "",
"searchList": "",
"searchTags": "",
"searchName": "",
"searchCover": "",
"searchChapter": "",
"searchDescription": "",
"searchResult": "",
"enableMultiRoads": false,
"chapterRoads": "",
"chapterRoadName": "",
"chapterUrl": "",
"chapterNextUrl": "",
"chapterList": "",
"chapterName": "",
"chapterResult": "",
"contentUrl": "",
"contentNextUrl": "",
"contentItems": ""
}
```
<<< ./rule-tpl.ts [typescript]
<<< ./rule-tpl.json [json]

:::

Expand Down
45 changes: 45 additions & 0 deletions docs/rule/rule-tpl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"id": "xxx-xxx-xxx-xxx-xxx",
"author": "",
"name": "",
"host": "",
"icon": "",
"contentType": 1,
"sort": 0,
"userAgent": "",
"enableDiscover": false,
"discoverUrl": "",
"discoverNextUrl": "",
"discoverList": "",
"discoverTags": "",
"discoverName": "",
"discoverCover": "",
"discoverChapter": "",
"discoverDescription": "",
"discoverResult": "",
"enableSearch": false,
"searchUrl": "",
"searchAuthor": "",
"chapterCover": "",
"chapterTime": "",
"discoverAuthor": "",
"searchList": "",
"searchTags": "",
"searchName": "",
"searchCover": "",
"searchChapter": "",
"searchDescription": "",
"searchResult": "",
"enableMultiRoads": false,
"chapterRoads": "",
"chapterRoadName": "",
"chapterUrl": "",
"chapterNextUrl": "",
"chapterList": "",
"chapterName": "",
"chapterResult": "",
"contentUrl": "",
"contentNextUrl": "",
"contentItems": "",
"contentDecoder": ""
}
79 changes: 79 additions & 0 deletions docs/rule/rule-tpl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
export interface Rule {
// ===== 通用字段 =====
// 域名
// 当发起网络请求时, 如果最终的地址非 `http` 开头, 那么请求的时候会自动拼接上 `host`
// 规则里也可以使用变量 `$host` 来获取它
host: string;
id: string; // uuid, 用于区分规则的唯一性
name: string; // 规则名称
sort: number; // 规则排序, 越高越靠前
contentType: ContentType; // 规则类型
loadJs: string; // 全局JS脚本
author: string; // 规则作者
userAgent: string; // Headers JSON字符串

// ===== 解析流程 - 搜索 =====
enableSearch: boolean; // 表示搜索功能开启的状态
searchUrl: string; // 用法可参考 `URL地址规则`
// 以下规则用法可参考 `取列表规则`
// 可以使用变量: `result` 获取 `searchUrl` 的结果
searchList: string;
// 以下规则用法可参考 `取内容规则`
// 可以使用变量: `result` 获取 `searchList` 数组当前项的结果
searchCover: string; // 封面
searchName: string; // 标题
searchAuthor: string; // 作者
searchChapter: string; // 最新章节
searchDescription: string; // 描述
searchResult: string; // 结果

// ===== 解析流程 - 章节列表 =====
// 以下规则用法可参考 `URL地址规则`
// 可以使用变量: `result` 获取 `searchResult` 或者 `discoverResult` 的结果
chapterUrl: string;
// 以下规则用法可参考 `取列表规则`
// 可以使用变量: `result` 获取 `chapterUrl` 的结果
// 可以使用变量: `lastResult` 获取 `searchResult` 或者 `discoverResult` 的结果
chapterList: string; // 列表
// 以下规则用法可参考 `取内容规则`
// 可以使用变量: `result` 获取 `chapterList` 数组当前项的结果
// 可以使用变量: `lastResult` 获取 `searchResult` 或者 `discoverResult` 的结果
chapterName: string; // 标题
chapterCover: string; // 封面
chapterTime: string; // 时间
chapterNextUrl: string; // 下一页地址
chapterResult: string; // 结果

// ===== 解析流程 - 发现页 =====
enableDiscover: boolean; // 是否启用发现页
discoverUrl: string; // 用法可参考 `发现页分类规则`
// 以下规则用法可参考 `取列表规则`
// 可以使用变量: `result` 获取 `discoverUrl` 的结果
discoverList: string; // 列表
// 以下规则用法可参考 `取内容规则`
// 可以使用变量: `result` 获取 `discoverList` 数组当前项的结果
discoverName: string; // 标题
discoverCover: string; // 封面
discoverAuthor: string; // 作者
discoverDescription: string; // 描述
discoverResult: string; // 结果
// discoverItems: string
discoverTags: string;
discoverChapter: string;
discoverNextUrl: string; // 下一页地址

// ===== 解析流程 - 正文 =====
contentUrl: string;
contentItems: string; // 内容
contentNextUrl: string; // 用于一篇正文存在多个页面的场景
contentDecoder: string; // 用户正文图片需要解密的场景
}

enum ContentType {
MANGA = 0, // 漫画
NOVEL = 1, // 小说
VIDEO = 2, // 视频
AUDIO = 3, // 音频
RSS = 4,
NOVELMORE = 5
}
1 change: 1 addition & 0 deletions docs/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default defineConfig({
plugins: [UnoCSS()],

server: {
port: 8897,
hmr: {
overlay: false
}
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/analyzer/RuleManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,4 +391,8 @@ export class RuleManager implements IParser {

return result;
}

contentDecoder(result: string): Promise<string> {
return this.analyzerManager.getString(this.rule.contentDecoder, result);
}
}
3 changes: 3 additions & 0 deletions packages/core/src/parser/iptv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export default class IPTV implements IParser {
constructor(rule: Rule) {
this._rule = rule;
}
async contentDecoder(result: string): Promise<string> {
return result;
}

async _getM3UList() {
if (this._m3u.length) return;
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ export interface IParser {
getContent(result: string): Promise<string[]>;
discoverMap(): Promise<DiscoverItem[]>;
discover(result: string): Promise<SearchItem[]>;
contentDecoder(result: string): Promise<string>;
}
2 changes: 2 additions & 0 deletions packages/rule-utils/src/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export interface Rule {
// ===== 解析流程 - 正文 =====
contentUrl: string;
contentNextUrl: string;
contentDecoder: string;

// ===== 暂不支持 =====
createTime?: number;
Expand Down Expand Up @@ -133,6 +134,7 @@ export function createRule(rule: Partial<Rule>): Rule {
contentUrl: '',
contentNextUrl: '',
contentItems: '',
contentDecoder: '',
viewStyle: 0
},
rule
Expand Down
10 changes: 10 additions & 0 deletions packages/shared/src/controller/RuleManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ export class RuleManager extends BaseController {
return await this.discoverByRule({ rule, data });
}

@Post('content-decoder')
async contentDecoder({ ruleId, content }: { ruleId: string; content: string }) {
const rule = await this.getRule(ruleId);
const ruleManager = this.createRuleManager(rule);
return await ruleManager.contentDecoder(content);
}

@Post('search-by-rule-id')
// @Cacheable({
// ttl: 1000 * 60 * 5,
Expand Down Expand Up @@ -69,9 +76,11 @@ export class RuleManager extends BaseController {
async content({ filePath, chapterPath, ruleId, noCache }: { ruleId: string; filePath: string; chapterPath: string; noCache: boolean }) {
const cacheKey = `content@${ruleId || '__local__'}@${md5(filePath)}@v3_${md5(chapterPath)}`;
const result: {
contentDecoder: boolean; // 是否需要正文解密
contentType?: number;
content: string[] | string;
} = {
contentDecoder: false,
content: []
};
if (noCache) {
Expand All @@ -86,6 +95,7 @@ export class RuleManager extends BaseController {
// 在线
const rule = await this.getRule(ruleId);
const { contentType, content } = await this.contentByRule({ rule, chapterPath });
result.contentDecoder = !!rule.contentDecoder;
result.content = content;
result.contentType = contentType;
} else {
Expand Down
7 changes: 7 additions & 0 deletions packages/shared/src/entity/ResourceRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,4 +357,11 @@ export class ResourceRule {
default: ''
})
loadJs!: string;

@Column({
name: 'content_decoder',
type: 'text',
default: ''
})
contentDecoder!: string;
}
3 changes: 2 additions & 1 deletion packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@
"monaco-editor": "0.51.0",
"nprogress": "^0.2.0",
"p-limit": "^6.1.0",
"p-queue": "^8.0.1",
"pinia": "^2.2.2",
"qs": "^6.13.0",
"sqlite3": "5.1.6",
"uuid": "^10.0.0",
"vue": "^3.5.6",
"vue": "^3.5.8",
"vue-router": "^4.4.5"
},
"devDependencies": {
Expand Down
8 changes: 8 additions & 0 deletions packages/web/src/api/modules/rule-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,11 @@ export function analyzerUrl(data: any) {
data
});
}

export function contentDecoder(data: any) {
return request({
method: 'post',
url: 'rule-manager/content-decoder',
data
});
}
Loading

0 comments on commit 9654508

Please sign in to comment.