Skip to content

Commit

Permalink
feat: 处理 lastResult 规则
Browse files Browse the repository at this point in the history
  • Loading branch information
aooiuu committed Jul 31, 2024
1 parent 63f02b2 commit 2c168d3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/rule/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ enum ContentType {
| searchKey ||`$keyword` , ⚠️不推荐使用 |
| $host || 替换规则的 `host` |
| $result || 上一个步骤 result 字段的结果 |
| lastResult | | |
| lastResult | | |
| searchPage || |
| $page || |
| $pageSize || |
Expand Down
30 changes: 17 additions & 13 deletions packages/core/src/analyzer/RuleManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ export class RuleManager {
}

async getChapter(result: string): Promise<ChapterItem[]> {
JSEngine.setEnvironment({
result,
})
if (this.rule.chapterUrl === '正文') {
return [
{
Expand All @@ -87,8 +90,9 @@ export class RuleManager {

JSEngine.setEnvironment({
page: 1,
baseUrl: chapterUrl,
lastResult: result,
result: body,
baseUrl: chapterUrl,
})

let list = []
Expand All @@ -115,20 +119,17 @@ export class RuleManager {
return chapterItems
}

async getContent(result: string, lastResult?: string): Promise<string[]> {
if (lastResult) {
JSEngine.setEnvironment({
page: 1,
result: lastResult,
lastResult,
})
}
async getContent(result: string): Promise<string[]> {
JSEngine.setEnvironment({
result,
})
const contentUrl = this.rule.contentUrl !== 'null' ? this.rule.contentUrl : null
const { body, params } = await fetch(this.parseUrl(contentUrl || result), '', result, this.rule)
JSEngine.setEnvironment({
page: 1,
baseUrl: params.url,
lastResult: result,
result: body,
baseUrl: params.url,
})
let list = await this.analyzerManager.getStringList(this.rule.contentItems, body)
if (this.rule.contentType === ContentType.NOVEL) {
Expand Down Expand Up @@ -234,6 +235,9 @@ export class RuleManager {

// 获取分类下内容
async discover(url: string, page = 1) {
JSEngine.setEnvironment({
result: url,
})
const hasNextUrlRule
= this.rule.discoverNextUrl !== undefined
&& this.rule.discoverNextUrl.length > 0
Expand Down Expand Up @@ -265,9 +269,9 @@ export class RuleManager {
}

JSEngine.setEnvironment({
page,
rule: this.rule,
result: discoverUrl,
page: 1,
lastResult: url,
result: body,
baseUrl: this.rule.host,
})

Expand Down

0 comments on commit 2c168d3

Please sign in to comment.