Skip to content

Commit f4e6be0

Browse files
committedJan 24, 2024
feat: refactor provider api
1 parent 9d2661f commit f4e6be0

File tree

9 files changed

+28
-60
lines changed

9 files changed

+28
-60
lines changed
 

‎packages/get-bonus/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@
3434
"test:ci": "vitest --run",
3535
"typecheck": "tsc --noEmit"
3636
},
37+
"dependencies": {
38+
"jsdom": "^24.0.0",
39+
"ofetch": "^1.3.3"
40+
},
3741
"engines": {
3842
"node": ">=v20.10.0"
39-
},
40-
"dependencies": {
41-
"cheerio": "1.0.0-rc.12",
42-
"jsdom": "^24.0.0"
4343
}
4444
}

‎packages/get-bonus/src/animate/index.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import type { Detail, SearchResult, SearchOptions, DetailItem } from '../types';
22

33
import { JSDOM } from 'jsdom';
4+
import { ofetch } from 'ofetch';
5+
46
import { Provider } from '../scraper';
57

68
export class Animate extends Provider {
79
constructor() {
810
super('animate');
911
}
1012

11-
async search(text: string, options?: SearchOptions): Promise<SearchResult[]> {
12-
const html: string = await $fetch('https://www.melonbooks.co.jp/search/search.php', {
13+
async search(text: string, options: SearchOptions): Promise<SearchResult[]> {
14+
const html: string = await ofetch('https://www.melonbooks.co.jp/search/search.php', {
1315
query: {
1416
name: text,
1517
'additional[]': 'pr'

‎packages/get-bonus/src/comiczin/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export class Comiczin extends Provider {
77
super('comiczin');
88
}
99

10-
async search(text: string, options?: SearchOptions): Promise<SearchResult[]> {
10+
async search(text: string, options: SearchOptions): Promise<SearchResult[]> {
1111
return [];
1212
}
1313

‎packages/get-bonus/src/gamers/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export class Gamers extends Provider {
77
super('gamers');
88
}
99

10-
async search(text: string, options?: SearchOptions): Promise<SearchResult[]> {
10+
async search(text: string, options: SearchOptions): Promise<SearchResult[]> {
1111
return [];
1212
}
1313

‎packages/get-bonus/src/mangaoh/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export class Mangaoh extends Provider {
77
super('mangaoh');
88
}
99

10-
async search(text: string, options?: SearchOptions): Promise<SearchResult[]> {
10+
async search(text: string, options: SearchOptions): Promise<SearchResult[]> {
1111
return [];
1212
}
1313

‎packages/get-bonus/src/melonbooks/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export class Melonbooks extends Provider {
77
super('melonbooks');
88
}
99

10-
async search(text: string, options?: SearchOptions): Promise<SearchResult[]> {
10+
async search(text: string, options: SearchOptions): Promise<SearchResult[]> {
1111
return [];
1212
}
1313

‎packages/get-bonus/src/scraper.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export abstract class Provider {
4242
this.id = name;
4343
}
4444

45-
abstract search(text: string, options?: Partial<SearchOptions>): Promise<SearchResult[]>;
45+
abstract search(text: string, options: Partial<SearchOptions>): Promise<SearchResult[]>;
4646

4747
abstract detail(url: string): Promise<Detail | undefined>;
4848
}

‎packages/get-bonus/src/toranoana/index.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import type { Detail, SearchResult, SearchOptions, DetailItem } from '../types';
22

33
import { JSDOM } from 'jsdom';
4+
import { ofetch } from 'ofetch';
5+
46
import { Provider } from '../scraper';
57

68
export class Toranoana extends Provider {
79
constructor() {
810
super('toranoana');
911
}
1012

11-
async search(text: string, options?: SearchOptions): Promise<SearchResult[]> {
12-
const html: string = await $fetch('https://ecs.toranoana.jp/tora/ec/app/catalog/list', {
13+
async search(text: string, options: SearchOptions): Promise<SearchResult[]> {
14+
const html: string = await ofetch('https://ecs.toranoana.jp/tora/ec/app/catalog/list', {
1315
query: {
1416
searchWord: text,
1517
stock_status: '○,△',

‎pnpm-lock.yaml

+11-47
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.