narou 0.5.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.browser.d.ts +30 -0
- package/dist/index.browser.d.ts.map +1 -0
- package/dist/index.browser.js +119 -0
- package/dist/index.browser.js.map +1 -0
- package/dist/index.common.d.ts +8 -0
- package/dist/index.common.d.ts.map +1 -0
- package/dist/index.common.js +17 -0
- package/dist/index.common.js.map +1 -0
- package/dist/index.d.ts +30 -31
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +120 -113
- package/dist/index.js.map +1 -1
- package/dist/narou-fetch.d.ts +13 -0
- package/dist/narou-fetch.d.ts.map +1 -0
- package/dist/narou-fetch.js +130 -0
- package/dist/narou-fetch.js.map +1 -0
- package/dist/narou-jsonp.d.ts +10 -0
- package/dist/narou-jsonp.d.ts.map +1 -0
- package/dist/narou-jsonp.js +102 -0
- package/dist/narou-jsonp.js.map +1 -0
- package/dist/narou-ranking-results.d.ts +8 -8
- package/dist/narou-ranking-results.js +2 -2
- package/dist/narou-search-results.d.ts +90 -89
- package/dist/narou-search-results.d.ts.map +1 -1
- package/dist/narou-search-results.js +51 -51
- package/dist/narou-search-results.js.map +1 -1
- package/dist/narou.d.ts +24 -25
- package/dist/narou.d.ts.map +1 -1
- package/dist/narou.js +104 -142
- package/dist/narou.js.map +1 -1
- package/dist/params.d.ts +230 -230
- package/dist/params.js +173 -173
- package/dist/ranking-history.d.ts +13 -13
- package/dist/ranking-history.js +13 -13
- package/dist/ranking-history.js.map +1 -1
- package/dist/ranking.d.ts +47 -45
- package/dist/ranking.d.ts.map +1 -1
- package/dist/ranking.js +167 -165
- package/dist/ranking.js.map +1 -1
- package/dist/search-builder-r18.d.ts +21 -21
- package/dist/search-builder-r18.d.ts.map +1 -1
- package/dist/search-builder-r18.js +64 -63
- package/dist/search-builder-r18.js.map +1 -1
- package/dist/search-builder.d.ts +228 -226
- package/dist/search-builder.d.ts.map +1 -1
- package/dist/search-builder.js +412 -412
- package/dist/search-builder.js.map +1 -1
- package/dist/util/jsonp.d.ts +14 -0
- package/dist/util/jsonp.d.ts.map +1 -0
- package/dist/util/jsonp.js +48 -0
- package/dist/util/jsonp.js.map +1 -0
- package/dist/util/unzipp.d.ts +3 -3
- package/dist/util/unzipp.js +56 -56
- package/dist/util/unzipp.js.map +1 -1
- package/dist/util/url.d.ts +10 -0
- package/dist/util/url.d.ts.map +1 -0
- package/dist/util/url.js +9 -0
- package/dist/util/url.js.map +1 -0
- package/dist.es2015/index.browser.js +50 -0
- package/dist.es2015/index.browser.js.map +1 -0
- package/dist.es2015/index.common.js +5 -0
- package/dist.es2015/index.common.js.map +1 -0
- package/dist.es2015/index.js +50 -49
- package/dist.es2015/index.js.map +1 -1
- package/dist.es2015/narou-fetch.js +44 -0
- package/dist.es2015/narou-fetch.js.map +1 -0
- package/dist.es2015/narou-jsonp.js +22 -0
- package/dist.es2015/narou-jsonp.js.map +1 -0
- package/dist.es2015/narou-ranking-results.js +1 -1
- package/dist.es2015/narou-search-results.js +46 -46
- package/dist.es2015/narou-search-results.js.map +1 -1
- package/dist.es2015/narou.js +23 -60
- package/dist.es2015/narou.js.map +1 -1
- package/dist.es2015/params.js +170 -170
- package/dist.es2015/ranking-history.js +9 -9
- package/dist.es2015/ranking.js +90 -90
- package/dist.es2015/ranking.js.map +1 -1
- package/dist.es2015/search-builder-r18.js +41 -42
- package/dist.es2015/search-builder-r18.js.map +1 -1
- package/dist.es2015/search-builder.js +383 -383
- package/dist.es2015/search-builder.js.map +1 -1
- package/dist.es2015/util/jsonp.js +43 -0
- package/dist.es2015/util/jsonp.js.map +1 -0
- package/dist.es2015/util/unzipp.js +7 -7
- package/dist.es2015/util/url.js +7 -0
- package/dist.es2015/util/url.js.map +1 -0
- package/dist.esm/index.browser.js +102 -0
- package/dist.esm/index.browser.js.map +1 -0
- package/dist.esm/index.common.js +5 -0
- package/dist.esm/index.common.js.map +1 -0
- package/dist.esm/index.js +102 -97
- package/dist.esm/index.js.map +1 -1
- package/dist.esm/narou-fetch.js +128 -0
- package/dist.esm/narou-fetch.js.map +1 -0
- package/dist.esm/narou-jsonp.js +100 -0
- package/dist.esm/narou-jsonp.js.map +1 -0
- package/dist.esm/narou-ranking-results.js +1 -1
- package/dist.esm/narou-search-results.js +49 -49
- package/dist.esm/narou-search-results.js.map +1 -1
- package/dist.esm/narou.js +102 -140
- package/dist.esm/narou.js.map +1 -1
- package/dist.esm/params.js +170 -170
- package/dist.esm/ranking-history.js +9 -9
- package/dist.esm/ranking.js +164 -162
- package/dist.esm/ranking.js.map +1 -1
- package/dist.esm/search-builder-r18.js +62 -61
- package/dist.esm/search-builder-r18.js.map +1 -1
- package/dist.esm/search-builder.js +410 -410
- package/dist.esm/search-builder.js.map +1 -1
- package/dist.esm/util/jsonp.js +44 -0
- package/dist.esm/util/jsonp.js.map +1 -0
- package/dist.esm/util/unzipp.js +52 -52
- package/dist.esm/util/url.js +7 -0
- package/dist.esm/util/url.js.map +1 -0
- package/package-lock.json +3328 -4289
- package/package.json +8 -9
- package/src/index.browser.ts +63 -0
- package/src/index.common.ts +17 -0
- package/src/index.ts +22 -23
- package/src/narou-fetch.ts +51 -0
- package/src/narou-jsonp.ts +29 -0
- package/src/narou-ranking-results.ts +9 -9
- package/src/narou-search-results.ts +11 -10
- package/src/narou.ts +21 -49
- package/src/params.ts +280 -280
- package/src/ranking.ts +111 -107
- package/src/search-builder-r18.ts +1 -2
- package/src/search-builder.ts +5 -3
- package/src/util/jsonp.ts +66 -0
- package/src/util/unzipp.ts +9 -9
- package/src/util/url.ts +7 -0
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "narou",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "Narou API Wrapper",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
+
"browser": "dist/index.browser.js",
|
|
6
7
|
"types": "dist/index.d.ts",
|
|
7
8
|
"typings": "dist/index.d.ts",
|
|
8
9
|
"module": "dist.esm/index.js",
|
|
@@ -29,22 +30,20 @@
|
|
|
29
30
|
"@types/node": "^13.5.0",
|
|
30
31
|
"@types/node-fetch": "^2.5.7",
|
|
31
32
|
"chai": "^4.1.2",
|
|
32
|
-
"
|
|
33
|
-
"lint-staged": "^10.0.2",
|
|
34
|
-
"mocha": "^7.0.1",
|
|
33
|
+
"mocha": "^9.1.3",
|
|
35
34
|
"mocha-typescript": "^1.1.12",
|
|
36
35
|
"npm-run-all": "^4.1.4",
|
|
37
36
|
"nyc": "^15.0.0",
|
|
38
|
-
"prettier": "^
|
|
37
|
+
"prettier": "^2.4.1",
|
|
39
38
|
"rimraf": "^3.0.0",
|
|
40
|
-
"run-sequence": "^2.2.1",
|
|
41
39
|
"touch": "^3.1.0",
|
|
42
|
-
"ts-node": "^
|
|
40
|
+
"ts-node": "^10.3.0",
|
|
43
41
|
"tslint": "^6.0.0",
|
|
44
42
|
"tslint-config-prettier": "^1.16.0",
|
|
45
43
|
"tslint-plugin-prettier": "^2.0.1",
|
|
46
|
-
"typedoc": "^0.
|
|
47
|
-
"typescript": "^4.
|
|
44
|
+
"typedoc": "^0.22.5",
|
|
45
|
+
"typescript": "^4.4.4",
|
|
46
|
+
"node-fetch": "^2.6.1"
|
|
48
47
|
},
|
|
49
48
|
"scripts": {
|
|
50
49
|
"build": "npm-run-all check clean build:tsc",
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import NarouNovelJsonp from "./narou-jsonp";
|
|
2
|
+
import NarouNovel from "./narou";
|
|
3
|
+
import SearchBuilder from "./search-builder";
|
|
4
|
+
import SearchBuilderR18 from "./search-builder-r18";
|
|
5
|
+
import RankingBuilder from "./ranking";
|
|
6
|
+
import { formatRankingHistory, RankingHistoryResult } from "./ranking-history";
|
|
7
|
+
|
|
8
|
+
export * from "./index.common";
|
|
9
|
+
export { NarouNovelJsonp };
|
|
10
|
+
|
|
11
|
+
const narouNovelJsonp = new NarouNovelJsonp();
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 検索
|
|
15
|
+
* @param {string} [word] - 検索ワード
|
|
16
|
+
* @returns {SearchBuilder}
|
|
17
|
+
*/
|
|
18
|
+
export function search(
|
|
19
|
+
word: string = "",
|
|
20
|
+
api: NarouNovel = narouNovelJsonp
|
|
21
|
+
): SearchBuilder {
|
|
22
|
+
const builder = new SearchBuilder({}, api);
|
|
23
|
+
if (word != "") builder.word(word);
|
|
24
|
+
return builder;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 検索
|
|
29
|
+
* @param {string} [word] - 検索ワード
|
|
30
|
+
* @returns {SearchBuilder}
|
|
31
|
+
*/
|
|
32
|
+
export function searchR18(
|
|
33
|
+
word: string = "",
|
|
34
|
+
api: NarouNovel = narouNovelJsonp
|
|
35
|
+
): SearchBuilderR18 {
|
|
36
|
+
const builder = new SearchBuilderR18({}, api);
|
|
37
|
+
if (word != "") builder.word(word);
|
|
38
|
+
return builder;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function ranking(api: NarouNovel = narouNovelJsonp): RankingBuilder {
|
|
42
|
+
const builder = new RankingBuilder({}, api);
|
|
43
|
+
return builder;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function rankingHistory(
|
|
47
|
+
ncode: string,
|
|
48
|
+
api: NarouNovel = narouNovelJsonp
|
|
49
|
+
): Promise<RankingHistoryResult[]> {
|
|
50
|
+
const result = await api.executeRankingHistory({ ncode });
|
|
51
|
+
if (Array.isArray(result)) {
|
|
52
|
+
return result.map(formatRankingHistory);
|
|
53
|
+
} else {
|
|
54
|
+
throw new Error(result);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export default {
|
|
59
|
+
search,
|
|
60
|
+
ranking,
|
|
61
|
+
searchR18,
|
|
62
|
+
rankingHistory,
|
|
63
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import NarouNovel from "./narou";
|
|
2
|
+
import { RankingHistoryResult } from "./ranking-history";
|
|
3
|
+
|
|
4
|
+
export { NarouNovel, RankingHistoryResult };
|
|
5
|
+
export { RankingType } from "./ranking";
|
|
6
|
+
export {
|
|
7
|
+
Fields,
|
|
8
|
+
Order,
|
|
9
|
+
BigGenre,
|
|
10
|
+
BigGenreNotation,
|
|
11
|
+
Genre,
|
|
12
|
+
GenreNotation,
|
|
13
|
+
R18Site,
|
|
14
|
+
R18SiteNotation,
|
|
15
|
+
} from "./params";
|
|
16
|
+
export { NarouSearchResult } from "./narou-search-results";
|
|
17
|
+
export { NarouRankingResult, RankingResult } from "./narou-ranking-results";
|
package/src/index.ts
CHANGED
|
@@ -1,31 +1,26 @@
|
|
|
1
1
|
import NarouNovel from "./narou";
|
|
2
|
+
import NarouNovelFetch from "./narou-fetch";
|
|
3
|
+
import NarouNovelJsonp from "./narou-jsonp";
|
|
2
4
|
import RankingBuilder from "./ranking";
|
|
3
5
|
import { formatRankingHistory, RankingHistoryResult } from "./ranking-history";
|
|
4
6
|
import SearchBuilder from "./search-builder";
|
|
5
7
|
import SearchBuilderR18 from "./search-builder-r18";
|
|
6
8
|
|
|
7
|
-
export
|
|
8
|
-
export {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Order,
|
|
12
|
-
BigGenre,
|
|
13
|
-
BigGenreNotation,
|
|
14
|
-
Genre,
|
|
15
|
-
GenreNotation,
|
|
16
|
-
R18Site,
|
|
17
|
-
R18SiteNotation
|
|
18
|
-
} from "./params";
|
|
19
|
-
export { NarouSearchResult } from "./narou-search-results";
|
|
20
|
-
export { NarouRankingResult, RankingResult } from "./narou-ranking-results";
|
|
9
|
+
export * from "./index.common";
|
|
10
|
+
export { NarouNovelFetch, NarouNovelJsonp };
|
|
11
|
+
|
|
12
|
+
const narouNovelFetch = new NarouNovelFetch();
|
|
21
13
|
|
|
22
14
|
/**
|
|
23
15
|
* 検索
|
|
24
16
|
* @param {string} [word] - 検索ワード
|
|
25
17
|
* @returns {SearchBuilder}
|
|
26
18
|
*/
|
|
27
|
-
export function search(
|
|
28
|
-
|
|
19
|
+
export function search(
|
|
20
|
+
word: string = "",
|
|
21
|
+
api: NarouNovel = narouNovelFetch
|
|
22
|
+
): SearchBuilder {
|
|
23
|
+
const builder = new SearchBuilder({}, api);
|
|
29
24
|
if (word != "") builder.word(word);
|
|
30
25
|
return builder;
|
|
31
26
|
}
|
|
@@ -35,21 +30,25 @@ export function search(word: string = ""): SearchBuilder {
|
|
|
35
30
|
* @param {string} [word] - 検索ワード
|
|
36
31
|
* @returns {SearchBuilder}
|
|
37
32
|
*/
|
|
38
|
-
export function searchR18(
|
|
39
|
-
|
|
33
|
+
export function searchR18(
|
|
34
|
+
word: string = "",
|
|
35
|
+
api: NarouNovel = narouNovelFetch
|
|
36
|
+
): SearchBuilderR18 {
|
|
37
|
+
const builder = new SearchBuilderR18({}, api);
|
|
40
38
|
if (word != "") builder.word(word);
|
|
41
39
|
return builder;
|
|
42
40
|
}
|
|
43
41
|
|
|
44
|
-
export function ranking(): RankingBuilder {
|
|
45
|
-
const builder = new RankingBuilder();
|
|
42
|
+
export function ranking(api: NarouNovel = narouNovelFetch): RankingBuilder {
|
|
43
|
+
const builder = new RankingBuilder({}, api);
|
|
46
44
|
return builder;
|
|
47
45
|
}
|
|
48
46
|
|
|
49
47
|
export async function rankingHistory(
|
|
50
|
-
ncode: string
|
|
48
|
+
ncode: string,
|
|
49
|
+
api: NarouNovel = narouNovelFetch
|
|
51
50
|
): Promise<RankingHistoryResult[]> {
|
|
52
|
-
const result = await
|
|
51
|
+
const result = await api.executeRankingHistory({ ncode });
|
|
53
52
|
if (Array.isArray(result)) {
|
|
54
53
|
return result.map(formatRankingHistory);
|
|
55
54
|
} else {
|
|
@@ -61,5 +60,5 @@ export default {
|
|
|
61
60
|
search,
|
|
62
61
|
ranking,
|
|
63
62
|
searchR18,
|
|
64
|
-
rankingHistory
|
|
63
|
+
rankingHistory,
|
|
65
64
|
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import nodeFetch from "node-fetch";
|
|
2
|
+
import nodeURL from "./util/url";
|
|
3
|
+
|
|
4
|
+
import { unzipp } from "./util/unzipp";
|
|
5
|
+
import NarouNovel, { NarouParams } from "./narou";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* なろう小説APIへのリクエストを実行する
|
|
9
|
+
* @class NarouNovel
|
|
10
|
+
* @private
|
|
11
|
+
*/
|
|
12
|
+
export default class NarouNovelFetch extends NarouNovel {
|
|
13
|
+
constructor(private fetch = nodeFetch) {
|
|
14
|
+
super();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
protected async execute<T>(
|
|
18
|
+
params: NarouParams,
|
|
19
|
+
endpoint: string
|
|
20
|
+
): Promise<T> {
|
|
21
|
+
const query = { ...params, out: "json" };
|
|
22
|
+
|
|
23
|
+
if (query.gzip === undefined) {
|
|
24
|
+
query.gzip = 5;
|
|
25
|
+
}
|
|
26
|
+
const url = new nodeURL(endpoint);
|
|
27
|
+
|
|
28
|
+
Object.entries(query).forEach(([key, value]) => {
|
|
29
|
+
if (value) {
|
|
30
|
+
url.searchParams.append(key, value.toString());
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const res = await this.fetch(url);
|
|
35
|
+
|
|
36
|
+
if (query.gzip === 0) {
|
|
37
|
+
return await res.json();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const buffer = await res.buffer();
|
|
41
|
+
try {
|
|
42
|
+
return await unzipp(buffer);
|
|
43
|
+
} catch {
|
|
44
|
+
try {
|
|
45
|
+
throw JSON.stringify(buffer.toString());
|
|
46
|
+
} catch {
|
|
47
|
+
throw buffer.toString();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import nodeURL from "./util/url";
|
|
2
|
+
|
|
3
|
+
import NarouNovel, { NarouParams } from "./narou";
|
|
4
|
+
import { jsonp } from "./util/jsonp";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* なろう小説APIへのリクエストを実行する
|
|
8
|
+
* @class NarouNovel
|
|
9
|
+
* @private
|
|
10
|
+
*/
|
|
11
|
+
export default class NarouNovelJsonp extends NarouNovel {
|
|
12
|
+
protected async execute<T>(
|
|
13
|
+
params: NarouParams,
|
|
14
|
+
endpoint: string
|
|
15
|
+
): Promise<T> {
|
|
16
|
+
const query = { ...params, out: "jsonp" };
|
|
17
|
+
query.gzip = 0;
|
|
18
|
+
|
|
19
|
+
const url = new nodeURL(endpoint);
|
|
20
|
+
|
|
21
|
+
Object.entries(query).forEach(([key, value]) => {
|
|
22
|
+
if (value) {
|
|
23
|
+
url.searchParams.append(key, value.toString());
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return await jsonp(url.toString());
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { NarouSearchResult } from "./narou-search-results";
|
|
2
|
-
|
|
3
|
-
export interface NarouRankingResult {
|
|
4
|
-
ncode: string;
|
|
5
|
-
rank: number;
|
|
6
|
-
pt: number;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface RankingResult extends NarouSearchResult, NarouRankingResult {}
|
|
1
|
+
import { NarouSearchResult } from "./narou-search-results";
|
|
2
|
+
|
|
3
|
+
export interface NarouRankingResult {
|
|
4
|
+
ncode: string;
|
|
5
|
+
rank: number;
|
|
6
|
+
pt: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface RankingResult extends NarouSearchResult, NarouRankingResult {}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @class NarouSearchResults
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { SearchParams } from "./params";
|
|
6
|
+
import { booleanNumber, Genre, R18Site, SearchParams } from "./params";
|
|
7
7
|
|
|
8
8
|
export default class NarouSearchResults {
|
|
9
9
|
allcount: number;
|
|
@@ -93,23 +93,24 @@ export interface NarouSearchResult {
|
|
|
93
93
|
userid: number;
|
|
94
94
|
writer: string;
|
|
95
95
|
story: string;
|
|
96
|
-
|
|
96
|
+
nocgenre: R18Site;
|
|
97
|
+
genre: Genre;
|
|
97
98
|
keyword: string;
|
|
98
99
|
general_firstup: string;
|
|
99
100
|
general_lastup: string;
|
|
100
101
|
novel_type: number;
|
|
101
102
|
noveltype: number;
|
|
102
|
-
end:
|
|
103
|
+
end: booleanNumber;
|
|
103
104
|
general_all_no: number;
|
|
104
105
|
length: number;
|
|
105
106
|
time: number;
|
|
106
|
-
isstop:
|
|
107
|
-
isr15:
|
|
108
|
-
isbl:
|
|
109
|
-
isgl:
|
|
110
|
-
iszankoku:
|
|
111
|
-
istensei:
|
|
112
|
-
istenni:
|
|
107
|
+
isstop: booleanNumber;
|
|
108
|
+
isr15: booleanNumber;
|
|
109
|
+
isbl: booleanNumber;
|
|
110
|
+
isgl: booleanNumber;
|
|
111
|
+
iszankoku: booleanNumber;
|
|
112
|
+
istensei: booleanNumber;
|
|
113
|
+
istenni: booleanNumber;
|
|
113
114
|
pc_or_k: number;
|
|
114
115
|
global_point: number;
|
|
115
116
|
daily_point: number;
|
package/src/narou.ts
CHANGED
|
@@ -1,83 +1,55 @@
|
|
|
1
|
-
import fetch from "node-fetch";
|
|
2
|
-
import { URL } from "url";
|
|
3
|
-
|
|
4
1
|
import { NarouRankingResult } from "./narou-ranking-results";
|
|
5
2
|
import NarouSearchResults from "./narou-search-results";
|
|
6
3
|
import { RankingHistoryParams, RankingParams, SearchParams } from "./params";
|
|
7
4
|
import { RankingHistoryRawResult } from "./ranking-history";
|
|
8
|
-
import { unzipp } from "./util/unzipp";
|
|
9
5
|
|
|
10
|
-
type NarouParams = SearchParams | RankingParams | RankingHistoryParams;
|
|
6
|
+
export type NarouParams = SearchParams | RankingParams | RankingHistoryParams;
|
|
11
7
|
|
|
12
8
|
/**
|
|
13
9
|
* なろう小説APIへのリクエストを実行する
|
|
14
10
|
* @class NarouNovel
|
|
15
11
|
* @private
|
|
16
12
|
*/
|
|
17
|
-
export default class NarouNovel {
|
|
13
|
+
export default abstract class NarouNovel {
|
|
18
14
|
/**
|
|
19
15
|
* なろう小説APIへの検索リクエストを実行する
|
|
20
16
|
* @param params クエリパラメータ
|
|
21
17
|
* @param endpoint APIエンドポイント
|
|
22
18
|
* @returns {Promise<NarouSearchResults>} 検索結果
|
|
23
19
|
*/
|
|
24
|
-
|
|
20
|
+
protected abstract execute<T>(
|
|
25
21
|
params: NarouParams,
|
|
26
|
-
endpoint
|
|
27
|
-
): Promise<
|
|
28
|
-
const query = { ...params, out: "json" };
|
|
29
|
-
|
|
30
|
-
if (query.gzip === undefined) {
|
|
31
|
-
query.gzip = 5;
|
|
32
|
-
}
|
|
33
|
-
const url = new URL(endpoint);
|
|
34
|
-
|
|
35
|
-
Object.entries(query).forEach(([key, value]) => {
|
|
36
|
-
if (value) {
|
|
37
|
-
url.searchParams.append(key, value.toString());
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
const res = await fetch(url);
|
|
22
|
+
endpoint: string
|
|
23
|
+
): Promise<T>;
|
|
42
24
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const buffer = await res.buffer();
|
|
48
|
-
try {
|
|
49
|
-
return await unzipp(buffer);
|
|
50
|
-
} catch {
|
|
51
|
-
try {
|
|
52
|
-
return JSON.stringify(buffer.toString());
|
|
53
|
-
} catch {
|
|
54
|
-
return buffer.toString();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
static async executeSearch(
|
|
60
|
-
params: any,
|
|
25
|
+
async executeSearch(
|
|
26
|
+
params: NarouParams,
|
|
61
27
|
endpoint = "http://api.syosetu.com/novelapi/api/"
|
|
62
28
|
): Promise<NarouSearchResults> {
|
|
63
29
|
return new NarouSearchResults(await this.execute(params, endpoint), params);
|
|
64
30
|
}
|
|
65
31
|
|
|
66
|
-
|
|
67
|
-
return this.executeSearch(
|
|
32
|
+
async executeNovel(params: SearchParams): Promise<NarouSearchResults> {
|
|
33
|
+
return await this.executeSearch(
|
|
34
|
+
params,
|
|
35
|
+
"http://api.syosetu.com/novelapi/api/"
|
|
36
|
+
);
|
|
68
37
|
}
|
|
69
38
|
|
|
70
|
-
|
|
71
|
-
return this.executeSearch(
|
|
39
|
+
async executeNovel18(params: SearchParams): Promise<NarouSearchResults> {
|
|
40
|
+
return await this.executeSearch(
|
|
41
|
+
params,
|
|
42
|
+
"http://api.syosetu.com/novel18api/api/"
|
|
43
|
+
);
|
|
72
44
|
}
|
|
73
45
|
|
|
74
|
-
|
|
75
|
-
return this.execute(params, "http://api.syosetu.com/rank/rankget/");
|
|
46
|
+
async executeRanking(params: RankingParams): Promise<NarouRankingResult[]> {
|
|
47
|
+
return await this.execute(params, "http://api.syosetu.com/rank/rankget/");
|
|
76
48
|
}
|
|
77
49
|
|
|
78
|
-
|
|
50
|
+
async executeRankingHistory(
|
|
79
51
|
params: RankingHistoryParams
|
|
80
52
|
): Promise<RankingHistoryRawResult[]> {
|
|
81
|
-
return this.execute(params, "http://api.syosetu.com/rank/rankin/");
|
|
53
|
+
return await this.execute(params, "http://api.syosetu.com/rank/rankin/");
|
|
82
54
|
}
|
|
83
55
|
}
|